Skip to content

Commit 5f2820b

Browse files
committed
RONDB-969: set MaxConcurrentReqs=GOMAXPROCS
1 parent 3f3df87 commit 5f2820b

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

storage/ndb/rest-server/rest-api-server/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ Currently, the REST API server only supports [Hopsworks API Keys](https://docs.h
195195
"REST": {
196196
"Enable": true,
197197
"ServerIP": "localhost",
198-
"ServerPort": 4406
198+
"ServerPort": 4406,
199+
"MaxConcurrentReqs": 0
199200
},
200201
"GRPC": {
201202
"Enable": true,
@@ -295,14 +296,16 @@ Currently, the REST API server only supports [Hopsworks API Keys](https://docs.h
295296

296297
- **OperationIDMaxSize:** Max length of operation ID. Default is 256 characters.
297298

298-
- **REST**
299+
- **REST**
299300

300-
- **Enable:** Enable/Disable REST Server Interface
301+
- **Enable:** Enable/Disable REST Server Interface
301302

302303
- **ServerIP:** Binds the REST server to this IP. The default value is *localhost*
303304

304305
- **ServerPort:** REST server port. The default port is *4406*
305306

307+
- **MaxConcurrentReqs:** Maximum number of concurrent requests the server will handle. The default value is *0* (auto mode). When set to *0*, the server automatically sets the limit to GOMAXPROCS (matching CPU resources). Set to a positive number to define a custom limit. This helps prevent overloading the server under high traffic.
308+
306309
- **GRPC**
307310

308311
- **Enable:** Enable/Disable GRPC Server Interface

storage/ndb/rest-server/rest-api-server/internal/config/init_defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func newWithDefaults() AllConfigs {
6565
Enable: true,
6666
ServerIP: "0.0.0.0",
6767
ServerPort: 4406,
68-
MaxConcurrentReqs: 0, // 0 = unlimited (default for backward compatibility)
68+
MaxConcurrentReqs: 0, // 0 = auto (set to GOMAXPROCS), >0 = user-defined limit
6969
},
7070
RonDB: RonDB{
7171
Mgmds: []Mgmd{

storage/ndb/rest-server/rest-api-server/internal/config/structs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type REST struct {
7777
Enable bool
7878
ServerIP string
7979
ServerPort uint16
80-
MaxConcurrentReqs uint32 // Maximum concurrent requests (0 = unlimited)
80+
MaxConcurrentReqs uint32 // Maximum concurrent requests (0 = auto/GOMAXPROCS, >0 = user-defined)
8181
}
8282

8383
func (g *REST) Validate() error {

storage/ndb/rest-server/rest-api-server/internal/servers/rest/server.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"fmt"
2525
"net/http"
2626
"os"
27+
"runtime"
2728
"strings"
2829
"syscall"
2930
"time"
@@ -117,9 +118,22 @@ func registerHandlers(router *gin.Engine, heap *heap.Heap, apiKeyCache apikey.Ca
117118
fvMeta *fsmeta.FeatureViewMetaDataCache, rdrsMetrics *metrics.RDRSMetrics) {
118119
router.Use(ErrorHandler)
119120

120-
// Apply concurrency limiter if configured (0 = unlimited, no limiter)
121+
// Apply concurrency limiter
122+
// 0 = auto (set to GOMAXPROCS), >0 = user-defined limit
121123
conf := config.GetAll()
122-
if conf.REST.MaxConcurrentReqs > 0 {
124+
if conf.REST.MaxConcurrentReqs == 0 {
125+
// Auto mode: use GOMAXPROCS
126+
var gomaxprocs int
127+
if conf.Internal.GOMAXPROCS > 0 {
128+
gomaxprocs = conf.Internal.GOMAXPROCS
129+
} else {
130+
gomaxprocs = runtime.GOMAXPROCS(0) // 0 means query current value without changing it
131+
}
132+
log.Infof("MaxConcurrentReqs set to auto mode: using GOMAXPROCS=%d", gomaxprocs)
133+
router.Use(middleware.ConcurrencyLimiterWithQueue(uint32(gomaxprocs)))
134+
} else {
135+
// User-defined limit
136+
log.Infof("MaxConcurrentReqs set to %d", conf.REST.MaxConcurrentReqs)
123137
router.Use(middleware.ConcurrencyLimiterWithQueue(conf.REST.MaxConcurrentReqs))
124138
}
125139

0 commit comments

Comments
 (0)