Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup
uses: actions/setup-go@v4
with:
go-version: "1.23"
go-version: "1.25"

- run: go version

Expand Down
9 changes: 7 additions & 2 deletions FUTURE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
## ✒ 未来版本的新特性 (Features in future versions)

### v0.3.x

* [x] 重构代码,精简 Executor 实现
* [ ] 完善单元测试,将覆盖率提高到 90% 以上

### v0.2.x

* [x] 增加异步任务执行器
* [x] 支持轮询调度策略
* [x] 支持随机调度策略
* [ ] 支持任务数量优先调度策略
* [ ] 支持任务时间优先调度策略
* [ ] ~~支持任务数量优先调度策略~~
* [ ] ~~支持任务时间优先调度策略~~
* [x] 支持 worker 动态扩缩容
* [x] 支持查询可用的 worker 数量
* [x] 支持设置 worker 任务队列大小
Expand Down
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## ✒ 历史版本的特性介绍 (Features in old versions)

### v0.3.0-alpha

> 此版本发布于 2026-01-07

* 重构代码,精简 Executor 实现

### v0.2.5-alpha

> 此版本发布于 2025-06-30
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2023 FishGoddess
Copyright (c) 2025 FishGoddess

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
Expand Down
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
.PHONY: test fmt
.PHONY: fmt test

all: test
all: fmt test

fmt:
go fmt ./...

test:
go test -v -cover ./...

bench:
go test -v ./_examples/performance_test.go -run=none -bench=. -benchmem -benchtime=1s
go test -v ./_examples/basic_test.go -run=none -bench=. -benchmem -benchtime=1s

fmt:
go fmt ./...
25 changes: 15 additions & 10 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ $ go get -u github.com/FishGoddess/goes
package main

import (
"context"
"fmt"
"time"

"github.com/FishGoddess/goes"
)

func main() {
ctx := context.Background()

// Limits the number of simultaneous goroutines and not reuses them.
limiter := goes.NewLimiter(4)

Expand All @@ -54,7 +57,7 @@ func main() {
defer executor.Close()

for i := 0; i < 20; i++ {
executor.Submit(func() {
executor.Submit(ctx, func() {
fmt.Printf("executor --> %s\n", time.Now())
time.Sleep(time.Second)
})
Expand All @@ -73,20 +76,22 @@ $ make bench
```bash
goos: linux
goarch: amd64
cpu: AMD EPYC 7K62 48-Core Processor
cpu: Intel(R) Xeon(R) CPU E5-26xx v4

BenchmarkLimiter-2 2417040 498.5 ns/op 24 B/op 1 allocs/op
BenchmarkExecutor-2 20458502 58.3 ns/op 0 B/op 0 allocs/op
BenchmarkAntsPool-2 4295964 271.7 ns/op 0 B/op 0 allocs/op
BenchmarkLimiter-2 1256862 870.5 ns/op 24 B/op 1 allocs/op
BenchmarkExecutor-2 3916312 286.8 ns/op 0 B/op 0 allocs/op
BenchmarkAntsPool-2 1396972 846.6 ns/op 0 B/op 0 allocs/op
BenchmarkConcPool-2 1473289 843.4 ns/op 0 B/op 0 allocs/op

BenchmarkLimiterTime-2: num is 1000000, cost is 300.936441ms
BenchmarkExecutorTime-2: num is 1000000, cost is 63.026947ms
BenchmarkAntsPoolTime-2: num is 999744, cost is 346.972287ms
BenchmarkLimiterTime-2: num is 500000, cost is 391.462505ms
BenchmarkExecutorTime-2: num is 500000, cost is 180.279155ms
BenchmarkAntsPoolTime-2: num is 500000, cost is 547.328528ms
BenchmarkConcPoolTime-2: num is 500000, cost is 390.354196ms
```

> Obviously, goes.Executor is 5x faster than ants.Pool which has more features, so try goes if you prefer a lightweight and faster executor.
> Obviously, goes.Executor is faster than other concurrent libraries, so try goes.Executor if you prefer a light-weight and faster executor.

> Benchmarks: [_examples/performance_test.go](./_examples/performance_test.go).
> Benchmarks: [_examples/basic_test.go](./_examples/basic_test.go).

### 👥 Contributing

Expand Down
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ $ go get -u github.com/FishGoddess/goes
package main

import (
"context"
"fmt"
"time"

"github.com/FishGoddess/goes"
)

func main() {
ctx := context.Background()

// Limits the number of simultaneous goroutines and not reuses them.
limiter := goes.NewLimiter(4)

Expand All @@ -54,7 +57,7 @@ func main() {
defer executor.Close()

for i := 0; i < 20; i++ {
executor.Submit(func() {
executor.Submit(ctx, func() {
fmt.Printf("executor --> %s\n", time.Now())
time.Sleep(time.Second)
})
Expand All @@ -73,20 +76,22 @@ $ make bench
```bash
goos: linux
goarch: amd64
cpu: AMD EPYC 7K62 48-Core Processor
cpu: Intel(R) Xeon(R) CPU E5-26xx v4

BenchmarkLimiter-2 2417040 498.5 ns/op 24 B/op 1 allocs/op
BenchmarkExecutor-2 20458502 58.3 ns/op 0 B/op 0 allocs/op
BenchmarkAntsPool-2 4295964 271.7 ns/op 0 B/op 0 allocs/op
BenchmarkLimiter-2 1256862 870.5 ns/op 24 B/op 1 allocs/op
BenchmarkExecutor-2 3916312 286.8 ns/op 0 B/op 0 allocs/op
BenchmarkAntsPool-2 1396972 846.6 ns/op 0 B/op 0 allocs/op
BenchmarkConcPool-2 1473289 843.4 ns/op 0 B/op 0 allocs/op

BenchmarkLimiterTime-2: num is 1000000, cost is 300.936441ms
BenchmarkExecutorTime-2: num is 1000000, cost is 63.026947ms
BenchmarkAntsPoolTime-2: num is 999744, cost is 346.972287ms
BenchmarkLimiterTime-2: num is 500000, cost is 391.462505ms
BenchmarkExecutorTime-2: num is 500000, cost is 180.279155ms
BenchmarkAntsPoolTime-2: num is 500000, cost is 547.328528ms
BenchmarkConcPoolTime-2: num is 500000, cost is 390.354196ms
```

> 很明显,goes.Executor 的性能比功能更丰富的 ants.Pool 要高出 5 倍左右,所以当你需要一个很轻量且高性能的异步任务执行器时,可以尝试下 goes。
> 很明显,goes.Executor 的性能比其他的并发执行库高很多,所以当你需要一个轻量且高性能的并发执行器时,可以尝试下 goes.Executor

> 测试文件:[_examples/performance_test.go](./_examples/performance_test.go)。
> 测试文件:[_examples/basic_test.go](./_examples/basic_test.go)。

### 👥 贡献者

Expand Down
7 changes: 5 additions & 2 deletions _examples/basic.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// Copyright 2025s FishGoddess. All rights reserved.
// Copyright 2025 FishGoddess. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package main

import (
"context"
"fmt"
"time"

"github.com/FishGoddess/goes"
)

func main() {
ctx := context.Background()

// Limits the number of simultaneous goroutines and not reuses them.
limiter := goes.NewLimiter(4)

Expand All @@ -29,7 +32,7 @@ func main() {
defer executor.Close()

for i := 0; i < 20; i++ {
executor.Submit(func() {
executor.Submit(ctx, func() {
fmt.Printf("executor --> %s\n", time.Now())
time.Sleep(time.Second)
})
Expand Down
62 changes: 52 additions & 10 deletions _examples/performance_test.go → _examples/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
package main

import (
"context"
"sync/atomic"
"testing"
"time"

"github.com/FishGoddess/goes"
//"github.com/panjf2000/ants/v2"
//"github.com/sourcegraph/conc/pool"
)

const (
limit = 256
workerNum = limit
size = limit
timeLoop = 100_0000
limit = 64
workers = limit
timeLoop = 50_0000
)

func bench(num *uint32) {
Expand Down Expand Up @@ -65,7 +66,8 @@ func BenchmarkLimiterTime(b *testing.B) {

// go test -v -run=none -bench=^BenchmarkExecutor$ -benchmem -benchtime=1s
func BenchmarkExecutor(b *testing.B) {
executor := goes.NewExecutor(workerNum)
ctx := context.Background()
executor := goes.NewExecutor(workers)

num := uint32(0)
task := func() {
Expand All @@ -74,7 +76,7 @@ func BenchmarkExecutor(b *testing.B) {

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
executor.Submit(task)
executor.Submit(ctx, task)
}
})

Expand All @@ -84,7 +86,8 @@ func BenchmarkExecutor(b *testing.B) {

// go test -v -run=none -bench=^BenchmarkExecutorTime$ -benchmem -benchtime=1s
func BenchmarkExecutorTime(b *testing.B) {
executor := goes.NewExecutor(workerNum)
ctx := context.Background()
executor := goes.NewExecutor(workers)

num := uint32(0)
task := func() {
Expand All @@ -93,7 +96,7 @@ func BenchmarkExecutorTime(b *testing.B) {

beginTime := time.Now()
for range timeLoop {
executor.Submit(task)
executor.Submit(ctx, task)
}

executor.Close()
Expand All @@ -104,7 +107,7 @@ func BenchmarkExecutorTime(b *testing.B) {

// // go test -v -run=none -bench=^BenchmarkAntsPool$ -benchmem -benchtime=1s
// func BenchmarkAntsPool(b *testing.B) {
// pool, _ := ants.NewPool(workerNum)
// pool, _ := ants.NewPool(workers)
//
// num := uint32(0)
// task := func() {
Expand All @@ -123,7 +126,7 @@ func BenchmarkExecutorTime(b *testing.B) {
//
// // go test -v -run=none -bench=^BenchmarkAntsPoolTime$ -benchmem -benchtime=1s
// func BenchmarkAntsPoolTime(b *testing.B) {
// pool, _ := ants.NewPool(workerNum)
// pool, _ := ants.NewPool(workers)
//
// num := uint32(0)
// task := func() {
Expand All @@ -140,3 +143,42 @@ func BenchmarkExecutorTime(b *testing.B) {
// cost := time.Since(beginTime)
// b.Logf("num is %d, cost is %s", num, cost)
// }
//
// // // go test -v -run=none -bench=^BenchmarkConcPool$ -benchmem -benchtime=1s
// func BenchmarkConcPool(b *testing.B) {
// pool := pool.New().WithMaxGoroutines(workers)
//
// num := uint32(0)
// task := func() {
// bench(&num)
// }
//
// b.RunParallel(func(pb *testing.PB) {
// for pb.Next() {
// pool.Go(task)
// }
// })
//
// pool.Wait()
// b.Logf("num is %d", num)
// }
//
// // go test -v -run=none -bench=^BenchmarkConcPoolTime$ -benchmem -benchtime=1s
// func BenchmarkConcPoolTime(b *testing.B) {
// pool := pool.New().WithMaxGoroutines(workers)
//
// num := uint32(0)
// task := func() {
// bench(&num)
// }
//
// beginTime := time.Now()
// for range timeLoop {
// pool.Go(task)
// }
//
// pool.Wait()
//
// cost := time.Since(beginTime)
// b.Logf("num is %d, cost is %s", num, cost)
// }
58 changes: 0 additions & 58 deletions _examples/purge.go

This file was deleted.

Loading
Loading