Git Product home page Git Product logo

simpool's Introduction

simpool...

goroutine pool with channel

Installation

go get github.com/wonksing/simpool

Example

Basic Usage: Simple print

// PrintJob to push into the pool
// A job which interfaces simpool.Job
type PrintJob struct {
	word string
}

// Execute your job here
func (s *PrintJob) Execute() *simpool.JobResult {
	// your code
	fmt.Println(s.word)

	// returns nil since we are just printing word
	return nil
}

var (
	numWorkers   int
	maxQueueSize int
	numTests     int
)

func init() {
	flag.IntVar(&numWorkers, "w", 32, "number of workers")
	flag.IntVar(&maxQueueSize, "q", 100, "max queue size")
	flag.IntVar(&numTests, "n", 200000, "number of tests")
	flag.Parse()
	runtime.GOMAXPROCS(runtime.NumCPU())
}
func main() {
	log.Printf("numWorkers: %v, maxQueueSize: %v, numCPU: %v", numWorkers, maxQueueSize, runtime.NumCPU())

	start := time.Now()
	// create pool
	pool := simpool.NewPool(numWorkers, maxQueueSize)

	// create a job in each iteration and queue into the pool
	for i := 0; i < numTests; i++ {
		job := &PrintJob{strconv.Itoa(i)}
		pool.Queue(job) // non-blocking operation as long as the pool has remaining space
	}
	log.Printf("Finished queueing(%v)\n", time.Now())
	pool.Close() // wait for all jobs to finish and return

	elapsed := time.Since(start)
	log.Printf("Finished %v jobs(%v)\n", numTests, elapsed)
}

Usage in DB to DB

Usage in Http Server

simpool's People

Contributors

wonkdance avatar wonksing avatar

Stargazers

 avatar

Watchers

 avatar  avatar

simpool's Issues

리팩토링

  1. README.md 작성
  2. 코드 주석 & 명칭 정리 필요

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.