Merge branch '11638-limit-conns'
authorTom Clegg <tom@curoverse.com>
Mon, 8 May 2017 20:04:59 +0000 (16:04 -0400)
committerTom Clegg <tom@curoverse.com>
Mon, 8 May 2017 20:04:59 +0000 (16:04 -0400)
closes #11638

services/ws/config.go
services/ws/event_source.go
services/ws/server.go

index 0faa863d82e361ccf8f61ed70dfb2c12a292a978..79c2f232daf5059c4b51f7d1bb2fa27a592c5f64 100644 (file)
@@ -7,11 +7,12 @@ import (
 )
 
 type wsConfig struct {
-       Client    arvados.Client
-       Postgres  pgConfig
-       Listen    string
-       LogLevel  string
-       LogFormat string
+       Client       arvados.Client
+       Postgres     pgConfig
+       PostgresPool int
+       Listen       string
+       LogLevel     string
+       LogFormat    string
 
        PingTimeout      arvados.Duration
        ClientEventQueue int
@@ -24,13 +25,15 @@ func defaultConfig() wsConfig {
                        APIHost: "localhost:443",
                },
                Postgres: pgConfig{
-                       "dbname":          "arvados_production",
-                       "user":            "arvados",
-                       "password":        "xyzzy",
-                       "host":            "localhost",
-                       "connect_timeout": "30",
-                       "sslmode":         "require",
+                       "dbname":                    "arvados_production",
+                       "user":                      "arvados",
+                       "password":                  "xyzzy",
+                       "host":                      "localhost",
+                       "connect_timeout":           "30",
+                       "sslmode":                   "require",
+                       "fallback_application_name": "arvados-ws",
                },
+               PostgresPool:     64,
                LogLevel:         "info",
                LogFormat:        "json",
                PingTimeout:      arvados.Duration(time.Minute),
index fe1876cc2788e9ccaaaff2f1f21d3116b3974b38..7c1b58492dd030ef6b579abe8b699d787a758cc2 100644 (file)
@@ -29,8 +29,9 @@ func (c pgConfig) ConnectionString() string {
 }
 
 type pgEventSource struct {
-       DataSource string
-       QueueSize  int
+       DataSource   string
+       MaxOpenConns int
+       QueueSize    int
 
        db         *sql.DB
        pqListener *pq.Listener
@@ -115,6 +116,10 @@ func (ps *pgEventSource) Run() {
                logger(nil).WithError(err).Error("sql.Open failed")
                return
        }
+       if ps.MaxOpenConns <= 0 {
+               logger(nil).Warn("no database connection limit configured -- consider setting PostgresPool>0 in arvados-ws configuration file")
+       }
+       db.SetMaxOpenConns(ps.MaxOpenConns)
        if err = db.Ping(); err != nil {
                logger(nil).WithError(err).Error("db.Ping failed")
                return
index 8870ca1df4a7f01a20b21b48b676a20cb16cc5ad..059b073fb1f47b34f4a82cef89e807983ce7fe21 100644 (file)
@@ -44,8 +44,9 @@ func (srv *server) setup() {
 
        srv.listener = ln
        srv.eventSource = &pgEventSource{
-               DataSource: srv.wsConfig.Postgres.ConnectionString(),
-               QueueSize:  srv.wsConfig.ServerEventQueue,
+               DataSource:   srv.wsConfig.Postgres.ConnectionString(),
+               MaxOpenConns: srv.wsConfig.PostgresPool,
+               QueueSize:    srv.wsConfig.ServerEventQueue,
        }
        srv.httpServer = &http.Server{
                Addr:           srv.wsConfig.Listen,