• Stars
    star
    87
  • Rank 378,796 (Top 8 %)
  • Language
    Go
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go simple async worker pool

๐Ÿ‘จโ€๐Ÿ”ง worker-pool

Build Status Go Report Card codecov FOSSA Status license

logo

Go simple async worker pool.

๐Ÿ“– ABOUT

Worker pool is a software design pattern for achieving concurrency of task execution. Maintains multiple workers waiting for tasks to be allocated for concurrent execution. By maintaining a pool of workers, the model increases performance and avoids latency in execution. The number of available workers might be tuned to the computing resources available.

You can read more about worker pools in Go here.

Contributors:

Want to contribute ? Feel free to send pull requests!

Have problems, bugs, feature ideas? We are using the github issue tracker to manage them.

๐Ÿ“š Documentation

For examples visit godoc#pkg-examples

For GoDoc reference, visit pkg.go.dev

๐Ÿš HOW TO USE

๐Ÿš… Benchmark

CPU: 3,3 GHz Intel Core i7

RAM: 16 GB 2133 MHz LPDDR3

โžœ  worker-pool git:(master) โœ— go test -bench=. -cpu=4 -benchmem
goos: darwin
goarch: amd64
pkg: github.com/vardius/worker-pool/v2
BenchmarkWorker1-4                	 3944299	       284 ns/op	      56 B/op	       3 allocs/op
BenchmarkWorker1Parallel-4        	 7394715	       138 ns/op	      48 B/op	       2 allocs/op
BenchmarkWorker100-4              	 1657569	       693 ns/op	      56 B/op	       3 allocs/op
BenchmarkWorker100Parallel-4      	 3673483	       368 ns/op	      48 B/op	       2 allocs/op
BenchmarkWorkerNumCPU-4           	 2590293	       445 ns/op	      56 B/op	       3 allocs/op
BenchmarkWorkerNumCPUParallel-4   	 3591553	       298 ns/op	      48 B/op	       2 allocs/op
PASS
ok  	github.com/vardius/worker-pool/v2	9.511s

๐Ÿซ Basic example

package main

import (
    "fmt"
    "sync"

    "github.com/vardius/worker-pool/v2"
)

func main() {
	var wg sync.WaitGroup

	poolSize := 1
	jobsAmount := 3
	workersAmount := 2

	// create new pool
	pool := workerpool.New(poolSize)
	out := make(chan int, jobsAmount)
	worker := func(i int) {
        defer wg.Done()
        out <- i
    }

	for i := 1; i <= workersAmount; i++ {
		if err := pool.AddWorker(worker); err != nil {
			panic(err)
		}
	}

	wg.Add(jobsAmount)

	for i := 0; i < jobsAmount; i++ {
		if err := pool.Delegate(i); err != nil {
			panic(err)
		}
	}

	go func() {
		// stop all workers after jobs are done
		wg.Wait()
		close(out)
		pool.Stop() // stop removes all workers from pool, to resume work add them again
	}()

	sum := 0
	for n := range out {
		sum += n
	}

	fmt.Println(sum)
	// Output:
	// 3
}

๐Ÿ“œ License

This package is released under the MIT license. See the complete license in the package

FOSSA Status

More Repositories

1

go-api-boilerplate

Go Server/API boilerplate using best practices DDD CQRS ES gRPC
Go
924
star
2

message-bus

Go simple async message bus
JavaScript
247
star
3

gorouter

Go Server/API micro framework, HTTP request router, multiplexer, mux
Go
154
star
4

gollback

Go asynchronous simple function utilities, for managing execution of closures and callbacks
Go
109
star
5

peer-data

Library for files, media streaming/sharing using WebRTC
JavaScript
64
star
6

peer-cdn

Lightweight library providing peer to peer CDN functionality
JavaScript
61
star
7

progress-go

Go simple progress bar writing to output
Go
53
star
8

web-components-webpack-es6-boilerplate

Web Components project starter using ES6 and Webpack
JavaScript
44
star
9

pubsub

gRPC message-oriented middleware on top of message-bus, event ingestion and delivery system.
Go
41
star
10

react-webrtc-chat

React WebRTC chat
JavaScript
41
star
11

web-component

Lightweight library providing interface for building web components
JavaScript
39
star
12

webrtc-chat

Serverless chat application useing peer to peer WebRTC
JavaScript
29
star
13

react-peer-data

React wrapper for PeerData library for files, media streaming/sharing using WebRTC.
TypeScript
20
star
14

react-user-media

React wrapper for getUserMedia
TypeScript
19
star
15

shutdown

Simple go signals handler for performing graceful shutdown by executing callback function
Go
18
star
16

gocontainer

Simple Dependency Injection Container
Go
18
star
17

pushpull

gRPC message-oriented middleware on top of worker-pool, event ingestion and delivery system.
Go
10
star
18

peer-data-server

Signaling server, messaging service on Node using socket
JavaScript
10
star
19

invoice-bundle

Symfony invoice bundle
JavaScript
8
star
20

blockchain

Simple gRPC blockchain
Go
8
star
21

crud-bundle

Provides crud actions, crud bundle for Symfony
PHP
7
star
22

trace

Simple helper to trace the function calls, errors or logs reference
Go
7
star
23

list-bundle

Provides list builder, list view bundle for Symfony
PHP
4
star
24

golog

Go logger
Go
4
star
25

goquery

Go query builder for sql
Go
3
star
26

gocrud

Simple Go (Golang) CRUD provider
Go
3
star
27

angular-symfony-acl

ACL component for Angular Js based on symfony2 user roles
JavaScript
2
star
28

angular-gravatar

Angular gravatar component
JavaScript
2
star
29

ng2-search

Angular 2 search module
JavaScript
1
star
30

angular2-chat

Socket.io Chat with NodeJS and Angular2
JavaScript
1
star
31

ng2-pagination

Angular2 pagination module
TypeScript
1
star
32

user-bundle

Simple symfony doctrine user bundle
PHP
1
star
33

mean-todos

MEAN (MongoDB, ExpressJS, Angular2, NodeJS) Todo List application
TypeScript
1
star
34

angular-oauth2

Angular oauth2 provider
JavaScript
1
star
35

angular2-github

GitHub User Search - Angular2 + Webpack App
JavaScript
1
star
36

vardius.github.io

SCSS
1
star
37

angular2-spotify

Spotify - Angular2 + Webpack App
JavaScript
1
star
38

menu-bundle

Simple symfony menu builder
PHP
1
star
39

admin-bundle

Symfony admin bundle, CMS
JavaScript
1
star
40

lru-cache

A Least Recently Used (LRU) Cache organizes items in order of use, allowing you to quickly identify which item hasn't been used for the longest amount of time.
Go
1
star