Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for positional parameters #3852

Merged
merged 7 commits into from Jun 18, 2021
Merged

Implement support for positional parameters #3852

merged 7 commits into from Jun 18, 2021

Conversation

roji
Copy link
Member

@roji roji commented Jun 17, 2021

This is an alternative, simpler approach to #3834, because of perf issues in that attempt with multiplexing. The approach here does not tie together raw SQL mode to preparation, and simply uses the presence of positional parameters as an indication that raw mode is active. In the absence of any parameters, we parse/rewrite SQL as usual, since legacy semicolon batching may be in use (this unfortunately means that Fortunes does not work in raw mode). We may introduce a switch in the future to force raw mode, in which case the 0-param case would also not parse/rewrite.

Perf-wise, the longer the SQL and the more parameters are contained, the more this will be an improvement.

Part of #1042
Leads to #2317

scenario RPS
Fortunes before 480,589
Fortunes after 474,297
Single query named before 418,626
Single query named after 423,520
Single query positional after 422,187
Multi query named before 25,143
Multi query named after 24,698
Multi query positional after 26,468
Detailed run results

Fortunes Before (5140019)

dotnet run -- --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/platform.benchmarks.yml --scenario fortunes --profile aspnet-citrine-lin --application.framework net6.0 --application.options.outputFiles Z:\projects\npgsql\src\Npgsql\bin\Release\net6.0\Npgsql.dll --variable warmup=45 --variable duration=120

| db                  |         |
| ------------------- | ------- |
| CPU Usage (%)       | 38      |
| Cores usage (%)     | 1,072   |
| Working Set (MB)    | 44      |
| Build Time (ms)     | 1,692   |
| Start Time (ms)     | 338     |
| Published Size (KB) | 914,279 |


| application           |                                 |
| --------------------- | ------------------------------- |
| CPU Usage (%)         | 96                              |
| Cores usage (%)       | 2,695                           |
| Working Set (MB)      | 458                             |
| Private Memory (MB)   | 1,579                           |
| Build Time (ms)       | 2,574                           |
| Start Time (ms)       | 1,451                           |
| Published Size (KB)   | 91,126                          |
| .NET Core SDK Version | 6.0.100-preview.6.21276.12      |
| ASP.NET Core Version  | 6.0.0-preview.7.21317.2+0aa82c3 |
| .NET Runtime Version  | 6.0.0-preview.7.21317.7+eb7b3db |


| load                   |            |
| ---------------------- | ---------- |
| CPU Usage (%)          | 31         |
| Cores usage (%)        | 873        |
| Working Set (MB)       | 37         |
| Private Memory (MB)    | 363        |
| Start Time (ms)        | 0          |
| First Request (ms)     | 73         |
| Requests/sec           | 480,589    |
| Requests               | 57,718,341 |
| Mean latency (ms)      | 1.12       |
| Max latency (ms)       | 28.01      |
| Bad responses          | 0          |
| Socket errors          | 0          |
| Read throughput (MB/s) | 623.78     |
| Latency 50th (ms)      | 1.01       |
| Latency 75th (ms)      | 1.21       |
| Latency 90th (ms)      | 1.51       |
| Latency 99th (ms)      | 4.03       |

Fortunes After (a453dc5)

dotnet run -- --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/platform.benchmarks.yml --scenario fortunes --profile aspnet-citrine-lin --application.framework net6.0 --application.options.outputFiles Z:\projects\npgsql\src\Npgsql\bin\Release\net6.0\Npgsql.dll --variable warmup=45 --variable duration=120

| db                  |         |
| ------------------- | ------- |
| CPU Usage (%)       | 38      |
| Cores usage (%)     | 1,056   |
| Working Set (MB)    | 47      |
| Build Time (ms)     | 1,679   |
| Start Time (ms)     | 340     |
| Published Size (KB) | 914,279 |


| application           |                                 |
| --------------------- | ------------------------------- |
| CPU Usage (%)         | 96                              |
| Cores usage (%)       | 2,695                           |
| Working Set (MB)      | 451                             |
| Private Memory (MB)   | 1,580                           |
| Build Time (ms)       | 2,576                           |
| Start Time (ms)       | 1,540                           |
| Published Size (KB)   | 91,126                          |
| .NET Core SDK Version | 6.0.100-preview.6.21276.12      |
| ASP.NET Core Version  | 6.0.0-preview.7.21317.2+0aa82c3 |
| .NET Runtime Version  | 6.0.0-preview.7.21317.7+eb7b3db |


| load                   |            |
| ---------------------- | ---------- |
| CPU Usage (%)          | 31         |
| Cores usage (%)        | 866        |
| Working Set (MB)       | 37         |
| Private Memory (MB)    | 363        |
| Start Time (ms)        | 0          |
| First Request (ms)     | 72         |
| Requests/sec           | 474,297    |
| Requests               | 56,961,560 |
| Mean latency (ms)      | 1.13       |
| Max latency (ms)       | 25.74      |
| Bad responses          | 0          |
| Socket errors          | 0          |
| Read throughput (MB/s) | 615.61     |
| Latency 50th (ms)      | 1.02       |
| Latency 75th (ms)      | 1.22       |
| Latency 90th (ms)      | 1.53       |
| Latency 99th (ms)      | 3.97       |

Single Query named before (5140019)

dotnet run -- --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/platform.benchmarks.yml --scenario single_query --profile aspnet-citrine-lin --application.framework net6.0 --application.options.outputFiles Z:\projects\npgsql\src\Npgsql\bin\Release\net6.0\Npgsql.dll --variable warmup=45 --variable duration=120

| db                  |         |
| ------------------- | ------- |
| CPU Usage (%)       | 35      |
| Cores usage (%)     | 986     |
| Working Set (MB)    | 46      |
| Build Time (ms)     | 1,755   |
| Start Time (ms)     | 348     |
| Published Size (KB) | 914,279 |


| application           |                                 |
| --------------------- | ------------------------------- |
| CPU Usage (%)         | 96                              |
| Cores usage (%)       | 2,685                           |
| Working Set (MB)      | 477                             |
| Private Memory (MB)   | 1,594                           |
| Build Time (ms)       | 3,748                           |
| Start Time (ms)       | 1,555                           |
| Published Size (KB)   | 91,126                          |
| .NET Core SDK Version | 6.0.100-preview.6.21276.12      |
| ASP.NET Core Version  | 6.0.0-preview.7.21317.2+0aa82c3 |
| .NET Runtime Version  | 6.0.0-preview.7.21317.7+eb7b3db |


| load                   |            |
| ---------------------- | ---------- |
| CPU Usage (%)          | 26         |
| Cores usage (%)        | 723        |
| Working Set (MB)       | 38         |
| Private Memory (MB)    | 358        |
| Start Time (ms)        | 0          |
| First Request (ms)     | 65         |
| Requests/sec           | 418,626    |
| Requests               | 50,276,778 |
| Mean latency (ms)      | 0.64       |
| Max latency (ms)       | 21.43      |
| Bad responses          | 0          |
| Socket errors          | 0          |
| Read throughput (MB/s) | 60.59      |
| Latency 50th (ms)      | 0.59       |
| Latency 75th (ms)      | 0.70       |
| Latency 90th (ms)      | 0.82       |
| Latency 99th (ms)      | 2.67       |

Single Query named after (a453dc5)

dotnet run -- --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/platform.benchmarks.yml --scenario single_query --profile aspnet-citrine-lin --application.framework net6.0 --application.options.outputFiles Z:\projects\npgsql\src\Npgsql\bin\Release\net6.0\Npgsql.dll --variable warmup=45 --variable duration=120

| db                  |         |
| ------------------- | ------- |
| CPU Usage (%)       | 35      |
| Cores usage (%)     | 987     |
| Working Set (MB)    | 46      |
| Build Time (ms)     | 1,722   |
| Start Time (ms)     | 363     |
| Published Size (KB) | 914,279 |


| application           |                                 |
| --------------------- | ------------------------------- |
| CPU Usage (%)         | 96                              |
| Cores usage (%)       | 2,679                           |
| Working Set (MB)      | 454                             |
| Private Memory (MB)   | 1,575                           |
| Build Time (ms)       | 2,620                           |
| Start Time (ms)       | 1,517                           |
| Published Size (KB)   | 91,126                          |
| .NET Core SDK Version | 6.0.100-preview.6.21276.12      |
| ASP.NET Core Version  | 6.0.0-preview.7.21317.2+0aa82c3 |
| .NET Runtime Version  | 6.0.0-preview.7.21317.7+eb7b3db |


| load                   |            |
| ---------------------- | ---------- |
| CPU Usage (%)          | 26         |
| Cores usage (%)        | 738        |
| Working Set (MB)       | 37         |
| Private Memory (MB)    | 358        |
| Start Time (ms)        | 0          |
| First Request (ms)     | 65         |
| Requests/sec           | 423,520    |
| Requests               | 50,864,574 |
| Mean latency (ms)      | 0.64       |
| Max latency (ms)       | 29.42      |
| Bad responses          | 0          |
| Socket errors          | 0          |
| Read throughput (MB/s) | 61.30      |
| Latency 50th (ms)      | 0.58       |
| Latency 75th (ms)      | 0.70       |
| Latency 90th (ms)      | 0.81       |
| Latency 99th (ms)      | 2.57       |

Single Query positional after (a453dc5)

dotnet run -- --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/platform.benchmarks.yml --scenario single_query --profile aspnet-citrine-lin --application.framework net6.0 --application.options.outputFiles Z:\projects\npgsql\src\Npgsql\bin\Release\net6.0\Npgsql.dll --variable warmup=45 --variable duration=120 --application.source.repository http://github.com/roji/AspNetBenchmarks --application.source.branchOrCommit RawSql

| db                  |         |
| ------------------- | ------- |
| CPU Usage (%)       | 35      |
| Cores usage (%)     | 991     |
| Working Set (MB)    | 46      |
| Build Time (ms)     | 1,739   |
| Start Time (ms)     | 337     |
| Published Size (KB) | 914,279 |


| application           |                                 |
| --------------------- | ------------------------------- |
| CPU Usage (%)         | 96                              |
| Cores usage (%)       | 2,681                           |
| Working Set (MB)      | 459                             |
| Private Memory (MB)   | 1,580                           |
| Build Time (ms)       | 2,624                           |
| Start Time (ms)       | 1,424                           |
| Published Size (KB)   | 91,126                          |
| .NET Core SDK Version | 6.0.100-preview.6.21276.12      |
| ASP.NET Core Version  | 6.0.0-preview.7.21317.2+0aa82c3 |
| .NET Runtime Version  | 6.0.0-preview.7.21317.7+eb7b3db |


| load                   |            |
| ---------------------- | ---------- |
| CPU Usage (%)          | 26         |
| Cores usage (%)        | 737        |
| Working Set (MB)       | 37         |
| Private Memory (MB)    | 358        |
| Start Time (ms)        | 0          |
| First Request (ms)     | 65         |
| Requests/sec           | 422,187    |
| Requests               | 50,695,518 |
| Mean latency (ms)      | 0.65       |
| Max latency (ms)       | 24.42      |
| Bad responses          | 0          |
| Socket errors          | 0          |
| Read throughput (MB/s) | 61.11      |
| Latency 50th (ms)      | 0.58       |
| Latency 75th (ms)      | 0.70       |
| Latency 90th (ms)      | 0.82       |
| Latency 99th (ms)      | 3.02       |

Multi Query named before (5140019)

dotnet run -- --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/platform.benchmarks.yml --scenario multiple_queries --profile aspnet-citrine-lin --application.framework net6.0 --application.options.outputFiles Z:\projects\npgsql\src\Npgsql\bin\Release\net6.0\Npgsql.dll --variable warmup=45 --variable duration=120

| db                  |         |
| ------------------- | ------- |
| CPU Usage (%)       | 41      |
| Cores usage (%)     | 1,162   |
| Working Set (MB)    | 47      |
| Build Time (ms)     | 1,772   |
| Start Time (ms)     | 348     |
| Published Size (KB) | 914,279 |


| application           |                                 |
| --------------------- | ------------------------------- |
| CPU Usage (%)         | 75                              |
| Cores usage (%)       | 2,094                           |
| Working Set (MB)      | 469                             |
| Private Memory (MB)   | 1,467                           |
| Build Time (ms)       | 2,635                           |
| Start Time (ms)       | 1,697                           |
| Published Size (KB)   | 91,126                          |
| .NET Core SDK Version | 6.0.100-preview.6.21276.12      |
| ASP.NET Core Version  | 6.0.0-preview.7.21317.2+0aa82c3 |
| .NET Runtime Version  | 6.0.0-preview.7.21317.7+eb7b3db |


| load                   |           |
| ---------------------- | --------- |
| CPU Usage (%)          | 2         |
| Cores usage (%)        | 50        |
| Working Set (MB)       | 38        |
| Private Memory (MB)    | 358       |
| Start Time (ms)        | 0         |
| First Request (ms)     | 75        |
| Requests/sec           | 25,143    |
| Requests               | 3,019,710 |
| Mean latency (ms)      | 10.18     |
| Max latency (ms)       | 33.31     |
| Bad responses          | 0         |
| Socket errors          | 0         |
| Read throughput (MB/s) | 18.17     |
| Latency 50th (ms)      | 10.15     |
| Latency 75th (ms)      | 10.68     |
| Latency 90th (ms)      | 11.19     |
| Latency 99th (ms)      | 12.41     |

Multi Query named after (a453dc5)

dotnet run -- --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/platform.benchmarks.yml --scenario multiple_queries --profile aspnet-citrine-lin --application.framework net6.0 --application.options.outputFiles Z:\projects\npgsql\src\Npgsql\bin\Release\net6.0\Npgsql.dll --variable warmup=45 --variable duration=120

| db                  |         |
| ------------------- | ------- |
| CPU Usage (%)       | 39      |
| Cores usage (%)     | 1,087   |
| Working Set (MB)    | 47      |
| Build Time (ms)     | 1,702   |
| Start Time (ms)     | 339     |
| Published Size (KB) | 914,279 |


| application           |                                 |
| --------------------- | ------------------------------- |
| CPU Usage (%)         | 73                              |
| Cores usage (%)       | 2,057                           |
| Working Set (MB)      | 455                             |
| Private Memory (MB)   | 1,556                           |
| Build Time (ms)       | 3,869                           |
| Start Time (ms)       | 1,610                           |
| Published Size (KB)   | 91,126                          |
| .NET Core SDK Version | 6.0.100-preview.6.21276.12      |
| ASP.NET Core Version  | 6.0.0-preview.7.21317.2+0aa82c3 |
| .NET Runtime Version  | 6.0.0-preview.7.21317.7+eb7b3db |


| load                   |           |
| ---------------------- | --------- |
| CPU Usage (%)          | 2         |
| Cores usage (%)        | 50        |
| Working Set (MB)       | 37        |
| Private Memory (MB)    | 358       |
| Start Time (ms)        | 0         |
| First Request (ms)     | 74        |
| Requests/sec           | 24,698    |
| Requests               | 2,966,221 |
| Mean latency (ms)      | 10.36     |
| Max latency (ms)       | 35.91     |
| Bad responses          | 0         |
| Socket errors          | 0         |
| Read throughput (MB/s) | 17.84     |
| Latency 50th (ms)      | 10.33     |
| Latency 75th (ms)      | 10.87     |
| Latency 90th (ms)      | 11.36     |
| Latency 99th (ms)      | 12.43     |

Multi Query positional after (a453dc5)

dotnet run -- --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/platform.benchmarks.yml --scenario multiple_queries --profile aspnet-citrine-lin --application.framework net6.0 --application.options.outputFiles Z:\projects\npgsql\src\Npgsql\bin\Release\net6.0\Npgsql.dll --variable warmup=45 --variable duration=120 --application.source.repository http://github.com/roji/AspNetBenchmarks --application.source.branchOrCommit RawSql

| db                  |         |
| ------------------- | ------- |
| CPU Usage (%)       | 41      |
| Cores usage (%)     | 1,147   |
| Working Set (MB)    | 47      |
| Build Time (ms)     | 1,715   |
| Start Time (ms)     | 370     |
| Published Size (KB) | 914,279 |


| application           |                                 |
| --------------------- | ------------------------------- |
| CPU Usage (%)         | 74                              |
| Cores usage (%)       | 2,069                           |
| Working Set (MB)      | 452                             |
| Private Memory (MB)   | 1,440                           |
| Build Time (ms)       | 2,643                           |
| Start Time (ms)       | 1,627                           |
| Published Size (KB)   | 91,126                          |
| .NET Core SDK Version | 6.0.100-preview.6.21276.12      |
| ASP.NET Core Version  | 6.0.0-preview.7.21317.2+0aa82c3 |
| .NET Runtime Version  | 6.0.0-preview.7.21317.7+eb7b3db |


| load                   |           |
| ---------------------- | --------- |
| CPU Usage (%)          | 2         |
| Cores usage (%)        | 52        |
| Working Set (MB)       | 37        |
| Private Memory (MB)    | 358       |
| Start Time (ms)        | 0         |
| First Request (ms)     | 75        |
| Requests/sec           | 26,468    |
| Requests               | 3,178,564 |
| Mean latency (ms)      | 9.67      |
| Max latency (ms)       | 31.76     |
| Bad responses          | 0         |
| Socket errors          | 0         |
| Read throughput (MB/s) | 19.12     |
| Latency 50th (ms)      | 9.65      |
| Latency 75th (ms)      | 10.16     |
| Latency 90th (ms)      | 10.64     |
| Latency 99th (ms)      | 11.68     |

EDIT: Note that with #3920, Fortunes can now be optimized to not parse/rewrite as well.

src/Npgsql/MultiplexingConnectorPool.cs Outdated Show resolved Hide resolved
test/Npgsql.Tests/PrepareTests.cs Outdated Show resolved Hide resolved
test/Npgsql.Tests/PrepareTests.cs Outdated Show resolved Hide resolved
src/Npgsql/NpgsqlStatement.cs Show resolved Hide resolved
src/Npgsql/NpgsqlCommand.cs Outdated Show resolved Hide resolved
src/Npgsql/NpgsqlCommand.cs Show resolved Hide resolved
@roji roji requested a review from vonzshik June 18, 2021 17:30
@roji roji requested a review from vonzshik June 18, 2021 17:48
@roji roji enabled auto-merge (squash) June 18, 2021 19:13
@roji roji merged commit 2594199 into main Jun 18, 2021
@roji roji deleted the RawMode branch June 18, 2021 19:16
@roji roji changed the title Implement raw SQL mode for prepared, non-batched commands (take 2) Implement support for positional parameters Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants