aboutsummaryrefslogtreecommitdiff
path: root/workerpool.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-03-30 18:11:40 +0300
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-03-30 18:11:40 +0300
commit92c779039c6ee8afaa943e746c801b434111b159 (patch)
tree7b894eb509aaf60c299d3b55488cadb796b9d2df /workerpool.go
parentworkerpool: reduced the time to hold the lock when cleaning unused worker gor... (diff)
downloadfasthttp-92c779039c6ee8afaa943e746c801b434111b159.tar.gz
fasthttp-92c779039c6ee8afaa943e746c801b434111b159.tar.bz2
fasthttp-92c779039c6ee8afaa943e746c801b434111b159.zip
workerpool: clean workerChan slices in order to reduce the amount of work for GC
Diffstat (limited to 'workerpool.go')
-rw-r--r--workerpool.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/workerpool.go b/workerpool.go
index 488f601..143af29 100644
--- a/workerpool.go
+++ b/workerpool.go
@@ -109,8 +109,10 @@ func (wp *workerPool) clean(scratch *[]*workerChan) {
// This notification must be outside the wp.lock, since ch.ch
// may be blocking and may consume a lot of time if many workers
// are located on non-local CPUs.
- for _, ch := range *scratch {
+ tmp := *scratch
+ for i, ch := range tmp {
ch.ch <- nil
+ tmp[i] = nil
}
}
@@ -151,6 +153,7 @@ func (wp *workerPool) getCh() *workerChan {
}
} else {
ch = ready[n]
+ ready[n] = nil
wp.ready = ready[:n]
}
wp.lock.Unlock()