All Projects → bdxing → workerPool

bdxing / workerPool

Licence: other
Auto scaling goroutine pool.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to workerPool

goroutines
It is an efficient, flexible, and lightweight goroutine pool. It provides an easy way to deal with concurrent tasks with limited resource.
Stars: ✭ 88 (+388.89%)
Mutual labels:  goroutine-pool
errgroup
errgroup with goroutine worker limits
Stars: ✭ 143 (+694.44%)
Mutual labels:  goroutine-pool
Tunny
A goroutine pool for Go
Stars: ✭ 2,755 (+15205.56%)
Mutual labels:  goroutine-pool
Ants
🐜🐜🐜 ants is a high-performance and low-cost goroutine pool in Go, inspired by fasthttp./ ants 是一个高性能且低损耗的 goroutine 池。
Stars: ✭ 7,180 (+39788.89%)
Mutual labels:  goroutine-pool
gpool
gpool - a generic context-aware resizable goroutines pool to bound concurrency based on semaphore.
Stars: ✭ 84 (+366.67%)
Mutual labels:  goroutine-pool
conn
netpoll事件驱动,goroutine协程池化,降低无效协程的资源占用,适用于高连接数(对于低频数据传输的场景,可以大幅降低协程数,提升资源利用率)
Stars: ✭ 28 (+55.56%)
Mutual labels:  goroutine-pool
gohive
🐝 A Highly Performant and easy to use goroutine pool for Go
Stars: ✭ 41 (+127.78%)
Mutual labels:  goroutine-pool
goroutine-pool
A simple goroutine pool which can create and release goroutine dynamically, inspired by fasthttp.
Stars: ✭ 31 (+72.22%)
Mutual labels:  goroutine-pool

workerPool

This is a goroutine pool, which can avoid a large amount of performance consumption of creation and destruction under high concurrency, ensure the stable scheduling of modules, and automatically scale the size of the co-program pool to fit the current business scheduling.

Installation

To install this package, you need to setup your Go workspace. The simplest way to install the library is to run:

go get github.com/bdxing/workerPool

Example

package main

import (
	. "github.com/bdxing/workerPool"
	"log"
	"time"
)

type TestAdd struct {
	a int
	b int
}

func main() {
	workerFunc := func(tmp interface{}) {
		ta := tmp.(*TestAdd)
		ta.a += ta.b
	}

	wp := &WorkerPool{
		MaxWorkerCount:        DefaultConcurrency, // max worker goroutine number, Hot add
		MaxIdleWorkerDuration: 5 * time.Second,    // worker goroutine max Idle Worker Duration
		WorkerFunc:            workerFunc,         // worker method
	}
	wp.Start()

	nowTime := time.Now()

	for i := 0; i < 100000000; i++ {
		if !wp.Serve(&TestAdd{
			a: i,
			b: i + 1,
		}) {
			log.Printf("wp.Serve(): timeout\n")
		}
	}

	log.Printf("consuming time: %v\n", time.Now().Sub(nowTime))

	// shutdown worker pool
	//wp.Stop()

}

Benchmark

goos: windows
goarch: amd64
pkg: github.com/bdxing/workerPool
cpu: Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz
BenchmarkWorkerPool_Serve
    worker_pool_test.go:80: taskCount:          1, workerCount:          1
    worker_pool_test.go:80: taskCount:        100, workerCount:         16
    worker_pool_test.go:80: taskCount:      10000, workerCount:         45
    worker_pool_test.go:80: taskCount:    1000000, workerCount:        111
    worker_pool_test.go:80: taskCount:    2567829, workerCount:        206
BenchmarkWorkerPool_Serve-12    	 2567829	       467.9 ns/op	      16 B/op	       1 allocs/op
PASS
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].