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
<atitle="Mentioned in Awesome Go"target="_blank"href="https://github.com/avelino/awesome-go"><imgsrc="https://awesome.re/mentioned-badge-flat.svg"></a>
15
15
</p>
16
16
17
-
# [[中文](README_ZH.md)]
17
+
English | [🇨🇳中文](README_ZH.md)
18
+
19
+
## 📖 Introduction
18
20
19
21
Library `ants` implements a goroutine pool with fixed capacity, managing and recycling a massive number of goroutines, allowing developers to limit the number of goroutines in your concurrent programs.
20
22
21
-
## Features:
23
+
## 🚀 Features:
22
24
23
25
- Managing and recycling a massive number of goroutines automatically
24
26
- Purging overdue goroutines periodically
@@ -27,7 +29,7 @@ Library `ants` implements a goroutine pool with fixed capacity, managing and rec
27
29
- Efficient in memory usage and it even achieves higher performance than unlimited goroutines in Golang
28
30
- Nonblocking mechanism
29
31
30
-
## Tested in the following Golang versions:
32
+
## ⚔️ Tested in the following Golang versions:
31
33
32
34
- 1.8.x
33
35
- 1.9.x
@@ -36,13 +38,13 @@ Library `ants` implements a goroutine pool with fixed capacity, managing and rec
@@ -56,7 +58,7 @@ go get -u github.com/panjf2000/ants
56
58
go get -u github.com/panjf2000/ants/v2
57
59
```
58
60
59
-
## How to use
61
+
## 🛠 How to use
60
62
Just take a imagination 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:
`ants.Options`contains all optional configurations of ants pool, which allows you to customize the goroutine pool by invoking option functions to set up each configuration in `NewPool`/`NewPoolWithFunc`method.
251
253
252
-
## Customize limited pool
254
+
###Customize limited pool
253
255
254
256
`ants` also supports customizing the capacity of pool. You can invoke the `NewPool` method to instantiate a pool with a given capacity, as following:
Tasks can be submitted by calling `ants.Submit(func())`
263
265
```go
264
266
ants.Submit(func(){})
265
267
```
266
268
267
-
## Tune pool capacity in runtime
269
+
###Tune pool capacity in runtime
268
270
You can tune the capacity of `ants` pool in runtime with `Tune(int)`:
269
271
270
272
```go
@@ -274,7 +276,7 @@ pool.Tune(100000) // Tune its capacity to 100000
274
276
275
277
Don't worry about the synchronous problems in this case, the method here is thread-safe (or should be called goroutine-safe).
276
278
277
-
## Pre-malloc goroutine queue in pool
279
+
###Pre-malloc goroutine queue in pool
278
280
279
281
`ants` allows you to pre-allocate memory of goroutine queue in 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 costs when re-slicing goroutine queue.
280
282
@@ -283,16 +285,16 @@ Don't worry about the synchronous problems in this case, the method here is thre
All tasks submitted to `ants` pool will not be guaranteed to be addressed in order, because those tasks scatter among a series of concurrent workers, thus those tasks would be executed concurrently.
In this benchmark result, the first and second benchmarks performed test cases with 1M tasks and the rest of benchmarks performed test cases with 10M tasks, both in unlimited goroutines and `ants` pool, and the capacity of this `ants` goroutine-pool was limited to 50K.
@@ -327,20 +329,20 @@ In above benchmark result, the first and second benchmarks performed test cases
<atitle="Mentioned in Awesome Go"target="_blank"href="https://github.com/avelino/awesome-go"><imgsrc="https://awesome.re/mentioned-badge-flat.svg"></a>
0 commit comments