Skip to content

Commit

Permalink
Increase disk I/O semaphore limit
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
neilalexander committed Feb 5, 2025
1 parent ba1b74b commit 8420b75
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"net"
"os"
"path/filepath"
"runtime"
"slices"
"sort"
"strings"
Expand Down Expand Up @@ -9553,8 +9554,15 @@ var dios chan struct{}
// Used to setup our simplistic counting semaphore using buffered channels.
// golang.org's semaphore seemed a bit heavy.
func init() {
// Limit ourselves to a max of 4 blocking IO calls.
const nIO = 4
// Limit ourselves to a sensible number of blocking I/O calls. Range between
// 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 8420b75

Please sign in to comment.