MCPcopy
hub / github.com/panjf2000/ants / TestAntsPoolWithFuncGenericGetWorkerFromCachePreMalloc

Function TestAntsPoolWithFuncGenericGetWorkerFromCachePreMalloc

ants_test.go:248–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

246}
247
248func TestAntsPoolWithFuncGenericGetWorkerFromCachePreMalloc(t *testing.T) {
249 dur := 10
250 p, _ := ants.NewPoolWithFuncGeneric(TestSize, demoPoolFuncInt, ants.WithPreAlloc(true))
251 defer p.Release()
252
253 for i := 0; i < AntsSize; i++ {
254 _ = p.Invoke(dur)
255 }
256 time.Sleep(2 * ants.DefaultCleanIntervalTime)
257 _ = p.Invoke(dur)
258 t.Logf("pool with func, running workers number:%d", p.Running())
259 mem := runtime.MemStats{}
260 runtime.ReadMemStats(&mem)
261 curMem = mem.TotalAlloc/MiB - curMem
262 t.Logf("memory usage:%d MB", curMem)
263}
264
265// Contrast between goroutines without a pool and goroutines with ants pool.
266

Callers

nothing calls this directly

Calls 3

ReleaseMethod · 0.80
InvokeMethod · 0.45
RunningMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…