Quellcode durchsuchen

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 vor 3 Jahren
Ursprung
Commit
5eed48c077
5 geänderte Dateien mit 23 neuen und 0 gelöschten Zeilen
  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 Datei anzeigen

@@ -745,6 +745,9 @@ datastore:
745 745
         password: "hunter2"
746 746
         history-database: "oragono_history"
747 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 752
 # languages config
750 753
 languages:

+ 7
- 0
irc/config.go Datei anzeigen

@@ -18,6 +18,7 @@ import (
18 18
 	"path/filepath"
19 19
 	"reflect"
20 20
 	"regexp"
21
+	"runtime"
21 22
 	"strconv"
22 23
 	"strings"
23 24
 	"time"
@@ -1478,6 +1479,12 @@ func LoadConfig(filename string) (config *Config, err error) {
1478 1479
 
1479 1480
 	config.Datastore.MySQL.ExpireTime = time.Duration(config.History.Restrictions.ExpireTime)
1480 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 1489
 	config.Server.Cloaks.Initialize()
1483 1490
 	if config.Server.Cloaks.Enabled {

+ 2
- 0
irc/mysql/config.go Datei anzeigen

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

+ 8
- 0
irc/mysql/history.go Datei anzeigen

@@ -100,6 +100,14 @@ func (m *MySQL) Open() (err error) {
100 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 111
 	err = m.fixSchemas()
104 112
 	if err != nil {
105 113
 		return err

+ 3
- 0
traditional.yaml Datei anzeigen

@@ -718,6 +718,9 @@ datastore:
718 718
         password: "hunter2"
719 719
         history-database: "oragono_history"
720 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 725
 # languages config
723 726
 languages:

Laden…
Abbrechen
Speichern