mirror of https://github.com/panjf2000/ants.git
Merge branch 'develop'
This commit is contained in:
commit
7c881fbcab
40
ants_test.go
40
ants_test.go
|
@ -130,42 +130,4 @@ func TestCodeCov(t *testing.T) {
|
|||
p.ReSize(TestSize)
|
||||
p.ReSize(AntsSize)
|
||||
t.Logf("pool with func, after resize, capacity:%d, running:%d", p.Cap(), p.Running())
|
||||
}
|
||||
|
||||
// func TestNoPool(t *testing.T) {
|
||||
// var wg sync.WaitGroup
|
||||
// for i := 0; i < n; i++ {
|
||||
// wg.Add(1)
|
||||
// go func() {
|
||||
// demoPoolFunc(n)
|
||||
// wg.Done()
|
||||
// }()
|
||||
// }
|
||||
|
||||
// wg.Wait()
|
||||
// mem := runtime.MemStats{}
|
||||
// runtime.ReadMemStats(&mem)
|
||||
// t.Logf("memory usage:%d", mem.TotalAlloc/GiB)
|
||||
// }
|
||||
|
||||
//func TestCustomPool(t *testing.T) {
|
||||
// p, _ := ants.NewPool(30000)
|
||||
// var wg sync.WaitGroup
|
||||
// for i := 0; i < n; i++ {
|
||||
// wg.Add(1)
|
||||
// p.Submit(func() {
|
||||
// demoFunc()
|
||||
// //demoFunc()
|
||||
// wg.Done()
|
||||
// })
|
||||
// }
|
||||
// wg.Wait()
|
||||
//
|
||||
// //t.Logf("pool capacity:%d", p.Cap())
|
||||
// //t.Logf("free workers number:%d", p.Free())
|
||||
//
|
||||
// t.Logf("running workers number:%d", p.Running())
|
||||
// mem := runtime.MemStats{}
|
||||
// runtime.ReadMemStats(&mem)
|
||||
// t.Logf("memory usage:%d", mem.TotalAlloc/1024)
|
||||
//}
|
||||
}
|
13
pool.go
13
pool.go
|
@ -67,7 +67,7 @@ func (p *Pool) periodicallyPurge() {
|
|||
p.lock.Unlock()
|
||||
return
|
||||
}
|
||||
n := 0
|
||||
n := -1
|
||||
for i, w := range idleWorkers {
|
||||
if currentTime.Sub(w.recycleTime) <= p.expiryDuration {
|
||||
break
|
||||
|
@ -76,11 +76,12 @@ func (p *Pool) periodicallyPurge() {
|
|||
w.task <- nil
|
||||
idleWorkers[i] = nil
|
||||
}
|
||||
n++
|
||||
if n >= len(idleWorkers) {
|
||||
p.workers = idleWorkers[:0]
|
||||
} else {
|
||||
p.workers = idleWorkers[n:]
|
||||
if n > -1 {
|
||||
if n >= len(idleWorkers)-1 {
|
||||
p.workers = idleWorkers[:0]
|
||||
} else {
|
||||
p.workers = idleWorkers[n+1:]
|
||||
}
|
||||
}
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
|
13
pool_func.go
13
pool_func.go
|
@ -68,7 +68,7 @@ func (p *PoolWithFunc) periodicallyPurge() {
|
|||
p.lock.Unlock()
|
||||
return
|
||||
}
|
||||
n := 0
|
||||
n := -1
|
||||
for i, w := range idleWorkers {
|
||||
if currentTime.Sub(w.recycleTime) <= p.expiryDuration {
|
||||
break
|
||||
|
@ -77,11 +77,12 @@ func (p *PoolWithFunc) periodicallyPurge() {
|
|||
w.args <- nil
|
||||
idleWorkers[i] = nil
|
||||
}
|
||||
n++
|
||||
if n >= len(idleWorkers) {
|
||||
p.workers = idleWorkers[:0]
|
||||
} else {
|
||||
p.workers = idleWorkers[n:]
|
||||
if n > -1 {
|
||||
if n >= len(idleWorkers)-1 {
|
||||
p.workers = idleWorkers[:0]
|
||||
} else {
|
||||
p.workers = idleWorkers[n+1:]
|
||||
}
|
||||
}
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue