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

perf: better field alignment #733

Merged
merged 1 commit into from
Feb 2, 2025
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
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

type singleClient struct {
conn conn
cmd Builder
retryHandler retryHandler
stop uint32
cmd Builder
retry bool
DisableCache bool
}
Expand Down Expand Up @@ -197,9 +197,9 @@ func (c *singleClient) Close() {
type dedicatedSingleClient struct {
conn conn
wire wire
cmd Builder
retryHandler retryHandler
mark uint32
cmd Builder
retry bool
}

Expand Down
16 changes: 8 additions & 8 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ var ErrSendToReplicasNotSet = errors.New("SendToReplicas must be set when Replic

type clusterClient struct {
pslots [16384]conn
rslots []conn
sc call
retryHandler retryHandler
opt *ClientOption
rOpt *ClientOption
conns map[string]connrole
connFn connFn
opt *ClientOption
retryHandler retryHandler
stopCh chan struct{}
cmd Builder
sc call
rslots []conn
mu sync.RWMutex
stop uint32
cmd Builder
retry bool
}

Expand Down Expand Up @@ -1236,15 +1236,15 @@ func (c *clusterClient) shouldRefreshRetry(err error, ctx context.Context) (addr
}

type dedicatedClusterClient struct {
client *clusterClient
conn conn
wire wire
retryHandler retryHandler
client *clusterClient
pshks *pshks
mu sync.Mutex
cmd Builder
retryHandler retryHandler
retry bool
slot uint16
retry bool
mark bool
}

Expand Down
2 changes: 1 addition & 1 deletion pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func newSubs() *subs {
}

type subs struct {
cnt uint64
chs map[string]chs
sub map[uint64]*sub
cnt uint64
mu sync.RWMutex
}

Expand Down
66 changes: 34 additions & 32 deletions rueidis.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ var (

// ClientOption should be passed to NewClient to construct a Client
type ClientOption struct {
// TCP & TLS
// Dialer can be used to customized how rueidis connect to a redis instance via TCP, including:
// - Timeout, the default is DefaultDialTimeout
// - KeepAlive, the default is DefaultTCPKeepAlive
// The Dialer.KeepAlive interval is used to detect an unresponsive idle tcp connection.
// OS takes at least (tcp_keepalive_probes+1)*Dialer.KeepAlive time to conclude an idle connection to be unresponsive.
// For example: DefaultTCPKeepAlive = 1s and the default of tcp_keepalive_probes on Linux is 9.
// Therefore, it takes at least 10s to kill an idle and unresponsive tcp connection on Linux by default.
Dialer net.Dialer
TLSConfig *tls.Config

// DialFn allows for a custom function to be used to create net.Conn connections
Expand All @@ -89,18 +80,45 @@ type ClientOption struct {
// NOTE: This function can't be used with ReplicaOnly option.
SendToReplicas func(cmd Completed) bool

// AuthCredentialsFn allows for setting the AUTH username and password dynamically on each connection attempt to
// support rotating credentials
AuthCredentialsFn func(AuthCredentialsContext) (AuthCredentials, error)

// RetryDelay is the function that returns the delay that should be used before retrying the attempt.
// The default is an exponential backoff with a maximum delay of 1 second.
// Only used when DisableRetry is false.
RetryDelay RetryDelayFn

// ReplicaSelector selects a replica node when `SendToReplicas` returns true.
// If the function is set, the client will send selected command to the replica node.
// Returned value is the index of the replica node in the replicas slice.
// If the returned value is out of range, the primary node will be selected.
// If primary node does not have any replica, the primary node will be selected
// and function will not be called.
// Currently only used for cluster client.
// Each ReplicaInfo must not be modified.
// NOTE: This function can't be used with ReplicaOnly option.
// NOTE: This function must be used with SendToReplicas function.
ReplicaSelector func(slot uint16, replicas []ReplicaInfo) int

// Sentinel options, including MasterSet and Auth options
Sentinel SentinelOption

// TCP & TLS
// Dialer can be used to customized how rueidis connect to a redis instance via TCP, including:
// - Timeout, the default is DefaultDialTimeout
// - KeepAlive, the default is DefaultTCPKeepAlive
// The Dialer.KeepAlive interval is used to detect an unresponsive idle tcp connection.
// OS takes at least (tcp_keepalive_probes+1)*Dialer.KeepAlive time to conclude an idle connection to be unresponsive.
// For example: DefaultTCPKeepAlive = 1s and the default of tcp_keepalive_probes on Linux is 9.
// Therefore, it takes at least 10s to kill an idle and unresponsive tcp connection on Linux by default.
Dialer net.Dialer

// Redis AUTH parameters
Username string
Password string
ClientName string

// AuthCredentialsFn allows for setting the AUTH username and password dynamically on each connection attempt to
// support rotating credentials
AuthCredentialsFn func(AuthCredentialsContext) (AuthCredentials, error)

// ClientSetInfo will assign various info attributes to the current connection.
// Note that ClientSetInfo should have exactly 2 values, the lib name and the lib version respectively.
ClientSetInfo []string
Expand Down Expand Up @@ -170,6 +188,9 @@ type ClientOption struct {
// produce notable CPU usage reduction under load. Ref: https://github.com/redis/rueidis/issues/156
MaxFlushDelay time.Duration

// ClusterOption is the options for the redis cluster client.
ClusterOption ClusterOption

// DisableTCPNoDelay turns on Nagle's algorithm in pipelining mode by using conn.SetNoDelay(false).
// Turning this on can result in lower p99 latencies and lower CPU usages if all your requests are small.
// But if you have large requests or fast network, this might degrade the performance. Ref: https://github.com/redis/rueidis/pull/650
Expand All @@ -181,10 +202,6 @@ type ClientOption struct {
ClientNoTouch bool
// DisableRetry disables retrying read-only commands under network errors
DisableRetry bool
// RetryDelay is the function that returns the delay that should be used before retrying the attempt.
// The default is an exponential backoff with a maximum delay of 1 second.
// Only used when DisableRetry is false.
RetryDelay RetryDelayFn
// DisableCache falls back Client.DoCache/Client.DoMultiCache to Client.Do/Client.DoMulti
DisableCache bool
// DisableAutoPipelining makes rueidis.Client always pick a connection from the BlockingPool to serve each request.
Expand All @@ -206,21 +223,6 @@ type ClientOption struct {
// even if we're above the configured client eviction threshold.
ClientNoEvict bool

// ClusterOption is the options for the redis cluster client.
ClusterOption ClusterOption

// ReplicaSelector selects a replica node when `SendToReplicas` returns true.
// If the function is set, the client will send selected command to the replica node.
// Returned value is the index of the replica node in the replicas slice.
// If the returned value is out of range, the primary node will be selected.
// If primary node does not have any replica, the primary node will be selected
// and function will not be called.
// Currently only used for cluster client.
// Each ReplicaInfo must not be modified.
// NOTE: This function can't be used with ReplicaOnly option.
// NOTE: This function must be used with SendToReplicas function.
ReplicaSelector func(slot uint16, replicas []ReplicaInfo) int

// EnableReplicaAZInfo enables the client to load the replica node's availability zone.
// If true, the client will set the `AZ` field in `ReplicaInfo`.
EnableReplicaAZInfo bool
Expand Down
Loading
Loading