xenon

module
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: MIT

README

xenon-go

golang pkg.go.dev MIT

[氙-Xenon] Go协程并发复用,降低CPU和内存负载

安装

go get -u github.com/noble-gase/xenon
模块 说明
errgroup 控制协程数量并按需创建
timewheel 分层时间轮(任务支持重试)
worker 基于 channel 实现的协程池

流程图

flowchart.jpg

效果

goos: darwin
goarch: arm64
cpu: Apple M4
场景-1
import "github.com/noble-gase/xenon/worker"

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

    pool := worker.New(5000)
    for i := 0; i < 100000000; i++ {
        i := i
        pool.Go(ctx, func(ctx context.Context) {
            time.Sleep(time.Second)
            fmt.Println("Index:", i)
        })
    }

    <-ctx.Done()
}
cpu

cpu-1.png

mem

mem-1.png

场景-2
import "github.com/noble-gase/xenon/worker"

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

    pool := worker.New(5000)
    for i := 0; i < 100; i++ {
        i := i
        pool.Go(ctx, func(ctx context.Context) {
            for j := 0; j < 1000000; j++ {
                j := j
                pool.Go(ctx, func(ctx context.Context) {
                    time.Sleep(time.Second)
                    fmt.Println("Index:", i, "-", j)
                })
            }
        })
    }

    <-ctx.Done()
}
cpu

cpu-2.png

mem

mem-2.png

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL