You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package main
import (
"github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/naza/pkg/taskpool"
"sync"
"time"
)
var (
taskNum = 1000 * 10000
initWorkerNum = 1 //1000 * 20 //1000 * 10
)
func originGo ( ) {
nazalog . Debug ( "> BenchmarkOriginGo" )
var wg sync . WaitGroup
for j := 0 ; j < 1 ; j ++ {
wg . Add ( taskNum )
for i := 0 ; i < taskNum ; i ++ {
go func ( ) {
time . Sleep ( 10 * time . Millisecond )
wg . Done ( )
} ( )
}
wg . Wait ( )
}
nazalog . Debug ( "< BenchmarkOriginGo" )
}
func taskPool ( ) {
nazalog . Debug ( "> BenchmarkTaskPool" )
var wg sync . WaitGroup
var ps [ ] taskpool . Pool
var poolNum = 1
for i := 0 ; i < poolNum ; i ++ {
p , _ := taskpool . NewPool ( func ( option * taskpool . Option ) {
option . InitWorkerNum = initWorkerNum
} )
ps = append ( ps , p )
}
for j := 0 ; j < 1 ; j ++ {
//b.StartTimer()
wg . Add ( taskNum )
for i := 0 ; i < taskNum ; i ++ {
ps [ i % poolNum ] . Go ( func ( ) {
time . Sleep ( 10 * time . Millisecond )
wg . Done ( )
} )
}
wg . Wait ( )
//b.StopTimer()
//idle, busy := p.Status()
//nazalog.Debugf("done, worker num. idle=%d, busy=%d", idle, busy) // 此时还有个别busy也是正常的, 因为只是业务方的任务代码执行完了, 可能还没回收到idle队列中
//p.KillIdleWorkers()
//idle, busy = p.Status()
//nazalog.Debugf("killed, worker num. idle=%d, busy=%d", idle, busy)
}
nazalog . Debug ( "< BenchmarkTaskPool" )
}
func main ( ) {
taskPool ( )
//originGo()
}