Skip to content

Commit

Permalink
Increase default diagnostic connection check interval and make it con…
Browse files Browse the repository at this point in the history
…figurable
  • Loading branch information
PatrickTaibel committed Sep 12, 2023
1 parent d889050 commit 6620538
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
4 changes: 3 additions & 1 deletion doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Configuration can be handled either via command-line arguments or via config fil
-remoteTimeout=0: Timeout to set for remote redises (connect+read+write)
-remoteWriteTimeout=0: Timeout to set for remote redises (write)
-remoteReconnectInterval=0: Interval in which connected redis connections will be forced to reconnect in minutes
-remoteDiagnosticCheckInterval=0: Interval to check the diagnostic connection in seconds
-socket="": The socket to listen for incoming connections on. If this is provided, host and port are ignored
-tcpConnections="localhost:6380 localhost:6381": TCP connections (destination redis servers) to multiplex over
-unixConnections="": Unix connections (destination redis servers) to multiplex over
Expand Down Expand Up @@ -48,7 +49,8 @@ for the configuration json is as follows:
"remoteReadTimeout": int,
"remoteWriteTimeout": int,
"remoteConnectTimeout": int,
"remoteReconnectInterval": int
"remoteReconnectInterval": int,
"remoteDiagnosticCheckInterval": int
},
...
]
Expand Down
39 changes: 20 additions & 19 deletions main/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,26 @@ import (
)

type PoolConfig struct {
Host string `json:"host"`
Port int `json:"port"`
Socket string `json:"socket"`
MaxProcesses int `json:"maxProcesses"`
PoolSize int `json:"poolSize"`
TcpConnections []string `json:"tcpConnections"`
UnixConnections []string `json:"unixConnections"`
AuthUser string `json:"authUser"`
AuthPassword string `json:"authPassword"`
LocalTimeout int64 `json:"localTimeout"`
LocalReadTimeout int64 `json:"localReadTimeout"`
LocalWriteTimeout int64 `json:"localWriteTimeout"`
LocalTransactionTimeout int64 `json:"localTransactionTimeout"`
RemoteTimeout int64 `json:"remoteTimeout"`
RemoteReadTimeout int64 `json:"remoteReadTimeout"`
RemoteWriteTimeout int64 `json:"remoteWriteTimeout"`
RemoteReconnectInterval int64 `json:"remoteReconnectInterval"`
RemoteConnectTimeout int64 `json:"remoteConnectTimeout"`
Failover bool `json:"failover"`
Host string `json:"host"`
Port int `json:"port"`
Socket string `json:"socket"`
MaxProcesses int `json:"maxProcesses"`
PoolSize int `json:"poolSize"`
TcpConnections []string `json:"tcpConnections"`
UnixConnections []string `json:"unixConnections"`
AuthUser string `json:"authUser"`
AuthPassword string `json:"authPassword"`
LocalTimeout int64 `json:"localTimeout"`
LocalReadTimeout int64 `json:"localReadTimeout"`
LocalWriteTimeout int64 `json:"localWriteTimeout"`
LocalTransactionTimeout int64 `json:"localTransactionTimeout"`
RemoteTimeout int64 `json:"remoteTimeout"`
RemoteReadTimeout int64 `json:"remoteReadTimeout"`
RemoteWriteTimeout int64 `json:"remoteWriteTimeout"`
RemoteReconnectInterval int64 `json:"remoteReconnectInterval"`
RemoteDiagnosticCheckInterval int64 `json:"remoteDiagnosticCheckInterval"`
RemoteConnectTimeout int64 `json:"remoteConnectTimeout"`
Failover bool `json:"failover"`
}

func ReadConfigFromFile(configFile string) ([]PoolConfig, error) {
Expand Down
18 changes: 13 additions & 5 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var remoteReadTimeout = flag.Int64("remoteReadTimeout", 0, "Timeout to set for r
var remoteWriteTimeout = flag.Int64("remoteWriteTimeout", 0, "Timeout to set for remote redises (write)")
var remoteConnectTimeout = flag.Int64("remoteConnectTimeout", 0, "Timeout to set for remote redises (connect)")
var remoteReconnectInterval = flag.Int64("remoteReconnectInterval", 0, "Interval in which connected redis connections will be forced to reconnect in minutes")
var remoteDiagnosticCheckInterval = flag.Int64("remoteDiagnosticCheckInterval", 0, "Interval to check the diagnostic connection in seconds")
var cpuProfile = flag.String("cpuProfile", "", "Direct CPU Profile to target file")
var configFile = flag.String("config", "", "Configuration file (JSON)")
var doDebug = flag.Bool("debug", false, "Debug mode")
Expand Down Expand Up @@ -149,11 +150,12 @@ func configureFromArgs() ([]PoolConfig, error) {
LocalWriteTimeout: *localWriteTimeout,
LocalTransactionTimeout: *localTransactionTimeout,

RemoteTimeout: *remoteTimeout,
RemoteReadTimeout: *remoteReadTimeout,
RemoteWriteTimeout: *remoteWriteTimeout,
RemoteConnectTimeout: *remoteConnectTimeout,
RemoteReconnectInterval: *remoteReconnectInterval,
RemoteTimeout: *remoteTimeout,
RemoteReadTimeout: *remoteReadTimeout,
RemoteWriteTimeout: *remoteWriteTimeout,
RemoteConnectTimeout: *remoteConnectTimeout,
RemoteReconnectInterval: *remoteReconnectInterval,
RemoteDiagnosticCheckInterval: *remoteDiagnosticCheckInterval,
}}

return config, nil
Expand Down Expand Up @@ -265,6 +267,12 @@ func createInstances(configs []PoolConfig) (rmuxInstances []*rmux.RedisMultiplex
log.Info("Setting remote reconnect interval to: %s", interval)
}

if config.RemoteDiagnosticCheckInterval != 0 {
interval := time.Duration(config.RemoteDiagnosticCheckInterval) * time.Second
rmuxInstance.EndpointDiagnosticCheckInterval = interval
log.Info("Setting remote diagnostic check interval to: %s", interval)
}

rmuxInstance.AuthUser = config.AuthUser
rmuxInstance.AuthPassword = config.AuthPassword

Expand Down
7 changes: 6 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ var (
MULTIPLEX_OPERATION_UNSUPPORTED_RESPONSE = []byte("This command is not supported for multiplexing servers")
//Response code for when a client can't connect to any target servers
CONNECTION_DOWN_RESPONSE = []byte("Connection down")
//Default diagnostic check interval
EXTERN_DIAGNOSTIC_CHECK_INTERVAL = 1 * time.Second
)

var version string = "dev"
Expand Down Expand Up @@ -77,6 +79,8 @@ type RedisMultiplexer struct {
EndpointWriteTimeout time.Duration
//An overridable reconnection interval. Defaults to EXTERN_RECONNECT_INTERVAL
EndpointReconnectInterval time.Duration
//An overridable diagnostic check interval. Defaults to EXTERN_DIAGNOSTIC_CHECK_INTERVAL
EndpointDiagnosticCheckInterval time.Duration
//An overridable read timeout. Defaults to EXTERN_READ_TIMEOUT
ClientReadTimeout time.Duration
//An overridable write timeout. Defaults to EXTERN_WRITE_TIMEOUT
Expand Down Expand Up @@ -134,6 +138,7 @@ func NewRedisMultiplexer(listenProtocol, listenEndpoint string, poolSize int) (n
newRedisMultiplexer.EndpointReadTimeout = connection.EXTERN_READ_TIMEOUT
newRedisMultiplexer.EndpointWriteTimeout = connection.EXTERN_WRITE_TIMEOUT
newRedisMultiplexer.EndpointReconnectInterval = connection.EXTERN_RECONNECT_INTERVAL
newRedisMultiplexer.EndpointDiagnosticCheckInterval = EXTERN_DIAGNOSTIC_CHECK_INTERVAL
newRedisMultiplexer.ClientReadTimeout = connection.EXTERN_READ_TIMEOUT
newRedisMultiplexer.ClientWriteTimeout = connection.EXTERN_WRITE_TIMEOUT
newRedisMultiplexer.ClientTransactionTimeout = EXTERN_TRANSACTION_TIMEOUT
Expand Down Expand Up @@ -180,7 +185,7 @@ func (this *RedisMultiplexer) maintainConnectionStates() {
runtime.ReadMemStats(&m)
// // Debug("Memory profile: InUse(%d) Idle (%d) Released(%d)", m.HeapInuse, m.HeapIdle, m.HeapReleased)
this.generateMultiplexInfo()
time.Sleep(100 * time.Millisecond)
time.Sleep(this.EndpointDiagnosticCheckInterval)
}
}

Expand Down

0 comments on commit 6620538

Please sign in to comment.