update go test and readme

This commit is contained in:
Andy Pan 2018-05-27 22:41:55 +08:00
parent 2fef3ca1f7
commit 6fa37b8aa7
3 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.
### Benchmarks with Pool
![](http://blog.taohuawu.club/upload/2018/05/pilgrnjs18jntol1795hobq5v6.png)
### Benchmarks with PoolWithFunc
![](http://blog.taohuawu.club/upload/2018/05/46a679eagsj97qd7ntnigp2ejs.png)
### Throughput
#### 10w tasks
![](http://blog.taohuawu.club/upload/2018/05/0s3q9cdj5ajr7rvvodr763c2s8.png)
#### 100w tasks
![](http://blog.taohuawu.club/upload/2018/05/7rshjcd256hoao39j54isum235.png)
#### 1000W tasks
![](http://blog.taohuawu.club/upload/2018/05/tv70o6bkgoi90r26gnl1k68bi2.png)
There was only the test of `ants` Pool because my computer was crash when it reached 1000w goroutines.
[1]: https://godoc.org/github.com/panjf2000/ants?status.svg
[2]: https://godoc.org/github.com/panjf2000/ants
[3]: https://goreportcard.com/badge/github.com/panjf2000/ants

View File

@ -32,20 +32,21 @@ import (
const (
_ = 1 << (10 * iota)
KiB // 1024
MiB // 1048576
GiB // 1073741824
TiB // 1099511627776 (超过了int32的范围)
PiB // 1125899906842624
EiB // 1152921504606846976
ZiB // 1180591620717411303424 (超过了int64的范围)
YiB // 1208925819614629174706176
KiB // 1024
MiB // 1048576
GiB // 1073741824
TiB // 1099511627776 (超过了int32的范围)
PiB // 1125899906842624
EiB // 1152921504606846976
ZiB // 1180591620717411303424 (超过了int64的范围)
YiB // 1208925819614629174706176
)
const RunTimes = 10000000
const loop = 10
func demoFunc() error {
time.Sleep(loop * time.Millisecond)
n := 10
time.Sleep(time.Duration(n) * time.Millisecond)
return nil
}
@ -95,17 +96,18 @@ func BenchmarkAntsPoolWithFunc(b *testing.B) {
func BenchmarkGoroutine(b *testing.B) {
for i := 0; i < b.N; i++ {
for j := 0; j < RunTimes; j++ {
go demoFunc()
go demoPoolFunc(loop)
}
}
}
func BenchmarkAntsPool(b *testing.B) {
p, _ := ants.NewPoolWithFunc(50000, demoPoolFunc)
b.ResetTimer()
for i := 0; i < b.N; i++ {
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"
)
var n = 10000000
var n = 1000000
func TestDefaultPool(t *testing.T) {
var wg sync.WaitGroup