gorker

package module
v0.0.0-...-0cc444e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2019 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gorker release CircleCI codecov Codacy Badge Go Report Card GoDoc

gorker is golang dispatch worker management library

Requirement

Go 1.8

Installation

go get github.com/kpango/gorker

Example

func main() {
	dispatcher := gorker.Get(3)
	dispatcher.StartWorkerObserver()

	for i := 0; i < 10000; i++ {
		func(n int) {
			dispatcher.Add(func() error {
				fmt.Printf("%03d:\t workers: %d\t%v\n", n, runtime.NumGoroutine()-2, time.Now().Format(time.RFC3339))
				time.Sleep(time.Millisecond * 100)
				return nil
			})
		}(i)
	}
	dispatcher.Start()

	time.Sleep(time.Second * 5)

	gorker.UpScale(7)
	fmt.Printf("UpScale : %d\n", 7)

	time.Sleep(time.Second * 5)

	gorker.DownScale(2)
	fmt.Printf("DownScale : %d\n", 2)

	time.Sleep(time.Second * 5)

	gorker.UpScale(20)
	time.Sleep(time.Second * 5)

	dispatcher.Add(func() error {
		fmt.Printf("last worker:\t workers: %d\t%v\n", runtime.NumGoroutine()-2, time.Now().Format(time.RFC3339))
		time.Sleep(time.Millisecond * 100)
		return nil
	})

	gorker.UpScale(200)
	time.Sleep(time.Second * 5)

	dispatcher.Stop(true)

	dispatcher.Wait()
}

Sample Logs

Benchmarks

Bench

Contribution

  1. Fork it ( https://github.com/kpango/gorker/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

kpango

LICENSE

gorker released under MIT license, refer LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(job func() error) chan error

func GetWorkerCount

func GetWorkerCount() int

func Wait

func Wait()

Types

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

func AutoScale

func AutoScale() *Dispatcher

func DownScale

func DownScale(workerCount int) *Dispatcher

func Get

func Get(maxWorker int) *Dispatcher

func GetInstance

func GetInstance() *Dispatcher

func New

func New(maxWorker int) *Dispatcher

func Reset

func Reset() *Dispatcher

func SafeReset

func SafeReset() *Dispatcher

func Start

func Start() *Dispatcher

func StartWithContext

func StartWithContext(c context.Context) *Dispatcher

func StartWorkerObserver

func StartWorkerObserver() *Dispatcher

func Stop

func Stop(immediately bool) *Dispatcher

func UpScale

func UpScale(workerCount int) *Dispatcher

func (*Dispatcher) Add

func (d *Dispatcher) Add(job func() error) chan error

func (*Dispatcher) AutoScale

func (d *Dispatcher) AutoScale() *Dispatcher

func (*Dispatcher) DownScale

func (d *Dispatcher) DownScale(workerCount int) *Dispatcher

func (*Dispatcher) GetWorkerCount

func (d *Dispatcher) GetWorkerCount() int

GetWorkerCount returns current worker count this function will be blocking while worker scaling

func (*Dispatcher) QueueRunner

func (d *Dispatcher) QueueRunner() *Dispatcher

func (*Dispatcher) Reset

func (d *Dispatcher) Reset() *Dispatcher

func (*Dispatcher) SafeReset

func (d *Dispatcher) SafeReset() *Dispatcher

func (*Dispatcher) ScaleBuffer

func (d *Dispatcher) ScaleBuffer(size int) *Dispatcher

func (*Dispatcher) Start

func (d *Dispatcher) Start() *Dispatcher

func (*Dispatcher) StartWithContext

func (d *Dispatcher) StartWithContext(c context.Context) *Dispatcher

func (*Dispatcher) StartWorkerObserver

func (d *Dispatcher) StartWorkerObserver() *Dispatcher

func (*Dispatcher) Stop

func (d *Dispatcher) Stop(immediately bool) *Dispatcher

func (*Dispatcher) UpScale

func (d *Dispatcher) UpScale(workerCount int) *Dispatcher

func (*Dispatcher) Wait

func (d *Dispatcher) Wait()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址