diff options
author | Aliaksandr Valialkin <valyala@gmail.com> | 2016-05-16 17:17:18 +0300 |
---|---|---|
committer | Aliaksandr Valialkin <valyala@gmail.com> | 2016-05-16 17:17:18 +0300 |
commit | f36b47782ae279a52f9f2adc7857eac32147bf87 (patch) | |
tree | 2fbd84ed419bcd1b1938156bfa26e6ee28db76ec /timer.go | |
parent | Issue #95: Added 'Related projects' chapter into README (diff) | |
download | fasthttp-f36b47782ae279a52f9f2adc7857eac32147bf87.tar.gz fasthttp-f36b47782ae279a52f9f2adc7857eac32147bf87.tar.bz2 fasthttp-f36b47782ae279a52f9f2adc7857eac32147bf87.zip |
removed memory allocations from tryDial. This should improve performance for non-keepalive connections
Diffstat (limited to 'timer.go')
-rw-r--r-- | timer.go | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -1,6 +1,7 @@ package fasthttp import ( + "sync" "time" ) @@ -24,3 +25,20 @@ func stopTimer(t *time.Timer) { } } } + +func acquireTimer(timeout time.Duration) *time.Timer { + v := timerPool.Get() + if v == nil { + return time.NewTimer(timeout) + } + t := v.(*time.Timer) + initTimer(t, timeout) + return t +} + +func releaseTimer(t *time.Timer) { + stopTimer(t) + timerPool.Put(t) +} + +var timerPool sync.Pool |