You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-189
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Library `ants` implements a goroutine pool with fixed capacity, managing and rec
25
25
- Purging overdue goroutines periodically
26
26
- Abundant APIs: submitting tasks, getting the number of running goroutines, tuning the capacity of the pool dynamically, releasing the pool, rebooting the pool, etc.
27
27
- Handle panic gracefully to prevent programs from crash
28
-
- Efficient in memory usage and it may even achieve ***higher performance*** than unlimited goroutines in Golang
28
+
- Efficient in memory usage and it may even achieve ***higher performance*** than unlimited goroutines in Go
29
29
- Nonblocking mechanism
30
30
- Preallocated memory (ring buffer, optional)
31
31
@@ -62,205 +62,30 @@ go get -u github.com/panjf2000/ants/v2
62
62
```
63
63
64
64
## 🛠 How to use
65
-
Just imagine that your program starts a massive number of goroutines, resulting in a huge consumption of memory. To mitigate that kind of situation, all you need to do is to import `ants` package and submit all your tasks to a default pool with fixed capacity, activated when package `ants` is imported:
65
+
Check out [the examples](https://pkg.go.dev/github.com/panjf2000/ants/v2#pkg-examples) for basic usage.
`ants.Options`contains all optional configurations of the ants pool, which allows you to customize the goroutine pool by invoking option functions to set up each configuration in `NewPool`/`NewPoolWithFunc`/`NewPoolWithFuncGeneric` method.
245
70
246
-
`ants.Options`contains all optional configurations of the ants pool, which allows you to customize the goroutine pool by invoking option functions to set up each configuration in `NewPool`/`NewPoolWithFunc`method.
71
+
Check out [ants.Options](https://pkg.go.dev/github.com/panjf2000/ants/v2#Options) and [ants.Option](https://pkg.go.dev/github.com/panjf2000/ants/v2#Option) for more details.
247
72
248
-
### Customize limited pool
73
+
### Customize pool capacity
249
74
250
-
`ants`also supports customizing the capacity of the pool. You can invoke the `NewPool` method to instantiate a pool with a given capacity, as follows:
75
+
`ants` supports customizing the capacity of the pool. You can call the `NewPool` method to instantiate a `Pool` with a given capacity, as follows:
251
76
252
77
```go
253
78
p, _:= ants.NewPool(10000)
254
79
```
255
80
256
81
### Submit tasks
257
-
Tasks can be submitted by calling `ants.Submit(func())`
82
+
Tasks can be submitted by calling `ants.Submit`
258
83
```go
259
84
ants.Submit(func(){})
260
85
```
261
86
262
-
### Tune pool capacity in runtime
263
-
You can tune the capacity of `ants` pool in runtime with `Tune(int)`:
87
+
### Tune pool capacity at runtime
88
+
You can tune the capacity of `ants` pool at runtime with `ants.Tune`:
264
89
265
90
```go
266
91
pool.Tune(1000) // Tune its capacity to 1000
@@ -274,11 +99,11 @@ Don't worry about the contention problems in this case, the method here is threa
274
99
`ants` allows you to pre-allocate the memory of the goroutine queue in the pool, which may get a performance enhancement under some special certain circumstances such as the scenario that requires a pool with ultra-large capacity, meanwhile, each task in goroutine lasts for a long time, in this case, pre-mallocing will reduce a lot of memory allocation in goroutine queue.
275
100
276
101
```go
277
-
// ants will pre-malloc the whole capacity of pool when you invoke this method
102
+
// ants will pre-malloc the whole capacity of pool when calling ants.NewPool.
0 commit comments