diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-07-27 16:40:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-27 16:40:35 +0800 |
commit | 8baa42c8d749381649404ecb194b8510af11ba0a (patch) | |
tree | ba1ef17894522c40eb41d3f9c484ccd9ba1a50d2 /modules/setting | |
parent | 73fb1ecdcf7c72c9b15caa70a8e3f444d311bd7b (diff) | |
download | gitea-8baa42c8d749381649404ecb194b8510af11ba0a.tar.gz gitea-8baa42c8d749381649404ecb194b8510af11ba0a.zip |
Calculate MAX_WORKERS default value by CPU number (#26177)
To avoid consuming user's 100% CPU, limit the default value of
MAX_WORKERS
Fix #26063 (the CPU 100% problem mentioned in it)
Diffstat (limited to 'modules/setting')
-rw-r--r-- | modules/setting/queue.go | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/modules/setting/queue.go b/modules/setting/queue.go index 8673537b52..fc15bd07ed 100644 --- a/modules/setting/queue.go +++ b/modules/setting/queue.go @@ -5,6 +5,7 @@ package setting import ( "path/filepath" + "runtime" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" @@ -25,18 +26,24 @@ type QueueSettings struct { MaxWorkers int } -var queueSettingsDefault = QueueSettings{ - Type: "level", // dummy, channel, level, redis - Datadir: "queues/common", // relative to AppDataPath - Length: 100, // queue length before a channel queue will block - - QueueName: "_queue", - SetName: "_unique", - BatchLength: 20, - MaxWorkers: 10, -} - func GetQueueSettings(rootCfg ConfigProvider, name string) (QueueSettings, error) { + queueSettingsDefault := QueueSettings{ + Type: "level", // dummy, channel, level, redis + Datadir: "queues/common", // relative to AppDataPath + Length: 100, // queue length before a channel queue will block + + QueueName: "_queue", + SetName: "_unique", + BatchLength: 20, + MaxWorkers: runtime.NumCPU() / 2, + } + if queueSettingsDefault.MaxWorkers < 1 { + queueSettingsDefault.MaxWorkers = 1 + } + if queueSettingsDefault.MaxWorkers > 10 { + queueSettingsDefault.MaxWorkers = 10 + } + // deep copy default settings cfg := QueueSettings{} if cfgBs, err := json.Marshal(queueSettingsDefault); err != nil { |