Skip to content
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
15 changes: 8 additions & 7 deletions internal/pool/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ var (
errConnNotAvailableForWrite = errors.New("redis: connection not available for write operation")
)

// getCachedTimeNs returns the current time in nanoseconds from the global cache.
// This is updated every 50ms by a background goroutine, avoiding expensive syscalls.
// Max staleness: 50ms.
// getCachedTimeNs returns the current time in nanoseconds.
// This function previously used a global cache updated by a background goroutine,
// but that caused unnecessary CPU usage when the client was idle (ticker waking up
// the scheduler every 50ms). We now use time.Now() directly, which is fast enough
// on modern systems (vDSO on Linux) and only adds ~1-2% overhead in extreme
// high-concurrency benchmarks while eliminating idle CPU usage.
func getCachedTimeNs() int64 {
return globalTimeCache.nowNs.Load()
return time.Now().UnixNano()
}

// GetCachedTimeNs returns the current time in nanoseconds from the global cache.
// This is updated every 50ms by a background goroutine, avoiding expensive syscalls.
// Max staleness: 50ms.
// GetCachedTimeNs returns the current time in nanoseconds.
// Exported for use by other packages that need fast time access.
func GetCachedTimeNs() int64 {
return getCachedTimeNs()
Expand Down
74 changes: 0 additions & 74 deletions internal/pool/global_time_cache.go

This file was deleted.

6 changes: 0 additions & 6 deletions internal/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ func NewConnPool(opt *Options) *ConnPool {
p.connsMu.Unlock()
}

startGlobalTimeCache()
subscribeToGlobalTimeCache()

return p
}

Expand Down Expand Up @@ -981,9 +978,6 @@ func (p *ConnPool) Close() error {
return ErrClosed
}

unsubscribeFromGlobalTimeCache()
stopGlobalTimeCache()

var firstErr error
p.connsMu.Lock()
for _, cn := range p.conns {
Expand Down
Loading