mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
set max API requests automatically based on RAM (#10421)
This commit is contained in:
parent
b0e1d4ce78
commit
572b1721b2
@ -377,7 +377,7 @@ func lookupConfigs(s config.Config, setDriveCount int) {
|
||||
logger.LogIf(ctx, fmt.Errorf("Invalid api configuration: %w", err))
|
||||
}
|
||||
|
||||
globalAPIConfig.init(apiConfig)
|
||||
globalAPIConfig.init(apiConfig, setDriveCount)
|
||||
|
||||
if globalIsErasure {
|
||||
globalStorageClass, err = storageclass.LookupConfig(s[config.StorageClassSubSys][config.Default], setDriveCount)
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio/cmd/config/api"
|
||||
"github.com/minio/minio/pkg/sys"
|
||||
)
|
||||
|
||||
type apiConfig struct {
|
||||
@ -33,22 +34,30 @@ type apiConfig struct {
|
||||
corsAllowOrigins []string
|
||||
}
|
||||
|
||||
func (t *apiConfig) init(cfg api.Config) {
|
||||
func (t *apiConfig) init(cfg api.Config, setDriveCount int) {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
|
||||
t.readyDeadline = cfg.APIReadyDeadline
|
||||
t.corsAllowOrigins = cfg.APICorsAllowOrigin
|
||||
var apiRequestsMaxPerNode int
|
||||
if cfg.APIRequestsMax <= 0 {
|
||||
return
|
||||
stats, err := sys.GetStats()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// max requests per node is calculated as
|
||||
// total_ram / ram_per_request
|
||||
// ram_per_request is 4MiB * setDriveCount + 2 * 10MiB (default erasure block size)
|
||||
apiRequestsMaxPerNode = int(stats.TotalRAM / uint64(setDriveCount*readBlockSize+blockSizeV1*2))
|
||||
} else {
|
||||
apiRequestsMaxPerNode = cfg.APIRequestsMax
|
||||
if len(globalEndpoints.Hostnames()) > 0 {
|
||||
apiRequestsMaxPerNode /= len(globalEndpoints.Hostnames())
|
||||
}
|
||||
}
|
||||
|
||||
apiRequestsMax := cfg.APIRequestsMax
|
||||
if len(globalEndpoints.Hostnames()) > 0 {
|
||||
apiRequestsMax /= len(globalEndpoints.Hostnames())
|
||||
}
|
||||
|
||||
t.requestsPool = make(chan struct{}, apiRequestsMax)
|
||||
t.requestsPool = make(chan struct{}, apiRequestsMaxPerNode)
|
||||
t.requestsDeadline = cfg.APIRequestsDeadline
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user