Sfoglia il codice sorgente

fix #1622

Allow users to set max MySQL connections and connection lifetime;
set a sane default for max connections if it's not present.
tags/v2.7.0-rc1
Shivaram Lingamneni 3 anni fa
parent
commit
5eed48c077
5 ha cambiato i file con 23 aggiunte e 0 eliminazioni
  1. 3
    0
      default.yaml
  2. 7
    0
      irc/config.go
  3. 2
    0
      irc/mysql/config.go
  4. 8
    0
      irc/mysql/history.go
  5. 3
    0
      traditional.yaml

+ 3
- 0
default.yaml Vedi File

745
         password: "hunter2"
745
         password: "hunter2"
746
         history-database: "oragono_history"
746
         history-database: "oragono_history"
747
         timeout: 3s
747
         timeout: 3s
748
+        max-conns: 4
749
+        # this may be necessary to prevent middleware from closing your connections:
750
+        #conn-max-lifetime: 180s
748
 
751
 
749
 # languages config
752
 # languages config
750
 languages:
753
 languages:

+ 7
- 0
irc/config.go Vedi File

18
 	"path/filepath"
18
 	"path/filepath"
19
 	"reflect"
19
 	"reflect"
20
 	"regexp"
20
 	"regexp"
21
+	"runtime"
21
 	"strconv"
22
 	"strconv"
22
 	"strings"
23
 	"strings"
23
 	"time"
24
 	"time"
1478
 
1479
 
1479
 	config.Datastore.MySQL.ExpireTime = time.Duration(config.History.Restrictions.ExpireTime)
1480
 	config.Datastore.MySQL.ExpireTime = time.Duration(config.History.Restrictions.ExpireTime)
1480
 	config.Datastore.MySQL.TrackAccountMessages = config.History.Retention.EnableAccountIndexing
1481
 	config.Datastore.MySQL.TrackAccountMessages = config.History.Retention.EnableAccountIndexing
1482
+	if config.Datastore.MySQL.MaxConns == 0 {
1483
+		// #1622: not putting an upper limit on the number of MySQL connections is
1484
+		// potentially dangerous. as a naive heuristic, assume they're running on the
1485
+		// same machine:
1486
+		config.Datastore.MySQL.MaxConns = runtime.NumCPU()
1487
+	}
1481
 
1488
 
1482
 	config.Server.Cloaks.Initialize()
1489
 	config.Server.Cloaks.Initialize()
1483
 	if config.Server.Cloaks.Enabled {
1490
 	if config.Server.Cloaks.Enabled {

+ 2
- 0
irc/mysql/config.go Vedi File

17
 	Password        string
17
 	Password        string
18
 	HistoryDatabase string `yaml:"history-database"`
18
 	HistoryDatabase string `yaml:"history-database"`
19
 	Timeout         time.Duration
19
 	Timeout         time.Duration
20
+	MaxConns        int           `yaml:"max-conns"`
21
+	ConnMaxLifetime time.Duration `yaml:"conn-max-lifetime"`
20
 
22
 
21
 	// XXX these are copied from elsewhere in the config:
23
 	// XXX these are copied from elsewhere in the config:
22
 	ExpireTime           time.Duration
24
 	ExpireTime           time.Duration

+ 8
- 0
irc/mysql/history.go Vedi File

100
 		return err
100
 		return err
101
 	}
101
 	}
102
 
102
 
103
+	if m.config.MaxConns != 0 {
104
+		m.db.SetMaxOpenConns(m.config.MaxConns)
105
+		m.db.SetMaxIdleConns(m.config.MaxConns)
106
+	}
107
+	if m.config.ConnMaxLifetime != 0 {
108
+		m.db.SetConnMaxLifetime(m.config.ConnMaxLifetime)
109
+	}
110
+
103
 	err = m.fixSchemas()
111
 	err = m.fixSchemas()
104
 	if err != nil {
112
 	if err != nil {
105
 		return err
113
 		return err

+ 3
- 0
traditional.yaml Vedi File

718
         password: "hunter2"
718
         password: "hunter2"
719
         history-database: "oragono_history"
719
         history-database: "oragono_history"
720
         timeout: 3s
720
         timeout: 3s
721
+        max-conns: 4
722
+        # this may be necessary to prevent middleware from closing your connections:
723
+        #conn-max-lifetime: 180s
721
 
724
 
722
 # languages config
725
 # languages config
723
 languages:
726
 languages:

Loading…
Annulla
Salva