Merged in feature/threadpoolchanges (pull request #121)
Thread Pool Changes * commentresponses
This commit is contained in:
@@ -63,7 +63,7 @@ func New(ctx context.Context, cfg Config) (func() error, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg.SetThreadPool(cfg.GetLogger())
|
||||
cfg.StartThreadPool(cfg.GetLogger())
|
||||
|
||||
return closeTracer, nil
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ type ConfigProvider interface {
|
||||
GetThreadMonitorInterval() int
|
||||
GetThreadPool() pond.Pool
|
||||
ThreadPoolStopAndWait()
|
||||
SetThreadPool(*slog.Logger)
|
||||
StartThreadPool(*slog.Logger)
|
||||
}
|
||||
|
||||
type ThreadPoolConfig struct {
|
||||
@@ -30,11 +30,11 @@ type PoolMetrics struct {
|
||||
ProcessingTime time.Duration
|
||||
}
|
||||
|
||||
func (dp *ThreadPoolConfig) SetThreadPool(logger *slog.Logger) {
|
||||
func (dp *ThreadPoolConfig) StartThreadPool(logger *slog.Logger) {
|
||||
dp.logger = logger
|
||||
|
||||
if dp.MaxWorkers <= 0 {
|
||||
dp.MaxWorkers = runtime.NumCPU() * 10000
|
||||
dp.MaxWorkers = runtime.NumCPU() * 10
|
||||
}
|
||||
|
||||
if dp.MonitorInterval <= 0 {
|
||||
@@ -85,7 +85,7 @@ func (dp *ThreadPoolConfig) GetThreadMonitorInterval() int {
|
||||
|
||||
func (dp *ThreadPoolConfig) GetThreadPool() pond.Pool {
|
||||
if dp.pool == nil {
|
||||
dp.SetThreadPool(slog.Default())
|
||||
dp.StartThreadPool(slog.Default())
|
||||
}
|
||||
|
||||
return dp.pool
|
||||
|
||||
@@ -16,9 +16,9 @@ func TestSetThreadPool(t *testing.T) {
|
||||
}
|
||||
sl := slog.New(l)
|
||||
|
||||
cfg.SetThreadPool(sl)
|
||||
cfg.StartThreadPool(sl)
|
||||
assert.Equal(t, 120, cfg.MonitorInterval)
|
||||
assert.LessOrEqual(t, 10000, cfg.MaxWorkers)
|
||||
assert.LessOrEqual(t, 10, cfg.MaxWorkers)
|
||||
assert.NotNil(t, cfg.pool)
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ func TestStopAndWait(t *testing.T) {
|
||||
sl := slog.New(l)
|
||||
|
||||
cfg.MonitorInterval = 1
|
||||
cfg.SetThreadPool(sl)
|
||||
cfg.StartThreadPool(sl)
|
||||
assert.Equal(t, 1, cfg.MonitorInterval)
|
||||
assert.LessOrEqual(t, 10000, cfg.MaxWorkers)
|
||||
assert.LessOrEqual(t, 10, cfg.MaxWorkers)
|
||||
assert.NotNil(t, cfg.pool)
|
||||
|
||||
for i := range 1000 {
|
||||
|
||||
Reference in New Issue
Block a user