alitto / pond

🔘 Minimalistic and High-performance goroutine worker pool written in Go
MIT License
1.43k stars 60 forks source link

pond.New(30, 100, pond.MinWorkers(30)) creates 60 goroutines not 30 #36

Closed hmedkouri closed 1 year ago

hmedkouri commented 1 year ago

I'm using version 1.8.1.

By writing pond.New(30, 100, pond.MinWorkers(30)) I'm expecting to create 30 goroutines at startup and have a fix pool of 30 overtime, am I correct?

Thank you

alitto commented 1 year ago

Hey @hmedkouri , that's right, with those options you are requesting a fixed size pool with 30 workers (max = 30 and min = 30). The title of the issue suggests you are seeting 60 goroutines, could you provide a full code example that displays this behaviour?

Here's a sample program that creates a pool with 30 workers, submits 1000 tasks and prints the size of the pool before & after:

package main

import (
    "fmt"
    "time"
    "github.com/alitto/pond"
)

func main() {

        // Create a fixed-size pool with 30 workers
    pool := pond.New(30, 100, pond.MinWorkers(30))
    fmt.Printf("Running workers before: %d\n", pool.RunningWorkers())

    // Submit 1000 tasks
    for i := 0; i < 1000; i++ {
        pool.Submit(func() {
            time.Sleep(10 * time.Millisecond)
        })
    }

    fmt.Printf("Running workers after: %d\n", pool.RunningWorkers())
    pool.StopAndWait()

}

This is what I'm seeing:

Running workers before: 30
Running workers after: 30
hmedkouri commented 1 year ago

Thank you that helped.

Note: I'm using pprof