aboutsummaryrefslogtreecommitdiff
path: root/timer.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-05-16 17:17:18 +0300
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-05-16 17:17:18 +0300
commitf36b47782ae279a52f9f2adc7857eac32147bf87 (patch)
tree2fbd84ed419bcd1b1938156bfa26e6ee28db76ec /timer.go
parentIssue #95: Added 'Related projects' chapter into README (diff)
downloadfasthttp-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.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/timer.go b/timer.go
index 4693ecf..bb12acb 100644
--- a/timer.go
+++ b/timer.go
@@ -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