mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
Actually honour max conns globally, not per storage struct
This commit is contained in:
parent
37dcd91e09
commit
c47665f1e8
@ -57,6 +57,10 @@ func NewStorage(postgresURI string) *Storage {
|
||||
// TODO: if we panic(), will sentry have a chance to flush the event?
|
||||
logger.Panic().Err(err).Str("uri", postgresURI).Msg("failed to open SQL DB")
|
||||
}
|
||||
return NewStorageWithDB(db)
|
||||
}
|
||||
|
||||
func NewStorageWithDB(db *sqlx.DB) *Storage {
|
||||
acc := &Accumulator{
|
||||
db: db,
|
||||
roomsTable: NewRoomsTable(db),
|
||||
|
@ -26,6 +26,10 @@ func NewStore(postgresURI, secret string) *Storage {
|
||||
// TODO: if we panic(), will sentry have a chance to flush the event?
|
||||
logger.Panic().Err(err).Str("uri", postgresURI).Msg("failed to open SQL DB")
|
||||
}
|
||||
return NewStoreWithDB(db, secret)
|
||||
}
|
||||
|
||||
func NewStoreWithDB(db *sqlx.DB, secret string) *Storage {
|
||||
return &Storage{
|
||||
DevicesTable: NewDevicesTable(db),
|
||||
TokensTable: NewTokensTable(db, secret),
|
||||
|
30
v3.go
30
v3.go
@ -77,20 +77,24 @@ func Setup(destHomeserver, postgresURI, secret string, opts Opts) (*handler2.Han
|
||||
},
|
||||
DestinationServer: destHomeserver,
|
||||
}
|
||||
store := state.NewStorage(postgresURI)
|
||||
storev2 := sync2.NewStore(postgresURI, secret)
|
||||
for _, db := range []*sqlx.DB{store.DB, storev2.DB} {
|
||||
if opts.DBMaxConns > 0 {
|
||||
// https://github.com/go-sql-driver/mysql#important-settings
|
||||
// "db.SetMaxIdleConns() is recommended to be set same to db.SetMaxOpenConns(). When it is smaller
|
||||
// than SetMaxOpenConns(), connections can be opened and closed much more frequently than you expect."
|
||||
db.SetMaxOpenConns(opts.DBMaxConns)
|
||||
db.SetMaxIdleConns(opts.DBMaxConns)
|
||||
}
|
||||
if opts.DBConnMaxIdleTime > 0 {
|
||||
db.SetConnMaxIdleTime(opts.DBConnMaxIdleTime)
|
||||
}
|
||||
db, err := sqlx.Open("postgres", postgresURI)
|
||||
if err != nil {
|
||||
sentry.CaptureException(err)
|
||||
// TODO: if we panic(), will sentry have a chance to flush the event?
|
||||
logger.Panic().Err(err).Str("uri", postgresURI).Msg("failed to open SQL DB")
|
||||
}
|
||||
if opts.DBMaxConns > 0 {
|
||||
// https://github.com/go-sql-driver/mysql#important-settings
|
||||
// "db.SetMaxIdleConns() is recommended to be set same to db.SetMaxOpenConns(). When it is smaller
|
||||
// than SetMaxOpenConns(), connections can be opened and closed much more frequently than you expect."
|
||||
db.SetMaxOpenConns(opts.DBMaxConns)
|
||||
db.SetMaxIdleConns(opts.DBMaxConns)
|
||||
}
|
||||
if opts.DBConnMaxIdleTime > 0 {
|
||||
db.SetConnMaxIdleTime(opts.DBConnMaxIdleTime)
|
||||
}
|
||||
store := state.NewStorageWithDB(db)
|
||||
storev2 := sync2.NewStoreWithDB(db, secret)
|
||||
bufferSize := 50
|
||||
deviceDataUpdateFrequency := time.Second
|
||||
if opts.TestingSynchronousPubsub {
|
||||
|
Loading…
x
Reference in New Issue
Block a user