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

Updates to aspnetcore PG database access #8005

Merged
merged 5 commits into from
Mar 20, 2023

Conversation

roji
Copy link
Contributor

@roji roji commented Mar 9, 2023

No description provided.

* Use batching with Sync error barriers in Updates
* Use NpgsqlDataSource
* Use typed NpgsqlParameter<T> everywhere
* Use positional parameter placeholders everywhere ($1, $2)
@roji
Copy link
Contributor Author

roji commented Mar 16, 2023

@DamianEdwards pushed your changes from aspnet/Benchmarks#1801 into this, can you please take a look?

Will leave this open for some last perf experiments I want to do in the coming days.

@DamianEdwards
Copy link
Contributor

@roji looks good!

@roji
Copy link
Contributor Author

roji commented Mar 16, 2023

Will leave this open for some last perf experiments I want to do in the coming days.

These aren't ready to be integrated here. Let's merge this PR, I'll continue experimenting and possibly submit a separate one later.

@roji roji marked this pull request as ready for review March 16, 2023 21:17
@roji
Copy link
Contributor Author

roji commented Mar 18, 2023

Note: added another commit here to disable SQL parsing/rewriting (see aspnet/Benchmarks#1590 (comment)). This should provide a small speed bump to Fortunes specifically.

Comment on lines +17 to +23
#if NPGSQL
// This disables SQL parsing/rewriting, which requires using positional parameters and NpgsqlBatch everywhere.
// This helps commands where there are no parameters (Fortunes); when there are parameters, their ParameterName
// being null already triggers positional parameters and disables parsing)
// Note that Dapper and EF aren't yet compatible with this mode.
AppContext.SetSwitch("Npgsql.EnableSqlRewriting", false);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we have enabled in our copy of the benchmark, or is it not required there for other reasons?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do it in our copy since we have Dapper and EF, which this is incompatible with... This one is tricky, since it's an AppContext switched cached at startup, but we don't know whether the application will be used for raw, dapper or EF.

This could be an #if (we already have #if DATABASE, #if NPGSQL vs. MYSQLCONNECTOR)...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Ideally this would be a property that be set directly on the command. What kind of gains are we talking about by setting it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See aspnet/Benchmarks#1590 (comment).

I did a measurement a long time ago and it wasn't very significant, but we're at the point where every little bit helps (I can measure again at some point).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using AppContext switches makes me slightly uneasy as they're usually reserved in .NET for restoring unsupported behaviors, rather than opting-in to legitimate optimizations. I think this is one of those things that's very much in the contentious or at least debatable zone WRT to keeping in the spirit of the benchmark.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this offline and I'm OK with this going in now.

@sebastienros
Copy link
Contributor

@nbrady-techempower ready to merge, thanks

@NateBrady23 NateBrady23 merged commit 38ee290 into TechEmpower:master Mar 20, 2023
@roji roji deleted the NpgsqlStuff branch March 20, 2023 19:17
franz1981 pushed a commit to franz1981/FrameworkBenchmarks that referenced this pull request Jun 23, 2023
* Some code cleanup

* Updates to aspnetcore PG database access

* Use batching with Sync error barriers in Updates
* Use NpgsqlDataSource
* Use typed NpgsqlParameter<T> everywhere
* Use positional parameter placeholders everywhere ($1, $2)

* Stop UTF8 decoding/reencoding in Fortunes platform

* Update Fortunes to use Razor templating

* Turn of SQL parsing/rewriting for Fortunes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants