-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Using sqlx + sqlite in goroutines with GOMAXPROCS > 1 #120
Comments
Maybe a proof-of-concept with using standard |
Indeed, I'd try |
Hi marbemac, I suspect this is related to sqlite3 or the sqlite3 driver. A quick examination of the sqlite3 driver shows that it's using the SQLITE_OPEN_FULLMUTEX open mode (which opens it in serialized threaded mode) and that it also checks that sqlite was compiled in multi-threaded mode, so the kind of obvious looking bug doesn't seem to be present.
It is possible that sqlx is somehow misusing |
I use sqlx to open the DB, but you're correct in that this might be a sqlite3 specific issue. I've generalized the example code a bit more so that you can give it a shot when you have a second: If you run the server in that example and then use apache bench or similar it errors out.
|
The linked test program from https://play.golang.org/p/2w8nWrwV1u is just spawning goroutines without any attempt at limiting concurrency. This ends up calling sqlite C code, which needs real threads. The initial error output (running with Go 1.8.1 on macOS 10.12.4) is:
The reported A similar discussion: You can avoid this issue by not permitting unlimited concurrency against the database (sqlite), which constrains the number of sqlite C calls.
I agree that there's nothing sqlx can do here. |
Hi, I'm trying to use sqlx in a non-blocking manner in a http.Handler. To do this I put the sqlx code in a goroutine. Everything works OK until I set GOMAXPROCS > 1, when it starts panicking under load.
This code errors when you throw a decent number of requests at it:
https://play.golang.org/p/JzdcbvkrvU
Bench the server with wrk or similar
I'm relatively new to go, and could be missing some obvious no-no with GOMAXPROCS and goroutines. If anybody could point me in the right direction I'd appreciate it.
The errors look like this:
The text was updated successfully, but these errors were encountered: