open with databases with C.SQLITE_OPEN_NOMUTEX

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 https://github.com/mattn/go-sqlite3/issues/249
This commit is contained in:
Frank Braun 2015-11-30 00:09:43 +00:00
parent 60160a1594
commit 9314beb63f
1 changed files with 1 additions and 1 deletions

View File

@ -346,7 +346,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
name := C.CString(dsn)
defer C.free(unsafe.Pointer(name))
rv := C._sqlite3_open_v2(name, &db,
C.SQLITE_OPEN_FULLMUTEX|
C.SQLITE_OPEN_NOMUTEX|
C.SQLITE_OPEN_READWRITE|
C.SQLITE_OPEN_CREATE,
nil)