aboutsummaryrefslogtreecommitdiff
path: root/workerpool.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-11-30 11:26:39 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-11-30 11:26:39 +0200
commitf214dc327f164ac64b9f818d5bd39c4dc217876c (patch)
tree01ee7f12447ac6070e80f6881be333103f8e3cd8 /workerpool.go
parentAdded an example for RequestCtx.TimeoutError (diff)
downloadfasthttp-f214dc327f164ac64b9f818d5bd39c4dc217876c.tar.gz
fasthttp-f214dc327f164ac64b9f818d5bd39c4dc217876c.tar.bz2
fasthttp-f214dc327f164ac64b9f818d5bd39c4dc217876c.zip
Scalability improvement: do not move read workers' queue when cleaning old workers. This should reduce latencies when server serves multi-million concurrent connections
Diffstat (limited to 'workerpool.go')
-rw-r--r--workerpool.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/workerpool.go b/workerpool.go
index cbab951..6119a62 100644
--- a/workerpool.go
+++ b/workerpool.go
@@ -81,12 +81,16 @@ func (wp *workerPool) clean() {
wp.lock.Lock()
chans := wp.ready
for len(chans) > 1 && time.Since(chans[0].t) > time.Second {
+ // notify the worker to stop.
chans[0].ch <- nil
- copy(chans, chans[1:])
- chans = chans[:len(chans)-1]
- wp.ready = chans
+
+ // do not do copy(chans, chans[1:]), since this may be quite slow
+ // for multi-million concurrent connections. Just move chans
+ // pointer one position ahead.
+ chans = chans[1:]
wp.workersCount--
}
+ wp.ready = chans
wp.lock.Unlock()
}