Merge branch 'develop'

This commit is contained in:
Andy Pan 2018-05-27 22:49:33 +08:00
commit 3dff642352
8 changed files with 42 additions and 14 deletions

View File

@ -137,6 +137,32 @@ All the tasks submitted to ants pool will not be guaranteed to be processed in o
The test data above is a basic benchmark and the more detailed benchmarks will be uploaded later. The test data above is a basic benchmark and the more detailed benchmarks will be uploaded later.
### Benchmarks with Pool
![](https://github.com/panjf2000/ants/blob/master/benchmark_pool.png)
### Benchmarks with PoolWithFunc
![](https://github.com/panjf2000/ants/blob/master/ants_bench_poolwithfunc.png)
### Throughput
#### 10w tasks
![](https://github.com/panjf2000/ants/blob/master/ants_bench_10w.png)
#### 100w tasks
![](https://github.com/panjf2000/ants/blob/master/ants_bench_100w.png)
#### 1000W tasks
![](https://github.com/panjf2000/ants/blob/master/ants_bench_1000w.png)
There was only the test of `ants` Pool because my computer was crash when it reached 1000w goroutines. ba
[1]: https://godoc.org/github.com/panjf2000/ants?status.svg [1]: https://godoc.org/github.com/panjf2000/ants?status.svg
[2]: https://godoc.org/github.com/panjf2000/ants [2]: https://godoc.org/github.com/panjf2000/ants
[3]: https://goreportcard.com/badge/github.com/panjf2000/ants [3]: https://goreportcard.com/badge/github.com/panjf2000/ants

BIN
ants_bench_1000w.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
ants_bench_100w.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

BIN
ants_bench_10w.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 KiB

BIN
ants_bench_poolwithfunc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

View File

@ -32,20 +32,21 @@ import (
const ( const (
_ = 1 << (10 * iota) _ = 1 << (10 * iota)
KiB // 1024 KiB // 1024
MiB // 1048576 MiB // 1048576
GiB // 1073741824 GiB // 1073741824
TiB // 1099511627776 (超过了int32的范围) TiB // 1099511627776 (超过了int32的范围)
PiB // 1125899906842624 PiB // 1125899906842624
EiB // 1152921504606846976 EiB // 1152921504606846976
ZiB // 1180591620717411303424 (超过了int64的范围) ZiB // 1180591620717411303424 (超过了int64的范围)
YiB // 1208925819614629174706176 YiB // 1208925819614629174706176
) )
const RunTimes = 10000000 const RunTimes = 10000000
const loop = 10 const loop = 10
func demoFunc() error { func demoFunc() error {
time.Sleep(loop * time.Millisecond) n := 10
time.Sleep(time.Duration(n) * time.Millisecond)
return nil return nil
} }
@ -95,17 +96,18 @@ func BenchmarkAntsPoolWithFunc(b *testing.B) {
func BenchmarkGoroutine(b *testing.B) { func BenchmarkGoroutine(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
for j := 0; j < RunTimes; j++ { for j := 0; j < RunTimes; j++ {
go demoFunc() go demoPoolFunc(loop)
} }
} }
} }
func BenchmarkAntsPool(b *testing.B) { func BenchmarkAntsPool(b *testing.B) {
p, _ := ants.NewPoolWithFunc(50000, demoPoolFunc)
b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
for j := 0; j < RunTimes; j++ { for j := 0; j < RunTimes; j++ {
ants.Submit(demoFunc) p.Serve(loop)
} }
b.Logf("running goroutines: %d", ants.Running()) // b.Logf("running goroutines: %d", p.Running())
} }
} }

View File

@ -30,7 +30,7 @@ import (
"github.com/panjf2000/ants" "github.com/panjf2000/ants"
) )
var n = 10000000 var n = 1000000
func TestDefaultPool(t *testing.T) { func TestDefaultPool(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup

BIN
benchmark_pool.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB