Skip to content

Commit

Permalink
Make Aerospike client connection queue size configurable (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
guscarreon authored Jan 17, 2023
1 parent 32b8f8e commit 918c220
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
6 changes: 6 additions & 0 deletions backends/aerospike.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func NewAerospikeBackend(cfg config.Aerospike, metrics *metrics.Metrics) *Aerosp
clientPolicy.IdleTimeout = time.Duration(cfg.ConnIdleTimeoutSecs) * time.Second
}

// Aerospike's default connection queue size per node is 256.
// If cfg.ConnQueueSize is greater than zero, it will override the default.
if cfg.ConnQueueSize > 0 {
clientPolicy.ConnectionQueueSize = cfg.ConnQueueSize
}

if len(cfg.Host) > 1 {
hosts = append(hosts, as.NewHost(cfg.Host, cfg.Port))
log.Info("config.backend.aerospike.host is being deprecated in favor of config.backend.aerospike.hosts")
Expand Down
8 changes: 8 additions & 0 deletions config/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type Aerospike struct {
// tries to use it. If set to a value less than or equal to 0, Aerospike
// Client's default value will be used which is 55 seconds.
ConnIdleTimeoutSecs int `mapstructure:"connection_idle_timeout_seconds"`
// Specifies the size of the connection queue per node.
ConnQueueSize int `mapstructure:"connection_queue_size"`
}

func (cfg *Aerospike) validateAndLog() error {
Expand Down Expand Up @@ -99,6 +101,12 @@ func (cfg *Aerospike) validateAndLog() error {
log.Infof("config.backend.aerospike.max_write_retries: %d.", cfg.MaxWriteRetries)
}

if cfg.ConnQueueSize > 0 {
log.Infof("config.backend.aerospike.connection_queue_size: %d", cfg.ConnQueueSize)
} else {
log.Infof("config.backend.aerospike.connection_queue_size value will default to 256")
}

return nil
}

Expand Down
48 changes: 47 additions & 1 deletion config/backends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestAerospikeValidateAndLog(t *testing.T) {
{msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size value will default to 256", lvl: logrus.InfoLevel},
},
},
{
Expand All @@ -62,6 +63,7 @@ func TestAerospikeValidateAndLog(t *testing.T) {
{msg: "config.backend.aerospike.namespace: prebid", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.user: prebid-user", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size value will default to 256", lvl: logrus.InfoLevel},
},
},
{
Expand All @@ -78,6 +80,7 @@ func TestAerospikeValidateAndLog(t *testing.T) {
{msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size value will default to 256", lvl: logrus.InfoLevel},
},
},
{
Expand All @@ -95,6 +98,7 @@ func TestAerospikeValidateAndLog(t *testing.T) {
{msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size value will default to 256", lvl: logrus.InfoLevel},
},
},
{
Expand All @@ -114,6 +118,7 @@ func TestAerospikeValidateAndLog(t *testing.T) {
{msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.default_ttl_seconds: 3600. Note that this configuration option is being deprecated in favor of config.request_limits.max_ttl_seconds", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size value will default to 256", lvl: logrus.InfoLevel},
},
},
{
Expand All @@ -131,6 +136,7 @@ func TestAerospikeValidateAndLog(t *testing.T) {
{msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size value will default to 256", lvl: logrus.InfoLevel},
},
},
{
Expand All @@ -148,10 +154,11 @@ func TestAerospikeValidateAndLog(t *testing.T) {
{msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_read_retries: 3.", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size value will default to 256", lvl: logrus.InfoLevel},
},
},
{
desc: "aerospike.max_write_retries invalid value. Default to 2 retries",
desc: "aerospike.max_write_retries invalid value. Default to 0 retries",
inCfg: Aerospike{
Host: "foo.com",
Port: 8888,
Expand All @@ -166,6 +173,7 @@ func TestAerospikeValidateAndLog(t *testing.T) {
{msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_write_retries value cannot be negative and will default to 0", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size value will default to 256", lvl: logrus.InfoLevel},
},
},
{
Expand All @@ -184,6 +192,7 @@ func TestAerospikeValidateAndLog(t *testing.T) {
{msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_write_retries: 1.", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size value will default to 256", lvl: logrus.InfoLevel},
},
},
{
Expand All @@ -202,6 +211,43 @@ func TestAerospikeValidateAndLog(t *testing.T) {
{msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_idle_timeout_seconds: 1.", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size value will default to 256", lvl: logrus.InfoLevel},
},
},
{
desc: "config.backend.aerospike.connection_queue_size invalid value found in config",
inCfg: Aerospike{
Host: "foo.com",
Port: 8888,
ConnQueueSize: -1,
},
hasError: false,
logEntries: []logComponents{
{msg: "config.backend.aerospike.host: foo.com", lvl: logrus.InfoLevel},
{msg: fmt.Sprintf("config.backend.aerospike.hosts: %v", []string{}), lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.port: 8888", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size value will default to 256", lvl: logrus.InfoLevel},
},
},
{
desc: "config.backend.aerospike.connection_queue_size valid value found in config",
inCfg: Aerospike{
Host: "foo.com",
Port: 8888,
ConnQueueSize: 64,
},
hasError: false,
logEntries: []logComponents{
{msg: "config.backend.aerospike.host: foo.com", lvl: logrus.InfoLevel},
{msg: fmt.Sprintf("config.backend.aerospike.hosts: %v", []string{}), lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.port: 8888", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel},
{msg: "config.backend.aerospike.connection_queue_size: 64", lvl: logrus.InfoLevel},
},
},
},
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func setConfigDefaults(v *viper.Viper) {
v.SetDefault("backend.aerospike.max_read_retries", 2)
v.SetDefault("backend.aerospike.max_write_retries", 0)
v.SetDefault("backend.aerospike.connection_idle_timeout_seconds", 0)
v.SetDefault("backend.aerospike.connection_queue_size", 0)
v.SetDefault("backend.cassandra.hosts", "")
v.SetDefault("backend.cassandra.keyspace", "")
v.SetDefault("backend.cassandra.default_ttl_seconds", utils.CASSANDRA_DEFAULT_TTL_SECONDS)
Expand Down

0 comments on commit 918c220

Please sign in to comment.