Limit max db connections
While load testing mysql compained about too many connections.
This commit is contained in:
parent
46f1bc17c1
commit
d5d19b55bb
|
|
@ -15,13 +15,19 @@ func New(dialect, connection, defaultUser, defaultPass string, strength int) (*G
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// we use the database connection inside the handlers from the http
|
|
||||||
// framework, therefore concurrent access occurs. Sqlite cannot handle
|
// We normally don't need that much connections, so we limit them. F.ex. mysql complains about
|
||||||
// concurrent writes, so we limit sqlite to one connection.
|
// "too many connections", while load testing Gotify.
|
||||||
// see https://github.com/mattn/go-sqlite3/issues/274
|
db.DB().SetMaxOpenConns(10)
|
||||||
|
|
||||||
if dialect == "sqlite3" {
|
if dialect == "sqlite3" {
|
||||||
|
// We use the database connection inside the handlers from the http
|
||||||
|
// framework, therefore concurrent access occurs. Sqlite cannot handle
|
||||||
|
// concurrent writes, so we limit sqlite to one connection.
|
||||||
|
// see https://github.com/mattn/go-sqlite3/issues/274
|
||||||
db.DB().SetMaxOpenConns(1)
|
db.DB().SetMaxOpenConns(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !db.HasTable(new(model.User)) && !db.HasTable(new(model.Message)) &&
|
if !db.HasTable(new(model.User)) && !db.HasTable(new(model.Message)) &&
|
||||||
!db.HasTable(new(model.Client)) && !db.HasTable(new(model.Application)) {
|
!db.HasTable(new(model.Client)) && !db.HasTable(new(model.Application)) {
|
||||||
db.AutoMigrate(new(model.User), new(model.Application), new(model.Message), new(model.Client))
|
db.AutoMigrate(new(model.User), new(model.Application), new(model.Message), new(model.Client))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue