Rebuild worker pool around channel-driven scheduling

This commit is contained in:
2026-10-21 01:14:55 +08:00
parent 24c7ab3a65
commit c0657699e4
4 changed files with 1102 additions and 1504 deletions

View File

@@ -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()
}