File tree Expand file tree Collapse file tree 3 files changed +8
-87
lines changed Expand file tree Collapse file tree 3 files changed +8
-87
lines changed Original file line number Diff line number Diff line change @@ -27,16 +27,17 @@ var (
2727 errConnNotAvailableForWrite = errors .New ("redis: connection not available for write operation" )
2828)
2929
30- // getCachedTimeNs returns the current time in nanoseconds from the global cache.
31- // This is updated every 50ms by a background goroutine, avoiding expensive syscalls.
32- // Max staleness: 50ms.
30+ // getCachedTimeNs returns the current time in nanoseconds.
31+ // This function previously used a global cache updated by a background goroutine,
32+ // but that caused unnecessary CPU usage when the client was idle (ticker waking up
33+ // the scheduler every 50ms). We now use time.Now() directly, which is fast enough
34+ // on modern systems (vDSO on Linux) and only adds ~1-2% overhead in extreme
35+ // high-concurrency benchmarks while eliminating idle CPU usage.
3336func getCachedTimeNs () int64 {
34- return globalTimeCache . nowNs . Load ()
37+ return time . Now (). UnixNano ()
3538}
3639
37- // GetCachedTimeNs returns the current time in nanoseconds from the global cache.
38- // This is updated every 50ms by a background goroutine, avoiding expensive syscalls.
39- // Max staleness: 50ms.
40+ // GetCachedTimeNs returns the current time in nanoseconds.
4041// Exported for use by other packages that need fast time access.
4142func GetCachedTimeNs () int64 {
4243 return getCachedTimeNs ()
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -178,9 +178,6 @@ func NewConnPool(opt *Options) *ConnPool {
178178 p .connsMu .Unlock ()
179179 }
180180
181- startGlobalTimeCache ()
182- subscribeToGlobalTimeCache ()
183-
184181 return p
185182}
186183
@@ -981,9 +978,6 @@ func (p *ConnPool) Close() error {
981978 return ErrClosed
982979 }
983980
984- unsubscribeFromGlobalTimeCache ()
985- stopGlobalTimeCache ()
986-
987981 var firstErr error
988982 p .connsMu .Lock ()
989983 for _ , cn := range p .conns {
You can’t perform that action at this time.
0 commit comments