Skip to content

Commit

Permalink
Increase disk I/O semaphore limit (#6449)
Browse files Browse the repository at this point in the history
This updates `dios` to range up to 50% of the core count on a system
with more than 32 CPU cores, otherwise obeying the 4 to 16 limit.

Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
derekcollison authored Feb 4, 2025
2 parents be97bc9 + 9a18fc0 commit abc1697
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -10007,8 +10007,14 @@ var dios chan struct{}
// golang.org's semaphore seemed a bit heavy.
func init() {
// Limit ourselves to a sensible number of blocking I/O calls. Range between
// 4-16 concurrent disk I/Os based on the number of CPU cores available.
nIO := min(16, max(4, runtime.GOMAXPROCS(-1)))
// 4-16 concurrent disk I/Os based on CPU cores, or 50% of cores if greater
// than 32 cores.
mp := runtime.GOMAXPROCS(-1)
nIO := min(16, max(4, mp))
if mp > 32 {
// If the system has more than 32 cores then limit dios to 50% of cores.
nIO = max(16, min(mp, mp/2))
}
dios = make(chan struct{}, nIO)
// Fill it up to start.
for i := 0; i < nIO; i++ {
Expand Down

0 comments on commit abc1697

Please sign in to comment.