Rebuild worker pool around channel-driven scheduling
This commit is contained in:
@@ -1,19 +1,44 @@
|
||||
package worker
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func BenchmarkQueueRingSteady(b *testing.B) {
|
||||
p, err := New(0, 6)
|
||||
func BenchmarkSubmitNoop(b *testing.B) {
|
||||
benchmarkSubmit(b, func() {})
|
||||
}
|
||||
|
||||
func BenchmarkSubmit10usTask(b *testing.B) {
|
||||
benchmarkSubmit(b, func() {
|
||||
deadline := time.Now().Add(10 * time.Microsecond)
|
||||
for time.Now().Before(deadline) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func benchmarkSubmit(b *testing.B, task func()) {
|
||||
p, err := New(6, 6)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
task := func() {}
|
||||
var completed atomic.Int64
|
||||
wrapped := func() {
|
||||
task()
|
||||
completed.Add(1)
|
||||
}
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
p.mu.Lock()
|
||||
p.enqueueLocked(task)
|
||||
p.dequeueLocked()
|
||||
p.mu.Unlock()
|
||||
for range b.N {
|
||||
if err := p.Submit(wrapped); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
for completed.Load() != int64(b.N) {
|
||||
runtime.Gosched()
|
||||
}
|
||||
b.StopTimer()
|
||||
p.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user