Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ type ClusterConfig struct {
// Default: 128 for older CQL versions
MaxRequestsPerConn int

// Threshold for the number of inflight requests per connection
// after which the connection is considered as heavy loaded
// Default: 512
HeavyLoadedConnectionThreshold int

// When a connection is considered as heavy loaded, the driver
// could switch to the least loaded connection for the same node.
// The switch will happen if the other connection is at least
// HeavyLoadedSwitchConnectionPercentage percentage less busy
// (in terms of inflight requests).
//
// For the default value of 20%, if the heavy loaded connection
// has 100 inflight requests, the switch will happen only if the
// least busy connection has less than 80 inflight requests.
//
// Default: 20%
HeavyLoadedSwitchConnectionPercentage int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please validate that this parameter is within valid range when the session is being created.


// Default consistency level.
// Default: Quorum
Consistency Consistency
Expand Down Expand Up @@ -267,6 +285,8 @@ func NewCluster(hosts ...string) *ClusterConfig {
ConnectTimeout: 600 * time.Millisecond,
Port: 9042,
NumConns: 2,
HeavyLoadedConnectionThreshold: 512,
HeavyLoadedSwitchConnectionPercentage: 20,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run gofmt on this file. It will be annoying for others contributors if gofmt keeps formatting code that they didn't modify.

Consistency: Quorum,
MaxPreparedStmts: defaultMaxPreparedStmts,
MaxRoutingKeyInfo: 1000,
Expand Down
4 changes: 2 additions & 2 deletions scylla.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,15 @@ func (p *scyllaConnPicker) maybeReplaceWithLessBusyConnection(c *Conn) *Conn {
return c
}
alternative := p.leastBusyConn()
if alternative != nil && alternative.InUseStreams() * 100 < c.InUseStreams() * 80 {
if alternative != nil && alternative.InUseStreams() * 100 < c.InUseStreams() * (100 - c.session.cfg.HeavyLoadedSwitchConnectionPercentage) {
return alternative
} else {
return c
}
}

func isHeavyLoaded(c *Conn) bool {
return c.streams.NumStreams / 2 > c.AvailableStreams();
return c.InUseStreams() > c.session.cfg.HeavyLoadedConnectionThreshold
}

func (p *scyllaConnPicker) leastBusyConn() *Conn {
Expand Down