Skip to content

Commit 2d47052

Browse files
LLT21LLT21
andauthored
MySQL added to framework next to PostgreSQL ODBC data access with native, reflection free C# compilation (#6749)
* MySQL ODBC implementation added to PostgreSQL ODBC implementation * Handling of Japanese characters in MariaDB ODBC connector * Optimal batch updates for MySQL and PostgreSQL Co-authored-by: LLT21 <[email protected]>
1 parent 14b7ff1 commit 2d47052

12 files changed

+270
-94
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
2+
RUN apt-get update
3+
RUN apt-get -yqq install clang zlib1g-dev libkrb5-dev libtinfo5
4+
RUN apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
5+
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
6+
xz-utils tk-dev libffi-dev liblzma-dev pgpool2 vim-tiny
7+
8+
WORKDIR /odbc
9+
10+
RUN curl -L -o unixODBC-2.3.9.tar.gz ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.9.tar.gz
11+
RUN tar -xvf unixODBC-2.3.9.tar.gz
12+
13+
WORKDIR /odbc/unixODBC-2.3.9
14+
RUN ./configure --prefix=/usr/local/unixODBC
15+
RUN make
16+
RUN make install
17+
18+
ENV PATH=/usr/local/unixODBC/lib:$PATH
19+
20+
WORKDIR /app
21+
COPY src .
22+
RUN dotnet publish -c Release -o out -r linux-x64 /p:Database=mysql
23+
24+
# Construct the actual image that will run
25+
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
26+
27+
RUN apt-get update
28+
# The following installs standard versions unixodbc 2.3.6 and pgsqlodbc 11
29+
#RUN apt-get install -y unixodbc odbc-postgresql
30+
# unixodbc still needs to be installed even if compiled locally
31+
RUN apt-get install -y unixodbc wget curl
32+
33+
WORKDIR /odbc
34+
35+
RUN curl -L -o mariadb-connector-odbc-3.1.13-debian-9-stretch-amd64.tar.gz https://downloads.mariadb.com/Connectors/odbc/connector-odbc-3.1.13/mariadb-connector-odbc-3.1.13-debian-9-stretch-amd64.tar.gz
36+
RUN tar -xvzf mariadb-connector-odbc-3.1.13-debian-9-stretch-amd64.tar.gz
37+
RUN cp mariadb-connector-odbc-3.1.13-debian-9-stretch-amd64/lib/mariadb/libm* /usr/lib/
38+
39+
COPY --from=build /usr/local/unixODBC /usr/local/unixODBC
40+
41+
# Check unixODBC version by:
42+
# 1. Logging into containter: docker run --rm -it --entrypoint=/bin/bash techempower/tfb.test.appmpower
43+
# 2. odbcinst --version
44+
45+
ENV PATH=/usr/local/unixODBC/bin:$PATH
46+
47+
WORKDIR /etc/
48+
COPY odbcinst.ini .
49+
50+
WORKDIR /app
51+
COPY --from=build /app/out ./
52+
53+
EXPOSE 8080
54+
55+
ENTRYPOINT ["./appMpower"]
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
2+
RUN apt-get update
3+
RUN apt-get -yqq install clang zlib1g-dev libkrb5-dev libtinfo5
4+
RUN apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
5+
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
6+
xz-utils tk-dev libffi-dev liblzma-dev pgpool2 vim-tiny
7+
8+
WORKDIR /odbc
9+
10+
# To compile the latest postgresql odbc driver, postgresql itself needs to be installed
11+
RUN curl -L -o postgresql-13.3.tar.gz https://ftp.postgresql.org/pub/source/v13.3/postgresql-13.3.tar.gz
12+
RUN curl -L -o unixODBC-2.3.9.tar.gz ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.9.tar.gz
13+
RUN curl -L -o psqlodbc-13.01.0000.tar.gz https://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-13.01.0000.tar.gz
14+
15+
RUN tar -xvf postgresql-13.3.tar.gz
16+
RUN tar -xvf unixODBC-2.3.9.tar.gz
17+
RUN tar -xvf psqlodbc-13.01.0000.tar.gz
18+
19+
WORKDIR /odbc/postgresql-13.3
20+
RUN ./configure
21+
RUN make
22+
RUN make install
23+
24+
ENV PATH=/usr/local/pgsql/bin:$PATH
25+
26+
WORKDIR /odbc/unixODBC-2.3.9
27+
RUN ./configure --prefix=/usr/local/unixODBC
28+
RUN make
29+
RUN make install
30+
31+
ENV PATH=/usr/local/unixODBC/lib:$PATH
32+
33+
WORKDIR /odbc/psqlodbc-13.01.0000
34+
RUN ./configure --with-unixodbc=/usr/local/unixODBC --with-libpq=/usr/local/pgsql --prefix=/usr/local/pgsqlodbc
35+
RUN make
36+
RUN make install
37+
38+
WORKDIR /app
39+
COPY src .
40+
RUN dotnet publish -c Release -o out -r linux-x64 /p:Database=postgresql
41+
42+
# Construct the actual image that will run
43+
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
44+
45+
RUN apt-get update
46+
# The following installs standard versions unixodbc 2.3.6 and pgsqlodbc 11
47+
#RUN apt-get install -y unixodbc odbc-postgresql
48+
# unixodbc still needs to be installed even if compiled locally
49+
RUN apt-get install -y unixodbc wget curl libpq-dev build-essential
50+
51+
WORKDIR /odbc
52+
53+
RUN curl -L -o pgpool-II-4.2.3.tar.gz https://www.pgpool.net/mediawiki/download.php?f=pgpool-II-4.2.3.tar.gz
54+
RUN tar -xvf pgpool-II-4.2.3.tar.gz
55+
56+
WORKDIR /odbc/pgpool-II-4.2.3
57+
RUN ./configure
58+
RUN make
59+
RUN make install
60+
61+
COPY --from=build /usr/local/unixODBC /usr/local/unixODBC
62+
63+
# Check unixODBC version by:
64+
# 1. Logging into containter: docker run --rm -it --entrypoint=/bin/bash techempower/tfb.test.appmpower
65+
# 2. odbcinst --version
66+
67+
ENV PATH=/usr/local/unixODBC/bin:$PATH
68+
69+
COPY --from=build /usr/local/pgsqlodbc /usr/local/pgsqlodbc
70+
71+
WORKDIR /etc/
72+
COPY odbcinst.ini .
73+
74+
WORKDIR /app
75+
COPY --from=build /app/out ./
76+
77+
EXPOSE 8080
78+
79+
ENTRYPOINT ["./appMpower"]

frameworks/CSharp/appmpower/appmpower.dockerfile

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,14 @@
11
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
22
RUN apt-get update
33
RUN apt-get -yqq install clang zlib1g-dev libkrb5-dev libtinfo5
4-
RUN apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
5-
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
6-
xz-utils tk-dev libffi-dev liblzma-dev pgpool2 vim-tiny
7-
8-
WORKDIR /odbc
9-
10-
# To compile the latest postgresql odbc driver, postgresql itself needs to be installed
11-
RUN curl -L -o postgresql-13.3.tar.gz https://ftp.postgresql.org/pub/source/v13.3/postgresql-13.3.tar.gz
12-
RUN curl -L -o unixODBC-2.3.9.tar.gz ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.9.tar.gz
13-
RUN curl -L -o psqlodbc-13.01.0000.tar.gz https://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-13.01.0000.tar.gz
14-
15-
RUN tar -xvf postgresql-13.3.tar.gz
16-
RUN tar -xvf unixODBC-2.3.9.tar.gz
17-
RUN tar -xvf psqlodbc-13.01.0000.tar.gz
18-
19-
WORKDIR /odbc/postgresql-13.3
20-
RUN ./configure
21-
RUN make
22-
RUN make install
23-
24-
ENV PATH=/usr/local/pgsql/bin:$PATH
25-
26-
WORKDIR /odbc/unixODBC-2.3.9
27-
RUN ./configure --prefix=/usr/local/unixODBC
28-
RUN make
29-
RUN make install
30-
31-
ENV PATH=/usr/local/unixODBC/lib:$PATH
32-
33-
WORKDIR /odbc/psqlodbc-13.01.0000
34-
RUN ./configure --with-unixodbc=/usr/local/unixODBC --with-libpq=/usr/local/pgsql --prefix=/usr/local/pgsqlodbc
35-
RUN make
36-
RUN make install
374

385
WORKDIR /app
396
COPY src .
407
RUN dotnet publish -c Release -o out -r linux-x64
418

429
# Construct the actual image that will run
4310
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
44-
4511
RUN apt-get update
46-
# The following installs standard versions unixodbc 2.3.6 and pgsqlodbc 11
47-
#RUN apt-get install -y unixodbc odbc-postgresql
48-
# unixodbc still needs to be installed even if compiled locally
49-
RUN apt-get install -y unixodbc wget curl libpq-dev build-essential
50-
51-
WORKDIR /odbc
52-
53-
RUN curl -L -o pgpool-II-4.2.3.tar.gz https://www.pgpool.net/mediawiki/download.php?f=pgpool-II-4.2.3.tar.gz
54-
RUN tar -xvf pgpool-II-4.2.3.tar.gz
55-
56-
WORKDIR /odbc/pgpool-II-4.2.3
57-
RUN ./configure
58-
RUN make
59-
RUN make install
60-
61-
COPY --from=build /usr/local/unixODBC /usr/local/unixODBC
62-
63-
# Check unixODBC version by:
64-
# 1. Logging into containter: docker run --rm -it --entrypoint=/bin/bash techempower/tfb.test.appmpower
65-
# 2. odbcinst --version
66-
67-
ENV PATH=/usr/local/unixODBC/bin:$PATH
68-
69-
COPY --from=build /usr/local/pgsqlodbc /usr/local/pgsqlodbc
70-
71-
WORKDIR /etc/
72-
COPY odbcinst.ini .
7312

7413
WORKDIR /app
7514
COPY --from=build /app/out ./

frameworks/CSharp/appmpower/benchmark_config.json

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
"default": {
66
"plaintext_url": "/plaintext",
77
"json_url": "/json",
8+
"port": 8080,
9+
"approach": "Realistic",
10+
"classification": "Platform",
11+
"database": "None",
12+
"framework": "ASP.NET Core",
13+
"language": "C#",
14+
"orm": "Raw",
15+
"platform": ".NET",
16+
"flavor": "CoreCLR",
17+
"webserver": "Kestrel",
18+
"os": "Linux",
19+
"database_os": "Linux",
20+
"display_name": "appMpower [Middleware]",
21+
"notes": "",
22+
"versus": "aspcore-mw"
23+
},
24+
"odbc-pg": {
825
"db_url": "/db",
926
"query_url": "/queries?c=",
1027
"update_url": "/updates?c=",
@@ -21,9 +38,30 @@
2138
"webserver": "Kestrel",
2239
"os": "Linux",
2340
"database_os": "Linux",
24-
"display_name": "appMpower",
41+
"display_name": "appMpower [Middleware, Odbc, Pg]",
42+
"notes": "",
43+
"versus": "aspcore-mw-ado-pg"
44+
},
45+
"odbc-my": {
46+
"db_url": "/db",
47+
"query_url": "/queries?c=",
48+
"update_url": "/updates?c=",
49+
"fortune_url": "/fortunes",
50+
"port": 8080,
51+
"approach": "Realistic",
52+
"classification": "Platform",
53+
"database": "MySQL",
54+
"framework": "ASP.NET Core",
55+
"language": "C#",
56+
"orm": "Raw",
57+
"platform": ".NET",
58+
"flavor": "CoreCLR",
59+
"webserver": "Kestrel",
60+
"os": "Linux",
61+
"database_os": "Linux",
62+
"display_name": "appMpower [Middleware, Odbc, My]",
2563
"notes": "",
26-
"versus": "aspcore"
64+
"versus": "aspcore-mw-ado-my"
2765
}
2866
}
2967
]

frameworks/CSharp/appmpower/config.toml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,42 @@ name = "appmpower"
44
[main]
55
urls.plaintext = "/plaintext"
66
urls.json = "/json"
7+
approach = "Realistic"
8+
classification = "Micro"
9+
database = "None"
10+
database_os = "Linux"
11+
os = "Linux"
12+
orm = "Raw"
13+
platform = ".NET"
14+
webserver = "kestrel"
15+
versus = "aspcore-mw"
16+
17+
[odbc-pg]
718
urls.db = "/db"
819
urls.query = "/queries?c="
920
urls.update = "/updates?c="
1021
urls.fortune = "/fortunes"
1122
approach = "Realistic"
12-
classification = "Platform"
23+
classification = "Micro"
1324
database = "Postgres"
1425
database_os = "Linux"
1526
os = "Linux"
1627
orm = "Raw"
1728
platform = ".NET"
18-
webserver = "kestrel"
19-
versus = "aspcore"
29+
webserver = "Kestrel"
30+
versus = "aspcore-mw-ado-pg"
31+
32+
[odbc-my]
33+
urls.db = "/db"
34+
urls.query = "/queries?c="
35+
urls.update = "/updates?c="
36+
urls.fortune = "/fortunes"
37+
approach = "Realistic"
38+
classification = "Micro"
39+
database = "MySQL"
40+
database_os = "Linux"
41+
os = "Linux"
42+
orm = "Raw"
43+
platform = ".NET"
44+
webserver = "Kestrel"
45+
versus = "aspcore-mw-ado-my"

frameworks/CSharp/appmpower/odbcinst.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Pooling=0
55

66
[ODBC Drivers]
77
PostgreSQL = Installed
8+
MariaDB = Installed
89

910
;
1011
; odbcinst.ini
@@ -18,4 +19,9 @@ Description=ODBC for PostgreSQL
1819
;Driver = /usr/lib/x86_64-linux-gnu/odbc/psqlodbcw.so
1920
Driver =/usr/local/pgsqlodbc/lib/psqlodbcw.so
2021
Threading = 0
21-
CPTimeout = 0
22+
CPTimeout = 0
23+
24+
[MariaDB]
25+
Description=MariaDB ODBC for MySQL
26+
Driver = /usr/lib/libmaodbc.so
27+
Threading = 0

frameworks/CSharp/appmpower/src/ConnectionStrings.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ namespace appMpower
22
{
33
public static class ConnectionStrings
44
{
5-
//public const string OdbcConnection = "Driver={PostgreSQL};Server=host.docker.internal;Port=5432;Database=hello_world;Uid=benchmarkdbuser;Pwd=benchmarkdbpass;UseServerSidePrepare=1;Pooling=false";
5+
#if MYSQL
6+
public const string OdbcConnection = "Driver={MariaDB};Server=tfb-database;Database=hello_world;Uid=benchmarkdbuser;Pwd=benchmarkdbpass;Pooling=false;OPTIONS=67108864;FLAG_FORWARD_CURSOR=1";
7+
#else
68
public const string OdbcConnection = "Driver={PostgreSQL};Server=tfb-database;Database=hello_world;Uid=benchmarkdbuser;Pwd=benchmarkdbpass;UseServerSidePrepare=1;Pooling=false";
9+
#endif
710
}
811
}

frameworks/CSharp/appmpower/src/Db/PooledConnections.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Concurrent;
32
using System.Data.Odbc;
43
using System.Threading.Tasks;
@@ -9,7 +8,13 @@ public static class PooledConnections
98
{
109
private static bool _connectionsCreated = false;
1110
private static short _createdConnections = 0;
12-
private static short _maxConnections = 333;
11+
12+
#if MYSQL
13+
private static short _maxConnections = 1250;
14+
#else
15+
private static short _maxConnections = 500;
16+
#endif
17+
1318
private static ConcurrentStack<PooledConnection> _stack = new ConcurrentStack<PooledConnection>();
1419
private static ConcurrentQueue<TaskCompletionSource<PooledConnection>> _waitingQueue = new ConcurrentQueue<TaskCompletionSource<PooledConnection>>();
1520

@@ -29,7 +34,6 @@ public static async Task<PooledConnection> GetConnection(string connectionString
2934
}
3035

3136
return pooledConnection;
32-
3337
}
3438
else
3539
{
@@ -81,4 +85,4 @@ public static void Release(PooledConnection pooledConnection)
8185
}
8286
}
8387
}
84-
}
88+
}

0 commit comments

Comments
 (0)