@@ -255,54 +255,50 @@ func (cfg *LimitConfig) Apply(c LimitConfig) {
255
255
256
256
// Scale scales up a limit configuration.
257
257
// memory is the amount of memory that the stack is allowed to consume,
258
- // for a full it's recommended to use 1/8 of the installed system memory.
258
+ // for a dedicated node it's recommended to use 1/8 of the installed system memory.
259
259
// If memory is smaller than 128 MB, the base configuration will be used.
260
260
func (cfg * ScalingLimitConfig ) Scale (memory int64 , numFD int ) LimitConfig {
261
- var scaleFactor int
262
- if memory > 128 << 20 {
263
- scaleFactor = int ((memory - 128 << 20 ) >> 20 )
264
- }
265
261
lc := LimitConfig {
266
- System : scale (cfg .SystemBaseLimit , cfg .SystemLimitIncrease , scaleFactor , numFD ),
267
- Transient : scale (cfg .TransientBaseLimit , cfg .TransientLimitIncrease , scaleFactor , numFD ),
268
- AllowlistedSystem : scale (cfg .AllowlistedSystemBaseLimit , cfg .AllowlistedSystemLimitIncrease , scaleFactor , numFD ),
269
- AllowlistedTransient : scale (cfg .AllowlistedTransientBaseLimit , cfg .AllowlistedTransientLimitIncrease , scaleFactor , numFD ),
270
- ServiceDefault : scale (cfg .ServiceBaseLimit , cfg .ServiceLimitIncrease , scaleFactor , numFD ),
271
- ServicePeerDefault : scale (cfg .ServicePeerBaseLimit , cfg .ServicePeerLimitIncrease , scaleFactor , numFD ),
272
- ProtocolDefault : scale (cfg .ProtocolBaseLimit , cfg .ProtocolLimitIncrease , scaleFactor , numFD ),
273
- ProtocolPeerDefault : scale (cfg .ProtocolPeerBaseLimit , cfg .ProtocolPeerLimitIncrease , scaleFactor , numFD ),
274
- PeerDefault : scale (cfg .PeerBaseLimit , cfg .PeerLimitIncrease , scaleFactor , numFD ),
275
- Conn : scale (cfg .ConnBaseLimit , cfg .ConnLimitIncrease , scaleFactor , numFD ),
276
- Stream : scale (cfg .StreamBaseLimit , cfg .ConnLimitIncrease , scaleFactor , numFD ),
262
+ System : scale (cfg .SystemBaseLimit , cfg .SystemLimitIncrease , memory , numFD ),
263
+ Transient : scale (cfg .TransientBaseLimit , cfg .TransientLimitIncrease , memory , numFD ),
264
+ AllowlistedSystem : scale (cfg .AllowlistedSystemBaseLimit , cfg .AllowlistedSystemLimitIncrease , memory , numFD ),
265
+ AllowlistedTransient : scale (cfg .AllowlistedTransientBaseLimit , cfg .AllowlistedTransientLimitIncrease , memory , numFD ),
266
+ ServiceDefault : scale (cfg .ServiceBaseLimit , cfg .ServiceLimitIncrease , memory , numFD ),
267
+ ServicePeerDefault : scale (cfg .ServicePeerBaseLimit , cfg .ServicePeerLimitIncrease , memory , numFD ),
268
+ ProtocolDefault : scale (cfg .ProtocolBaseLimit , cfg .ProtocolLimitIncrease , memory , numFD ),
269
+ ProtocolPeerDefault : scale (cfg .ProtocolPeerBaseLimit , cfg .ProtocolPeerLimitIncrease , memory , numFD ),
270
+ PeerDefault : scale (cfg .PeerBaseLimit , cfg .PeerLimitIncrease , memory , numFD ),
271
+ Conn : scale (cfg .ConnBaseLimit , cfg .ConnLimitIncrease , memory , numFD ),
272
+ Stream : scale (cfg .StreamBaseLimit , cfg .ConnLimitIncrease , memory , numFD ),
277
273
}
278
274
if cfg .ServiceLimits != nil {
279
275
lc .Service = make (map [string ]BaseLimit )
280
276
for svc , l := range cfg .ServiceLimits {
281
- lc .Service [svc ] = scale (l .BaseLimit , l .BaseLimitIncrease , scaleFactor , numFD )
277
+ lc .Service [svc ] = scale (l .BaseLimit , l .BaseLimitIncrease , memory , numFD )
282
278
}
283
279
}
284
280
if cfg .ProtocolLimits != nil {
285
281
lc .Protocol = make (map [protocol.ID ]BaseLimit )
286
282
for proto , l := range cfg .ProtocolLimits {
287
- lc .Protocol [proto ] = scale (l .BaseLimit , l .BaseLimitIncrease , scaleFactor , numFD )
283
+ lc .Protocol [proto ] = scale (l .BaseLimit , l .BaseLimitIncrease , memory , numFD )
288
284
}
289
285
}
290
286
if cfg .PeerLimits != nil {
291
287
lc .Peer = make (map [peer.ID ]BaseLimit )
292
288
for p , l := range cfg .PeerLimits {
293
- lc .Peer [p ] = scale (l .BaseLimit , l .BaseLimitIncrease , scaleFactor , numFD )
289
+ lc .Peer [p ] = scale (l .BaseLimit , l .BaseLimitIncrease , memory , numFD )
294
290
}
295
291
}
296
292
if cfg .ServicePeerLimits != nil {
297
293
lc .ServicePeer = make (map [string ]BaseLimit )
298
294
for svc , l := range cfg .ServicePeerLimits {
299
- lc .ServicePeer [svc ] = scale (l .BaseLimit , l .BaseLimitIncrease , scaleFactor , numFD )
295
+ lc .ServicePeer [svc ] = scale (l .BaseLimit , l .BaseLimitIncrease , memory , numFD )
300
296
}
301
297
}
302
298
if cfg .ProtocolPeerLimits != nil {
303
299
lc .ProtocolPeer = make (map [protocol.ID ]BaseLimit )
304
300
for p , l := range cfg .ProtocolPeerLimits {
305
- lc .ProtocolPeer [p ] = scale (l .BaseLimit , l .BaseLimitIncrease , scaleFactor , numFD )
301
+ lc .ProtocolPeer [p ] = scale (l .BaseLimit , l .BaseLimitIncrease , memory , numFD )
306
302
}
307
303
}
308
304
return lc
@@ -315,20 +311,30 @@ func (cfg *ScalingLimitConfig) AutoScale() LimitConfig {
315
311
)
316
312
}
317
313
318
- // factor is the number of MBs above the minimum (128 MB)
319
- func scale (base BaseLimit , inc BaseLimitIncrease , factor int , numFD int ) BaseLimit {
314
+ func scale (base BaseLimit , inc BaseLimitIncrease , memory int64 , numFD int ) BaseLimit {
315
+ // mebibytesAvailable represents how many MiBs we're allowed to use. Used to
316
+ // scale the limits. If this is below 128MiB we set it to 0 to just use the
317
+ // base amounts.
318
+ var mebibytesAvailable int
319
+ if memory > 128 << 20 {
320
+ mebibytesAvailable = int ((memory ) >> 20 )
321
+ }
320
322
l := BaseLimit {
321
- StreamsInbound : base .StreamsInbound + (inc .StreamsInbound * factor )>> 10 ,
322
- StreamsOutbound : base .StreamsOutbound + (inc .StreamsOutbound * factor )>> 10 ,
323
- Streams : base .Streams + (inc .Streams * factor )>> 10 ,
324
- ConnsInbound : base .ConnsInbound + (inc .ConnsInbound * factor )>> 10 ,
325
- ConnsOutbound : base .ConnsOutbound + (inc .ConnsOutbound * factor )>> 10 ,
326
- Conns : base .Conns + (inc .Conns * factor )>> 10 ,
327
- Memory : base .Memory + (inc .Memory * int64 (factor ))>> 10 ,
323
+ StreamsInbound : base .StreamsInbound + (inc .StreamsInbound * mebibytesAvailable )>> 10 ,
324
+ StreamsOutbound : base .StreamsOutbound + (inc .StreamsOutbound * mebibytesAvailable )>> 10 ,
325
+ Streams : base .Streams + (inc .Streams * mebibytesAvailable )>> 10 ,
326
+ ConnsInbound : base .ConnsInbound + (inc .ConnsInbound * mebibytesAvailable )>> 10 ,
327
+ ConnsOutbound : base .ConnsOutbound + (inc .ConnsOutbound * mebibytesAvailable )>> 10 ,
328
+ Conns : base .Conns + (inc .Conns * mebibytesAvailable )>> 10 ,
329
+ Memory : base .Memory + (inc .Memory * int64 (mebibytesAvailable ))>> 10 ,
328
330
FD : base .FD ,
329
331
}
330
332
if inc .FDFraction > 0 && numFD > 0 {
331
333
l .FD = int (inc .FDFraction * float64 (numFD ))
334
+ if l .FD < base .FD {
335
+ // Use at least the base amount
336
+ l .FD = base .FD
337
+ }
332
338
}
333
339
return l
334
340
}
0 commit comments