All Projects β†’ loveleshsharma β†’ gohive

loveleshsharma / gohive

Licence: MIT license
🐝 A Highly Performant and easy to use goroutine pool for Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to gohive

errgroup
errgroup with goroutine worker limits
Stars: ✭ 143 (+248.78%)
Mutual labels:  pool, goroutine, goroutine-pool
python-task-queue
Asynchronous serverless task queue with timed leasing of tasks. Threaded implementations for SQS and local filesystem.
Stars: ✭ 24 (-41.46%)
Mutual labels:  asynchronous-tasks, task-scheduler, task-queue
goroutine-pool
A simple goroutine pool which can create and release goroutine dynamically, inspired by fasthttp.
Stars: ✭ 31 (-24.39%)
Mutual labels:  pool, goroutine, goroutine-pool
Ants
🐜🐜🐜 ants is a high-performance and low-cost goroutine pool in Go, inspired by fasthttp./ ants ζ˜―δΈ€δΈͺι«˜ζ€§θƒ½δΈ”δ½ŽζŸθ€—ηš„ goroutine 池。
Stars: ✭ 7,180 (+17412.2%)
Mutual labels:  pool, goroutine, goroutine-pool
Asynq
Asynq: simple, reliable, and efficient distributed task queue in Go
Stars: ✭ 934 (+2178.05%)
Mutual labels:  asynchronous-tasks, task-queue
psched
Priority-based Task Scheduling for Modern C++
Stars: ✭ 59 (+43.9%)
Mutual labels:  task-scheduler, task-queue
Django Carrot
A lightweight task queue for Django using RabbitMQ
Stars: ✭ 58 (+41.46%)
Mutual labels:  asynchronous-tasks, task-queue
Cronscheduler.aspnetcore
Cron Scheduler for AspNetCore 2.x/3.x or DotNetCore 2.x/3.x Self-hosted
Stars: ✭ 100 (+143.9%)
Mutual labels:  asynchronous-tasks, task-scheduler
Cadence Java Client
Java framework for Cadence Workflow Service
Stars: ✭ 85 (+107.32%)
Mutual labels:  task-scheduler, task-queue
Rqueue
Rqueue aka Redis Queue [Task Queue, Message Broker] for Spring framework
Stars: ✭ 76 (+85.37%)
Mutual labels:  asynchronous-tasks, task-scheduler
Grpool
Lightweight Goroutine pool
Stars: ✭ 616 (+1402.44%)
Mutual labels:  pool, goroutine
workerpool
A workerpool that can get expanded & shrink dynamically.
Stars: ✭ 55 (+34.15%)
Mutual labels:  pool, goroutine
theeye-of-sauron
TheEye Dockers and QuickStart
Stars: ✭ 27 (-34.15%)
Mutual labels:  task-scheduler, task-queue
Gorpool
Simple Goroutine pool
Stars: ✭ 37 (-9.76%)
Mutual labels:  pool, goroutine
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 (+114.63%)
Mutual labels:  pool, goroutine-pool
orkid-node
Reliable and modern Redis Streams based task queue for Node.js πŸ€–
Stars: ✭ 61 (+48.78%)
Mutual labels:  task-scheduler, task-queue
billiards
billiards physics
Stars: ✭ 37 (-9.76%)
Mutual labels:  pool
go-workshops
Go language basic workshops for devz
Stars: ✭ 68 (+65.85%)
Mutual labels:  goroutine
php-task
Interface library for the PHPTask library
Stars: ✭ 23 (-43.9%)
Mutual labels:  task-scheduler
node-redis-connection-pool
A node.js connection manager for Redis
Stars: ✭ 52 (+26.83%)
Mutual labels:  pool

gohive

Package gohive implements a simple and easy to use goroutine pool for Go

Features

  • Pool can be created with a specific size as per the requirement
  • Offers efficient performance by implementing sync.Pool, which maintains pool of workers in which workers gets recycled automatically when not in use
  • Implements a Task Queue which can hold surplus tasks in waiting, if submitted more than the pool capacity
  • Implements PoolService type, which acts as an easy to use API with simple methods to interact with gohive
  • Gracefully handles panics and prevent the application from getting crashed or into deadlocks
  • Provides functions like: AvailableWorkers(), ActiveWorkers() and Close() etc.

Installation

Use go get to install and update:

$ go get -u github.com/loveleshsharma/gohive

Usage

  • Create an instance of PoolService type first
hive := gohive.NewFixedSizePool(5)
  • Invoke the Submit() function and pass the task to execute
hive.Submit(someTask())

Submit function accepts a function as an argument, which it passes to the pool if a worker is available, otherwise enqueues it in a waiting queue

  • To close the pool we can invoke the Close() function
hive.Close()

Once the pool is closed, we cannot assign any task to it

Example

Let's get into a full program where we can see how to use the gohive package in order to execute many goroutines simultaneously

package main

import (
	"github.com/loveleshsharma/gohive"
	"fmt"
	"sync"
)

func main() {

	var wg sync.WaitGroup
	hivePool := gohive.NewFixedSizePool(5)

	//wrap your executable function into another function with wg.Done()
	executableTask := func() {
		defer wg.Done()
		factorial(5)
	}

	wg.Add(1)
	hivePool.Submit(executableTask)

	wg.Wait()
}

func factorial(val int) {
	var fact = val
	var res = 1

	for i := fact; i > 0; i-- {
		res = res * i
	}

	fmt.Printf("Factorial: %v", res)
}

Important : Always put defer wg.Done() as the first statement of your wrapper function. It will prevent your program from deadlocks in case of panics

Workers implements a notifying mechanism, due to which they can notify to the pool that their task is completed and they are available to execute more tasks if in waiting queue

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].