GithubHelp home page GithubHelp logo

tomwright / gopool Goto Github PK

View Code? Open in Web Editor NEW
11.0 4.0 1.0 53 KB

Easy to use worker pool with dynamic pool sizing.

License: MIT License

Go 100.00%
golang go processing pooling process-pool go-routine worker worker-pool pool worker-management

gopool's Introduction

gopool

Build Status codecov Documentation

Go Pool makes it easy to set up and manage pools of background workers. Not only can they be started and stopped, but they can also be dynamically sized ensuring you have the optimal amount of workers running for your situation.

Pool Types

Long running, always alive workers

To start a pool of long running workers who's size will be managed by gopool, you should use the Pool.Start func.

A good use case for this is when you have a message queue that jobs get published to. Then lets assume you want to always have at least 1 worker consuming jobs from the queue, but you also want to scale the number of consumers according to the current lag.

To do this, just pass in a WorkerCountFunc that returns the number of workers you would want to run at any point in time, and pass in a SleepTimeFunc to customise how often gopool should modify the number of running workers.

E.g. Your WorkerCountFunc could return the {number of unread items in the queue} / 100, and the SleepTimeFunc could return time.Second * 120. This would mean that every 2 minutes gopool would resize the pool and ensure that X / 100 workers are running, where X is the number of unread items in the queue.

Temporary workers, which will die once their designated work has been finished

To start a pool of temporary workers who will die when their work input channel is closed, you should use the Pool.StartOnce func.

To wait for the pool to finish it's work you can use the Pool.Done func, as the channel it returns is closed when the pool's work is done.

Installation

go get -u github.com/tomwright/gopool

Documentation

Documentation can be found at https://godoc.org/github.com/tomwright/gopool.

gopool's People

Contributors

tomwright avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

renesugar

gopool's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.