-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Is it better to open SQLite in multi-thread mode? #249
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
Comments
I don't think that SQLITE_THREADSAFE affect only for sql.Open. |
Instead of C.SQLITE_OPEN_FULLMUTEX. With the currently used combination of flags in https://github.com/mattn/go-sqlite3/blob/master/sqlite3.go (compilation with -DSQLITE_THREADSAFE and sqlite3_open_v2() called with flag SQLITE_OPEN_FULLMUTEX) SQLite database files are opened in serialized mode (https://www.sqlite.org/threadsafe.html). Since sql.Open() (https://golang.org/pkg/database/sql/#Open) is safe for concurrent use by multiple goroutines it should be enough to open SQLite database files in multi-thread mode (flag SQLITE_OPEN_NOMUTEX instead of SQLITE_OPEN_FULLMUTEX). This should also improve performance. See also mattn/go-sqlite3#249
I agree with @frankbraun. As https://www.sqlite.org/threadsafe.html says, when using -DSQLITE_THREADSAFE=1 and SQLITE_OPEN_NOMUTEX, the SQLite is in Multi-thread mode. As SQLite's source code shows, when in Multi-thread mode, the SQLite still has an CoreMutex.
Since the Package sql already used mutex on connections, the SQlite's bFullMutex on connections is a bit redundant. Just using -DSQLITE_THREADSAFE=1 and SQLITE_OPEN_NOMUTEX is enough. |
How about to add |
Closed by #540 |
With the currently used combination of flags in https://github.com/mattn/go-sqlite3/blob/master/sqlite3.go (compilation with
-DSQLITE_THREADSAFE
andsqlite3_open_v2()
called with flagSQLITE_OPEN_FULLMUTEX
) SQLite database files are opened in serialized mode (see https://www.sqlite.org/threadsafe.html).Since
sql.Open()
(https://golang.org/pkg/database/sql/#Open) is safe for concurrent use by multiple goroutines it should be enough to open SQLite database files in multi-thread mode (flagSQLITE_OPEN_NOMUTEX
instead ofSQLITE_OPEN_FULLMUTEX
). This should also improve performance.Or am I missing something?
The text was updated successfully, but these errors were encountered: