Connect with using Multi-threaded Mode in dotnet
(1) By anonymous on 2022-07-30 23:02:20 [source]
Hello,
I'm using System.Data.SQLite, and I'm wondering how to set the Multi-threading mode, per https://www.sqlite.org/threadsafe.html.
Thank you! -Andrew
(2) By jose isaias cabrera (jicman) on 2022-07-31 12:54:34 in reply to 1 [link] [source]
A quick web search gave me this link. I would say, start with that.
josé
(3) By Keith Medcalf (kmedcalf) on 2022-07-31 16:22:09 in reply to 1 [link] [source]
Why would you wnt to change it from the default?
(4) By Andrew (AndrewC) on 2022-08-01 17:29:21 in reply to 3 [link] [source]
Serialized is the default, and that seems overly restrictive. I don't want to serialize all my access to the DB, and SQLite does support multi-threading, as long as I'm careful with how I share my connection objects.
In short: I'd like to performance test what I hope will be a more performance mode.
(5) By Keith Medcalf (kmedcalf) on 2022-08-01 20:14:16 in reply to 4 [link] [source]
In what way is it overly restrictive? Assuming that you do properly all the things that you need to be doing and comply with the entrance requirements, the only difference between serialized and multithreaded mode is that you are turning off the "belt and suspenders" that ensures you behave properly.
This would probably save you a couple of nanoseconds per library entrance while your "properness" is being checked.
However, if you turn off the "belt and suspenders" then if you behave improperly the library will not stop you from killing yourself and corrupting all your data.
Multithreading is supported by default. No changes are necessary.
(6) By Andrew (AndrewC) on 2022-08-01 21:46:03 in reply to 5 [link] [source]
Perhaps I'm not familiar enough with how SQLite works under the hood.
I have found that under serialized mode only one write can happen at a time, even using multiple connections (i.e. one connection per writing thread). I hoped that under multi-threading mode I could have multiple writes occur simultaneously, i.e. they wouldn't block on each other. But maybe that's not true? I just read,
https://www.sqlite.org/lockingv3.html
and it seems like only one write to the database is possible at a time. In Serialized Mode can multiple reads occur from multiple connections simultaneously?
Thanks for your thoughts on this.
(7) By Keith Medcalf (kmedcalf) on 2022-08-02 01:42:44 in reply to 6 [link] [source]
only one write to the database is possible at a time
Correct. Only one connection may write to the database at a time. Multiple statements may be running on the one connection, however.
In Serialized Mode can multiple reads occur from multiple connections simultaneously?
Yes.
(8) By mistachkin on 2022-08-02 18:40:14 in reply to 1 [link] [source]
Changing the threading mode in System.Data.SQLite is not supported.