ants
ants copied to clipboard
Performance differences between go1.13 and 1.14 and later versions
In the same hardware environment, I found similar results to the author's conclusion for go1.13 in my tests, but for 1.14 onwards, ants no longer has a time consumption advantage, only a memory usage advantage. Is it because version 1.14 implements signal-based scheduling? Attached are the test results, 3 million times, default pool size
1.13 go test -run="TestNoPool" -v === RUN TestNoPool --- PASS: TestNoPool (2.64s) ants_test.go:47: memory usage:1530 MB PASS ok testGo/ant 2.759s
go test -run="TestAntsPool" -v === RUN TestAntsPool --- PASS: TestAntsPool (1.55s) ants_test.go:71: pool, capacity:2147483647 ants_test.go:72: pool, running workers number:29722 ants_test.go:73: pool, free workers number:2147453925 ants_test.go:78: memory usage:73 MB PASS ok testGo/ant 1.549s
1.14 go test -run="TestNoPool" -v === RUN TestNoPool TestNoPool: ants_test.go:47: memory usage:289 MB --- PASS: TestNoPool (0.78s) PASS ok testGo/ant 0.783s
go test -run="TestAntsPool" -v === RUN TestAntsPool TestAntsPool: ants_test.go:71: pool, capacity:2147483647 TestAntsPool: ants_test.go:72: pool, running workers number:27475 TestAntsPool: ants_test.go:73: pool, free workers number:2147456172 TestAntsPool: ants_test.go:78: memory usage:71 MB --- PASS: TestAntsPool (1.38s) PASS ok testGo/ant 1.385s
I did the same tests where the golang environment is 1.18. It is easy to see go func() directly faster than using ants pool.So I also think goroutine pool can only save memory usage currently, not improvement in time.
Agree with OP. One more thing, the memory usage advantage is not too much, that we could ignore because it runs 1m times in each b.N loop: https://github.com/panjf2000/ants/blob/master/ants_benchmark_test.go#L33
duplicate #123