-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Microsoft.Data.Sqlite: Pool Connections #13837
Comments
@bricelam would this also be an excuse to implement auto-prepared statements (assuming it isn’t implemented yet)? |
We currently cache the compilation at the DbCommand level. We could lift it to an opened connection without this. With this we could do it across close and re-open. |
Cool! Once we have that, I think implementing auto-prepared commands (like Npgsql) could give us another boost. Cc @roji |
Nice... If you work on prepared statements, consider also persisting them across pooled open/close, otherwise they're useless in short-lived connection scenarios. |
@divega Is someone having a hard look a SqlClient for these performance improvements, would likely hit a wider audience? |
There are some PRAGMAs that change the functional behavior of the connection. If we add a pool, we'll need to consider how we handle these.
There are other statements that alter the connection state, but they're primarily for performance tuning and don't affect functionality. |
Also, extensions (e.g. SpatiaLite) are enabled per-connection. I don't think they can be disabled aside from closing and re-opening the connection. |
I decided this probably isn't a breaking change since we can make the behavioral breaking changes as part of #13826, and add pooling later to improve performance. |
I have a similar situation with PostgreSQL, where various connection state can be changed with parameters. PostgreSQL does contain a (note that Npgsql has a |
SQLite 3.30.0 added support to unload |
Since merging, the CI fail rate increased significantly from ericsink/SQLitePCL.raw#430 Fixes dotnet#16202, unresolves dotnet#13837
Since merging, the CI fail rate increased significantly from ericsink/SQLitePCL.raw#430 Fixes dotnet#16202, unresolves dotnet#13837
@ajcvickers: A simple question I'm sure but ... in the released version I am supposed to call SqliteConnection.ClearPool( SqliteConnection), where do I get the SqliteConnection from? DbContext.Database.GetDbConnection() returns a DbConnection instead. Edit: the parameter type to InitializeDbConnection in SqliteRelationalConnection.cs would seem to suggest that the DbConnection can just be cast down to an SqliteConnection, is that correct? Would be nice to note this in the Breaking Changes document. |
@sjb-sjb SqliteConnection inherits from DbConnetion. If you are using Sqlite, then your DbConnection is a SqliteConnection. |
@sjb-sjb How is this a breaking change? |
The breaking change was that connection pooling results in the file being locked for longer than before. To unlock the file you need to call ClearPool. In my case when my UI program is in the background for a long time then I want to release the file so that OneDrive can copy it. The breaking change page talks about calling SqliteConnection.ClearPool but doesn't say how to get the SqliteConnection. |
@sjb-sjb I'll bring it up with the team, but that seems like an extremely basic thing that anyone using C# should understand. |
Fair enough. I guess the reason I was confused was I assumed that SqliteConnection would be provided by the sqlite engine rather than by EF Core, so it wasn't a natural conclusion for me that it would be derived from an EF class. |
DbConnection is not an EF class. |
We did add a breaking change note about it here. |
I'm not trying to be hard-headed here. I know there is a breaking change note for EF, thanks, that's great. I'm just giving you the feedback that it would be nice if the breaking change note said "The SqliteConnection can be obtained by casting DbContext.Database.GetDbConnection() to SqliteConnection". It would save time poking around in the source code and bugging you nice folks in an attempt to figure it out. I know it's obvious to you but it wasn't very obvious to me for whatever reason. |
Pooling connections will improve performance--especially when using encryption which makes opening a connection more expensive. (Part of https://github.com/aspnet/Microsoft.Data.Sqlite/issues/412)
This would also allow us to make
CreateFunction()
, etc. calls persist between closing and re-opening a connection obviating the need for https://github.com/aspnet/Microsoft.Data.Sqlite/issues/354.The text was updated successfully, but these errors were encountered: