From 37ea64509a0848a4790c260f79cf698ba41a84a8 Mon Sep 17 00:00:00 2001 From: Sergey Solodyagin Date: Tue, 9 Apr 2024 00:01:28 +0300 Subject: [PATCH] rename --- .github/FUNDING.yml | 3 -- .github/workflows/codeql-analysis.yml | 70 ------------------------- .github/workflows/main.yml | 41 --------------- README.md | 52 +++++++++--------- examples/dynamic_size/dynamic_size.go | 2 +- examples/dynamic_size/go.mod | 8 ++- examples/fixed_size/fixed_size.go | 2 +- examples/fixed_size/go.mod | 8 ++- examples/group_context/go.mod | 8 ++- examples/group_context/group_context.go | 2 +- examples/pool_context/go.mod | 6 +-- examples/pool_context/pool_context.go | 2 +- examples/prometheus/go.mod | 6 +-- examples/prometheus/prometheus.go | 2 +- examples/task_group/go.mod | 8 ++- examples/task_group/task_group.go | 2 +- go.mod | 2 +- group_blackbox_test.go | 2 +- pond_blackbox_test.go | 2 +- 19 files changed, 54 insertions(+), 174 deletions(-) delete mode 100644 .github/FUNDING.yml delete mode 100644 .github/workflows/codeql-analysis.yml delete mode 100644 .github/workflows/main.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index cbc743b..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,3 +0,0 @@ -# These are supported funding model platforms - -github: alitto diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 7ec38c5..0000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,70 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - schedule: - - cron: '40 15 * * 1' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'go' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Learn more about CodeQL language support at https://git.io/codeql-language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index d374fe4..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,41 +0,0 @@ -on: - push: - branches: - - master - - main - pull_request: -name: Build -jobs: - test: - name: Test - strategy: - matrix: - go-version: [1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x] - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} - steps: - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v2 - - name: Test - run: make test - codecov: - name: Upload coverage report to Codecov - runs-on: ubuntu-latest - steps: - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v2 - - name: Test - run: make coverage - - uses: codecov/codecov-action@v3 - with: - files: coverage.out - fail_ci_if_error: true - verbose: true diff --git a/README.md b/README.md index 393108b..f4af441 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ # pond + Minimalistic and High-performance goroutine worker pool written in Go ## Motivation @@ -12,8 +13,8 @@ This library is meant to provide a simple way to limit concurrency when executin Some common scenarios include: - - Executing queries against a Database with a limited no. of connections - - Sending HTTP requests to a a rate/concurrency limited API +- Executing queries against a Database with a limited no. of connections +- Sending HTTP requests to a a rate/concurrency limited API ## Features: @@ -32,7 +33,7 @@ Some common scenarios include: - Task panics are handled gracefully (configurable panic handler) - Supports Non-blocking and Blocking task submission modes (buffered / unbuffered) - Very high performance and efficient resource usage under heavy workloads, even outperforming unbounded goroutines in some scenarios (See [benchmarks](https://github.com/alitto/pond-benchmarks)) -- Configurable pool resizing strategy, with 3 presets for common scenarios: Eager, Balanced and Lazy. +- Configurable pool resizing strategy, with 3 presets for common scenarios: Eager, Balanced and Lazy. - Complete pool metrics such as number of running workers, tasks waiting in the queue [and more](#metrics--monitoring). - **New (since v1.7.0)**: configurable parent context and graceful shutdown with deadline. - [API reference](https://pkg.go.dev/github.com/alitto/pond) @@ -40,20 +41,20 @@ Some common scenarios include: ## How to install ```bash -go get -u github.com/alitto/pond +go get -u git.company.lan/gopkg/pond ``` ## How to use ### Worker pool with dynamic size -``` go +```go package main import ( "fmt" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" ) func main() { @@ -77,18 +78,18 @@ func main() { ### Worker pool with fixed size -``` go +```go package main import ( "fmt" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" ) func main() { - // Create an unbuffered (blocking) pool with a fixed + // Create an unbuffered (blocking) pool with a fixed // number of workers pool := pond.New(10, 0, pond.MinWorkers(10)) @@ -107,13 +108,13 @@ func main() { ### Submitting a group of tasks -``` go +```go package main import ( "fmt" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" ) func main() { @@ -142,7 +143,7 @@ func main() { This feature provides synchronization, error propagation, and Context cancelation for subtasks of a common task. Similar to `errgroup.Group` from [`golang.org/x/sync/errgroup`](https://pkg.go.dev/golang.org/x/sync/errgroup) package with concurrency bounded by the worker pool. -``` go +```go package main import ( @@ -150,7 +151,7 @@ import ( "fmt" "net/http" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" ) func main() { @@ -197,8 +198,8 @@ func main() { Specifies the minimum number of worker goroutines that must be running at any given time. These goroutines are started when the pool is created. The default value is 0. Example: -``` go -// This will create a pool with 5 running worker goroutines +```go +// This will create a pool with 5 running worker goroutines pool := pond.New(10, 1000, pond.MinWorkers(5)) ``` @@ -206,14 +207,14 @@ pool := pond.New(10, 1000, pond.MinWorkers(5)) Defines how long to wait before removing idle worker goroutines from the pool. The default value is 5 seconds. Example: -``` go -// This will create a pool that will remove workers 100ms after they become idle +```go +// This will create a pool that will remove workers 100ms after they become idle pool := pond.New(10, 1000, pond.IdleTimeout(100 * time.Millisecond)) -``` +``` #### PanicHandler -Allows to configure a custom function to handle panics thrown by tasks submitted to the pool. The default handler just writes a message to standard output using `fmt.Printf` with the following contents: `Worker exits from a panic: [panic] \n Stack trace: [stack trace]`). Example: +Allows to configure a custom function to handle panics thrown by tasks submitted to the pool. The default handler just writes a message to standard output using `fmt.Printf` with the following contents: `Worker exits from a panic: [panic] \n Stack trace: [stack trace]`). Example: ```go // Custom panic handler function @@ -233,7 +234,7 @@ Configures the strategy used to resize the pool when backpressure is detected. Y - **Balanced**: tries to find a balance between responsiveness and throughput. It's suitable for general purpose worker pools or those that will operate close to 50% of their capacity most of the time. - **Lazy**: maximizes throughput at the expense of responsiveness. This strategy is meant for worker pools that will operate close to their max. capacity most of the time. -``` go +```go // Example: create pools with different resizing strategies eagerPool := pond.New(10, 1000, pond.Strategy(pond.Eager())) balancedPool := pond.New(10, 1000, pond.Strategy(pond.Balanced())) @@ -244,14 +245,14 @@ lazyPool := pond.New(10, 1000, pond.Strategy(pond.Lazy())) Configures a parent context on this pool to stop all workers when it is cancelled. The default value `context.Background()`. Example: -``` go -// This creates a pool that is stopped when myCtx is cancelled +```go +// This creates a pool that is stopped when myCtx is cancelled pool := pond.New(10, 1000, pond.Context(myCtx)) -``` +``` ### Resizing strategies -The following chart illustrates the behaviour of the different pool resizing strategies as the number of submitted tasks increases. Each line represents the number of worker goroutines in the pool (pool size) and the x-axis reflects the number of submitted tasks (cumulative). +The following chart illustrates the behaviour of the different pool resizing strategies as the number of submitted tasks increases. Each line represents the number of worker goroutines in the pool (pool size) and the x-axis reflects the number of submitted tasks (cumulative). ![Pool resizing strategies behaviour](./docs/strategies.svg) @@ -260,6 +261,7 @@ As the name suggests, the "Eager" strategy always spawns an extra worker when th ### Stopping a pool There are 3 methods available to stop a pool and release associated resources: + - `pool.Stop()`: stop accepting new tasks and signal all workers to stop processing new tasks. Tasks being processed by workers will continue until completion unless the process is terminated. - `pool.StopAndWait()`: stop accepting new tasks and wait until all running and queued tasks have completed before returning. - `pool.StopAndWaitFor(deadline time.Duration)`: similar to `StopAndWait` but with a deadline to prevent waiting indefinitely. @@ -310,4 +312,4 @@ Here are some of the resources which have served as inspiration when writing thi ## Contribution & Support -Feel free to send a pull request if you consider there's something which can be improved. Also, please open up an issue if you run into a problem when using this library or just have a question. \ No newline at end of file +Feel free to send a pull request if you consider there's something which can be improved. Also, please open up an issue if you run into a problem when using this library or just have a question. diff --git a/examples/dynamic_size/dynamic_size.go b/examples/dynamic_size/dynamic_size.go index 041565b..71bef5a 100644 --- a/examples/dynamic_size/dynamic_size.go +++ b/examples/dynamic_size/dynamic_size.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" ) func main() { diff --git a/examples/dynamic_size/go.mod b/examples/dynamic_size/go.mod index dfdfcf8..882c813 100644 --- a/examples/dynamic_size/go.mod +++ b/examples/dynamic_size/go.mod @@ -1,9 +1,7 @@ -module github.com/alitto/pond/examples/dynamic_size +module git.company.lan/gopkg/pond/examples/dynamic_size go 1.19 -require ( - github.com/alitto/pond v1.7.1 -) +require git.company.lan/gopkg/pond v0.0.0-00010101000000-000000000000 -replace github.com/alitto/pond => ../../ +replace git.company.lan/gopkg/pond => ../../ diff --git a/examples/fixed_size/fixed_size.go b/examples/fixed_size/fixed_size.go index ffe1263..0460867 100644 --- a/examples/fixed_size/fixed_size.go +++ b/examples/fixed_size/fixed_size.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" ) func main() { diff --git a/examples/fixed_size/go.mod b/examples/fixed_size/go.mod index 501b829..eeadf23 100644 --- a/examples/fixed_size/go.mod +++ b/examples/fixed_size/go.mod @@ -1,9 +1,7 @@ -module github.com/alitto/pond/examples/fixed_size +module git.company.lan/gopkg/pond/examples/fixed_size go 1.19 -require ( - github.com/alitto/pond v1.7.1 -) +require git.company.lan/gopkg/pond v0.0.0-00010101000000-000000000000 -replace github.com/alitto/pond => ../../ +replace git.company.lan/gopkg/pond => ../../ diff --git a/examples/group_context/go.mod b/examples/group_context/go.mod index d691841..5a71afe 100644 --- a/examples/group_context/go.mod +++ b/examples/group_context/go.mod @@ -1,9 +1,7 @@ -module github.com/alitto/pond/examples/group_context +module git.company.lan/gopkg/pond/examples/group_context go 1.19 -require ( - github.com/alitto/pond v1.7.1 -) +require git.company.lan/gopkg/pond v0.0.0-00010101000000-000000000000 -replace github.com/alitto/pond => ../../ +replace git.company.lan/gopkg/pond => ../../ diff --git a/examples/group_context/group_context.go b/examples/group_context/group_context.go index 99e97db..d03c215 100644 --- a/examples/group_context/group_context.go +++ b/examples/group_context/group_context.go @@ -5,7 +5,7 @@ import ( "fmt" "net/http" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" ) func main() { diff --git a/examples/pool_context/go.mod b/examples/pool_context/go.mod index 86edb61..26db644 100644 --- a/examples/pool_context/go.mod +++ b/examples/pool_context/go.mod @@ -1,7 +1,7 @@ -module github.com/alitto/pond/examples/pool_context +module git.company.lan/gopkg/pond/examples/pool_context go 1.19 -require github.com/alitto/pond v1.7.1 +require git.company.lan/gopkg/pond v0.0.0-00010101000000-000000000000 -replace github.com/alitto/pond => ../../ +replace git.company.lan/gopkg/pond => ../../ diff --git a/examples/pool_context/pool_context.go b/examples/pool_context/pool_context.go index 14ee93c..021cc4c 100644 --- a/examples/pool_context/pool_context.go +++ b/examples/pool_context/pool_context.go @@ -7,7 +7,7 @@ import ( "os/signal" "time" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" ) // Pressing Ctrl+C while this program is running will cause the program to terminate gracefully. diff --git a/examples/prometheus/go.mod b/examples/prometheus/go.mod index 74005ab..9952b92 100644 --- a/examples/prometheus/go.mod +++ b/examples/prometheus/go.mod @@ -1,9 +1,9 @@ -module github.com/alitto/pond/examples/fixed_size +module git.company.lan/gopkg/pond/examples/fixed_size go 1.19 require ( - github.com/alitto/pond v1.7.1 + git.company.lan/gopkg/pond v0.0.0-00010101000000-000000000000 github.com/prometheus/client_golang v1.11.1 ) @@ -19,4 +19,4 @@ require ( google.golang.org/protobuf v1.33.0 // indirect ) -replace github.com/alitto/pond => ../../ +replace git.company.lan/gopkg/pond => ../../ diff --git a/examples/prometheus/prometheus.go b/examples/prometheus/prometheus.go index 423e0ac..c688041 100644 --- a/examples/prometheus/prometheus.go +++ b/examples/prometheus/prometheus.go @@ -5,7 +5,7 @@ import ( "net/http" "time" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) diff --git a/examples/task_group/go.mod b/examples/task_group/go.mod index dadc199..caa31dc 100644 --- a/examples/task_group/go.mod +++ b/examples/task_group/go.mod @@ -1,9 +1,7 @@ -module github.com/alitto/pond/examples/task_group +module git.company.lan/gopkg/pond/examples/task_group go 1.19 -require ( - github.com/alitto/pond v1.7.1 -) +require git.company.lan/gopkg/pond v0.0.0-00010101000000-000000000000 -replace github.com/alitto/pond => ../../ +replace git.company.lan/gopkg/pond => ../../ diff --git a/examples/task_group/task_group.go b/examples/task_group/task_group.go index 7193a5f..8e27f9c 100644 --- a/examples/task_group/task_group.go +++ b/examples/task_group/task_group.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" ) func main() { diff --git a/go.mod b/go.mod index 1f22444..850a033 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/alitto/pond +module git.company.lan/gopkg/pond go 1.19 diff --git a/group_blackbox_test.go b/group_blackbox_test.go index b0a0144..7725a72 100644 --- a/group_blackbox_test.go +++ b/group_blackbox_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" ) func TestGroupSubmit(t *testing.T) { diff --git a/pond_blackbox_test.go b/pond_blackbox_test.go index ca10b11..0234909 100644 --- a/pond_blackbox_test.go +++ b/pond_blackbox_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/alitto/pond" + "git.company.lan/gopkg/pond" ) func assertEqual(t *testing.T, expected interface{}, actual interface{}) {