Skip to content

noble-gase/xe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

氙-Xe

golang pkg.go.dev MIT

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

特点

  1. 实现简单
  2. 性能优异
  3. 采用「生产-消费」模式
  4. 任务支持 context
  5. 支持任务缓存队列,缓存达上限会阻塞等待
  6. 基于官方版本实现的 errgroup,支持协程数量控制
  7. 简单实用的单层时间轮(支持一次性和多次重试任务)

安装

go get -u github.com/noble-gase/xe

流程图

flowchart.jpg

效果

goos: darwin
goarch: amd64
cpu: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz

场景-1

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

    pool := woker.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

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

    pool := woker.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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages