Giorgi / DuckDB.NET

Bindings and ADO.NET Provider for DuckDB
https://duckdb.net
MIT License
356 stars 62 forks source link

Finer grain locking to decrease contention in ConnectionManager #19

Closed SartorialOffense closed 2 years ago

SartorialOffense commented 2 years ago

Did the work in a couple steps: 1) Added a simple test to show how many open/closes could be done per second, 2) switched to locking on the Dictionary and the contained file references separately (4X speed improvement), 3) changed to using a ConcurrentDictionary (no measurable improvement). Also simplified some things and removed the Interlock code because it isn't needed with the locking. Also made the threading tests a little longer to make sure. Have not seen any anomalies.

Giorgi commented 2 years ago

I noticed that Close no longer throws an exception if the connection is already closed. Can you fix that in this PR too?

SartorialOffense commented 2 years ago

Sure. I added this in but made sure it doesn't throw if Disposed() is called multiple times as per MS. It will throw if you Dispose() then Close() or Close() twice - I think this is your goal. Have test cases for all these. Also made some simplifications in the test project.