-
Notifications
You must be signed in to change notification settings - Fork 1
/
doc.go
53 lines (53 loc) · 1.43 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Package ewp is the implementation of elastic/dynamic worker pool (EWP) with graceful shutdown.
//
// After started up, EWP controller automatically monitors the workload level of
// the pool and based on that to determine the pool size need to be
// expanded (spawn more workers) or shrunk (kill free workers).
//
// Create EWP with default configs:
// myPool, _ := ewp.NewDefault()
// myPool.Start()
//
// Or create EWP with full customized configs:
// ewpConfig := ewp.Config{
// MinWorker: 5,
// MaxWorker: 20,
// PoolControlInterval: 10 * time.Second,
// BufferLength: 1000,
// }
// controller = ewp.NewAgileController(nil)
// myPool, _ := ewp.New(ewpConfig, controller, logrus.New())
// myPool.Start()
//
// Or create a fixed traditional worker pool:
// ewpConfig := ewp.Config{
// MinWorker: 5,
// MaxWorker: 5,
// }
// myPool, _ := ewp.New(ewpConfig, nil, nil)
// myPool.Start()
//
//
// Send jobs to EWP to be processed later:
// for i := 0; i < 10; i++ {
// i := i
// jobFunc := func() {
// // Your job logic go here
// log.Printf("job #%d", i)
// }
// _ = myPool.Enqueue(jobFunc)
// }
//
// Send jobs with timeout:
// for i := 0; i < 10; i++ {
// i := i
// jobFunc := func() {
// // Your job logic go here
// log.Printf("job #%d", i)
// }
// _ = myPool.Enqueue(jobFunc, 2*time.Second)
// }
//
// Gracefully shutdown the EWP:
// _ = myPool.Close()
package ewp