From da5b1bba5c92ac1c651aa601b75ad8d8a0e8c355 Mon Sep 17 00:00:00 2001 From: andy pan Date: Fri, 27 Jul 2018 14:19:27 +0800 Subject: [PATCH 1/4] Auto stash before merge of "develop" and "master" --- README.md | 4 ++-- README_ZH.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b978649..198ed04 100644 --- a/README.md +++ b/README.md @@ -182,9 +182,9 @@ There was only the test of `ants` Pool because my computer was crash when it rea **As you can see, `ants` can up to 2x~6x faster than goroutines without pool and the memory consumption is reduced by 10 to 20 times.** -[1]: https://travis-ci.com/panjf2000/ants.svg?branch=master +[1]: https://travis-ci.com/panjf2000/ants.svg?branch=develop [2]: https://travis-ci.com/panjf2000/ants -[3]: https://codecov.io/gh/panjf2000/ants/branch/master/graph/badge.svg +[3]: https://codecov.io/gh/panjf2000/ants/branch/develop/graph/badge.svg [4]: https://codecov.io/gh/panjf2000/ants [5]: https://goreportcard.com/badge/github.com/panjf2000/ants [6]: https://goreportcard.com/report/github.com/panjf2000/ants diff --git a/README_ZH.md b/README_ZH.md index e06c36e..1ba7098 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -180,9 +180,9 @@ Go1.9 **从该demo测试吞吐性能对比可以看出,使用ants的吞吐性能相较于原生goroutine可以保持在2-6倍的性能压制,而内存消耗则可以达到10-20倍的节省优势。** -[1]: https://travis-ci.com/panjf2000/ants.svg?branch=master +[1]: https://travis-ci.com/panjf2000/ants.svg?branch=develop [2]: https://travis-ci.com/panjf2000/ants -[3]: https://codecov.io/gh/panjf2000/ants/branch/master/graph/badge.svg +[3]: https://codecov.io/gh/panjf2000/ants/branch/develop/graph/badge.svg [4]: https://codecov.io/gh/panjf2000/ants [5]: https://goreportcard.com/badge/github.com/panjf2000/ants [6]: https://goreportcard.com/report/github.com/panjf2000/ants From 042109890ad36bedd17974ae1dcb1a631377b554 Mon Sep 17 00:00:00 2001 From: andy pan Date: Tue, 31 Jul 2018 11:03:41 +0800 Subject: [PATCH 2/4] make some methods unexported --- pool.go | 10 +++++----- pool_func.go | 10 +++++----- worker.go | 2 +- worker_func.go | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pool.go b/pool.go index ac3edcd..ad78fe0 100644 --- a/pool.go +++ b/pool.go @@ -129,13 +129,13 @@ func (p *Pool) Running() int { return int(atomic.LoadInt32(&p.running)) } -// IncrRunning increases the number of the currently running goroutines -func (p *Pool) IncrRunning() { +// incrRunning increases the number of the currently running goroutines +func (p *Pool) incrRunning() { atomic.AddInt32(&p.running, 1) } -// DecrRunning decreases the number of the currently running goroutines -func (p *Pool) DecrRunning() { +// decrRunning decreases the number of the currently running goroutines +func (p *Pool) decrRunning() { atomic.AddInt32(&p.running, -1) } @@ -215,7 +215,7 @@ func (p *Pool) getWorker() *Worker { task: make(chan f, 1), } w.run() - p.IncrRunning() + p.incrRunning() } return w } diff --git a/pool_func.go b/pool_func.go index 77221e4..c672bd2 100644 --- a/pool_func.go +++ b/pool_func.go @@ -134,13 +134,13 @@ func (p *PoolWithFunc) Running() int { return int(atomic.LoadInt32(&p.running)) } -// IncrRunning increases the number of the currently running goroutines -func (p *PoolWithFunc) IncrRunning() { +// incrRunning increases the number of the currently running goroutines +func (p *PoolWithFunc) incrRunning() { atomic.AddInt32(&p.running, 1) } -// DecrRunning decreases the number of the currently running goroutines -func (p *PoolWithFunc) DecrRunning() { +// decrRunning decreases the number of the currently running goroutines +func (p *PoolWithFunc) decrRunning() { atomic.AddInt32(&p.running, -1) } @@ -220,7 +220,7 @@ func (p *PoolWithFunc) getWorker() *WorkerWithFunc { args: make(chan interface{}, 1), } w.run() - p.IncrRunning() + p.incrRunning() } return w } diff --git a/worker.go b/worker.go index 8d29a3a..aa4e761 100644 --- a/worker.go +++ b/worker.go @@ -46,7 +46,7 @@ func (w *Worker) run() { go func() { for f := range w.task { if f == nil { - w.pool.DecrRunning() + w.pool.decrRunning() return } f() diff --git a/worker_func.go b/worker_func.go index 22b6069..277ee31 100644 --- a/worker_func.go +++ b/worker_func.go @@ -46,7 +46,7 @@ func (w *WorkerWithFunc) run() { go func() { for args := range w.args { if args == nil { - w.pool.DecrRunning() + w.pool.decrRunning() return } w.pool.poolFunc(args) From 59ad1fa56cee30b66881884cd74fadb8b682b6bf Mon Sep 17 00:00:00 2001 From: andy pan Date: Tue, 31 Jul 2018 11:05:05 +0800 Subject: [PATCH 3/4] optimization for structure --- pool.go | 21 +++++++++++---------- pool_func.go | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/pool.go b/pool.go index ad78fe0..03f88c0 100644 --- a/pool.go +++ b/pool.go @@ -129,16 +129,6 @@ func (p *Pool) Running() int { return int(atomic.LoadInt32(&p.running)) } -// incrRunning increases the number of the currently running goroutines -func (p *Pool) incrRunning() { - atomic.AddInt32(&p.running, 1) -} - -// decrRunning decreases the number of the currently running goroutines -func (p *Pool) decrRunning() { - atomic.AddInt32(&p.running, -1) -} - // Free returns the available goroutines to work func (p *Pool) Free() int { return int(atomic.LoadInt32(&p.capacity) - atomic.LoadInt32(&p.running)) @@ -182,6 +172,17 @@ func (p *Pool) Release() error { //------------------------------------------------------------------------- +// incrRunning increases the number of the currently running goroutines +func (p *Pool) incrRunning() { + atomic.AddInt32(&p.running, 1) +} + +// decrRunning decreases the number of the currently running goroutines +func (p *Pool) decrRunning() { + atomic.AddInt32(&p.running, -1) +} + + // getWorker returns a available worker to run the tasks. func (p *Pool) getWorker() *Worker { var w *Worker diff --git a/pool_func.go b/pool_func.go index c672bd2..4b59bc1 100644 --- a/pool_func.go +++ b/pool_func.go @@ -134,16 +134,6 @@ func (p *PoolWithFunc) Running() int { return int(atomic.LoadInt32(&p.running)) } -// incrRunning increases the number of the currently running goroutines -func (p *PoolWithFunc) incrRunning() { - atomic.AddInt32(&p.running, 1) -} - -// decrRunning decreases the number of the currently running goroutines -func (p *PoolWithFunc) decrRunning() { - atomic.AddInt32(&p.running, -1) -} - // Free returns the available goroutines to work func (p *PoolWithFunc) Free() int { return int(atomic.LoadInt32(&p.capacity) - atomic.LoadInt32(&p.running)) @@ -187,6 +177,17 @@ func (p *PoolWithFunc) Release() error { //------------------------------------------------------------------------- +// incrRunning increases the number of the currently running goroutines +func (p *PoolWithFunc) incrRunning() { + atomic.AddInt32(&p.running, 1) +} + +// decrRunning decreases the number of the currently running goroutines +func (p *PoolWithFunc) decrRunning() { + atomic.AddInt32(&p.running, -1) +} + + // getWorker returns a available worker to run the tasks. func (p *PoolWithFunc) getWorker() *WorkerWithFunc { var w *WorkerWithFunc From 39951bd2f5ea2c26a024b4177e867aac92055791 Mon Sep 17 00:00:00 2001 From: andy pan Date: Tue, 31 Jul 2018 11:05:48 +0800 Subject: [PATCH 4/4] format codes --- pool.go | 1 - pool_func.go | 1 - 2 files changed, 2 deletions(-) diff --git a/pool.go b/pool.go index 03f88c0..96873cd 100644 --- a/pool.go +++ b/pool.go @@ -182,7 +182,6 @@ func (p *Pool) decrRunning() { atomic.AddInt32(&p.running, -1) } - // getWorker returns a available worker to run the tasks. func (p *Pool) getWorker() *Worker { var w *Worker diff --git a/pool_func.go b/pool_func.go index 4b59bc1..ee8c9c5 100644 --- a/pool_func.go +++ b/pool_func.go @@ -187,7 +187,6 @@ func (p *PoolWithFunc) decrRunning() { atomic.AddInt32(&p.running, -1) } - // getWorker returns a available worker to run the tasks. func (p *PoolWithFunc) getWorker() *WorkerWithFunc { var w *WorkerWithFunc