Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add max queue size config #107

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ $ go get github.com/Trendyol/go-dcp
| `scopeName` | string | no | _default | Couchbase scope name. |
| `collectionNames` | []string | no | _default | Couchbase collection names. |
| `connectionBufferSize` | uint, string | no | 20mb | [gocbcore](github.com/couchbase/gocbcore) library buffer size. `20mb` is default. Check this if you get OOM Killed. |
| `maxQueueSize` | int | no | 2048 | The maximum number of requests that can be queued waiting to be sent to a node. `2048` is default. Check this if you get queue overflowed or queue full. |
| `connectionTimeout` | time.Duration | no | 5s | Couchbase connection timeout. |
| `secureConnection` | bool | no | false | Enable TLS connection of Couchbase. |
| `rootCAPath` | string | no | *not set | if `secureConnection` set `true` this field is required. |
| `debug` | bool | no | false | For debugging purpose. |
| `dcp.bufferSize` | int | no | 16mb | Go DCP listener pre-allocated buffer size. `16mb` is default. Check this if you get OOM Killed. |
| `dcp.connectionBufferSize` | uint, string | no | 20mb | [gocbcore](github.com/couchbase/gocbcore) library buffer size. `20mb` is default. Check this if you get OOM Killed. |
| `dcp.connectionTimeout` | time.Duration | no | 5s | DCP connection timeout. |
| `dcp.maxQueueSize` | int | no | 2048 | The maximum number of requests that can be queued waiting to be sent to a node. `2048` is default. Check this if you get queue overflowed or queue full. |
| `dcp.listener.bufferSize` | uint | no | 1000 | Go DCP listener buffered channel size. |
| `dcp.listener.skipUntil` | time.Time | no | | Set this if you want to skip events until certain time. |
| `dcp.group.membership.type` | string | no | | DCP membership types. `couchbase`, `kubernetesHa`, `kubernetesStatefulSet`, `static` or `dynamic`. Check examples for details. |
Expand Down
13 changes: 13 additions & 0 deletions config/dcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type ExternalDcp struct {
ConnectionBufferSize any `yaml:"connectionBufferSize"`
Listener DCPListener `yaml:"listener"`
Group DCPGroup `yaml:"group"`
MaxQueueSize int `yaml:"maxQueueSize"`
ConnectionTimeout time.Duration `yaml:"connectionTimeout"`
Config ExternalDcpConfig `yaml:"config"`
}
Expand Down Expand Up @@ -134,6 +135,7 @@ type Dcp struct {
HealthCheck HealthCheck `yaml:"healthCheck"`
RollbackMitigation RollbackMitigation `yaml:"rollbackMitigation"`
API API `yaml:"api"`
MaxQueueSize int `yaml:"maxQueueSize"`
ConnectionTimeout time.Duration `yaml:"connectionTimeout"`
SecureConnection bool `yaml:"secureConnection"`
Debug bool `yaml:"debug"`
Expand Down Expand Up @@ -356,6 +358,7 @@ func (c *Dcp) ApplyDefaults() {
c.applyDefaultCollections()
c.applyDefaultScopeName()
c.applyDefaultConnectionBufferSize()
c.applyDefaultMaxQueueSize()
c.applyDefaultMetrics()
c.applyDefaultAPI()
c.applyDefaultLeaderElection()
Expand Down Expand Up @@ -468,6 +471,12 @@ func (c *Dcp) applyDefaultConnectionBufferSize() {
}
}

func (c *Dcp) applyDefaultMaxQueueSize() {
if c.MaxQueueSize == 0 {
c.MaxQueueSize = 2048
}
}

func (c *Dcp) applyDefaultMetrics() {
if c.Metric.Path == "" {
c.Metric.Path = "/metrics"
Expand Down Expand Up @@ -499,6 +508,10 @@ func (c *Dcp) applyDefaultDcp() {
c.Dcp.ConnectionBufferSize = helpers.ResolveUnionIntOrStringValue("20mb")
}

if c.Dcp.MaxQueueSize == 0 {
c.Dcp.MaxQueueSize = 2048
}

if c.Dcp.Listener.BufferSize == 0 {
c.Dcp.Listener.BufferSize = 1000
}
Expand Down
9 changes: 9 additions & 0 deletions config/dcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ func TestDcpApplyDefaultConnectionBufferSize(t *testing.T) {
}
}

func TestDcpApplyDefaultMaxQueueSize(t *testing.T) {
c := &Dcp{}
c.applyDefaultMaxQueueSize()

if c.MaxQueueSize != 2048 {
t.Errorf("ConnectionBufferSize is not set to expected value")
}
}

func TestDcpApplyDefaultMetrics(t *testing.T) {
c := &Dcp{}
c.applyDefaultMetrics()
Expand Down
11 changes: 7 additions & 4 deletions couchbase/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func CreateSecurityConfig(username string, password string, secureConnection boo

func CreateAgent(httpAddresses []string, bucketName string,
username string, password string, secureConnection bool, rootCAPath string,
connectionBufferSize uint, connectionTimeout time.Duration,
maxQueueSize int, connectionBufferSize uint, connectionTimeout time.Duration,
) (*gocbcore.Agent, error) {
agent, err := gocbcore.CreateAgent(
&gocbcore.AgentConfig{
Expand All @@ -181,6 +181,7 @@ func CreateAgent(httpAddresses []string, bucketName string,
},
KVConfig: gocbcore.KVConfig{
ConnectionBufferSize: connectionBufferSize,
MaxQueueSize: maxQueueSize,
},
},
)
Expand Down Expand Up @@ -210,8 +211,8 @@ func CreateAgent(httpAddresses []string, bucketName string,
return agent, nil
}

func (s *client) connect(bucketName string, connectionBufferSize uint, connectionTimeout time.Duration) (*gocbcore.Agent, error) {
return CreateAgent(s.config.Hosts, bucketName, s.config.Username, s.config.Password, s.config.SecureConnection, s.config.RootCAPath, connectionBufferSize, connectionTimeout) //nolint:lll
func (s *client) connect(bucketName string, maxQueueSize int, connectionBufferSize uint, connectionTimeout time.Duration) (*gocbcore.Agent, error) { //nolint:lll,unused
return CreateAgent(s.config.Hosts, bucketName, s.config.Username, s.config.Password, s.config.SecureConnection, s.config.RootCAPath, maxQueueSize, connectionBufferSize, connectionTimeout) //nolint:lll
}

func resolveHostsAsHTTP(hosts []string) []string {
Expand Down Expand Up @@ -256,7 +257,7 @@ func (s *client) Connect() error {
}
}

agent, err := s.connect(s.config.BucketName, connectionBufferSize, connectionTimeout)
agent, err := s.connect(s.config.BucketName, s.config.MaxQueueSize, connectionBufferSize, connectionTimeout)
if err != nil {
logger.Log.Error("error while connect to source bucket, err: %v", err)
return err
Expand All @@ -271,6 +272,7 @@ func (s *client) Connect() error {
} else {
metaAgent, err := s.connect(
couchbaseMetadataConfig.Bucket,
0, // gocb will use default value (2048)
couchbaseMetadataConfig.ConnectionBufferSize,
couchbaseMetadataConfig.ConnectionTimeout,
)
Expand Down Expand Up @@ -323,6 +325,7 @@ func (s *client) DcpConnect(useExpiryOpcode bool, useChangeStreams bool) error {
},
KVConfig: gocbcore.KVConfig{
ConnectionBufferSize: uint(helpers.ResolveUnionIntOrStringValue(s.config.Dcp.ConnectionBufferSize)),
MaxQueueSize: s.config.Dcp.MaxQueueSize,
},
}

Expand Down
Loading