github.com/zly-app/zapp@v1.3.3/component/gpool/config.go (about)

     1  /*
     2  -------------------------------------------------
     3     Author :       zlyuancn
     4     date:         2021/3/19
     5     Description :
     6  -------------------------------------------------
     7  */
     8  
     9  package gpool
    10  
    11  import (
    12  	"runtime"
    13  
    14  	"github.com/zly-app/zapp/core"
    15  )
    16  
    17  // 默认组件类型
    18  const DefaultComponentType core.ComponentType = "gpool"
    19  
    20  const (
    21  	// 默认任务队列大小
    22  	defaultJobQueueSize = 10000
    23  )
    24  
    25  type GPoolConfig struct {
    26  	// 任务队列大小
    27  	JobQueueSize int
    28  	// 同时处理信息的goroutine数, 设为0时取逻辑cpu数量 * 2, 设为负数时不作任何限制, 每个请求有独立的线程执行
    29  	ThreadCount int
    30  }
    31  
    32  func (g *GPoolConfig) check() {
    33  	if g.JobQueueSize < 1 {
    34  		g.JobQueueSize = defaultJobQueueSize
    35  	}
    36  	if g.ThreadCount == 0 {
    37  		g.ThreadCount = runtime.NumCPU() * 2
    38  	}
    39  	if g.ThreadCount < 1 {
    40  		g.ThreadCount = -1
    41  	}
    42  }