Skip to content

Commit

Permalink
CR: enable app limiter separately with EnableAppTxBacklogRateLimiting
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Nov 3, 2023
1 parent 7d32f6e commit a66abbf
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
3 changes: 3 additions & 0 deletions config/localTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ type Local struct {
// TxBacklogRateLimitingCongestionRatio determines the backlog filling threashold in percents at which app limiter kicks in
TxBacklogRateLimitingCongestionPct int `version[32]:"50"`

// EnableAppTxBacklogRateLimiting controls if an app rate limiter should be attached to the tx backlog enqueue process
EnableAppTxBacklogRateLimiting bool `version[32]:"true"`

// EnableTxBacklogRateLimiting controls if a rate limiter and congestion manager should be attached to the tx backlog enqueue process
// if enabled, the over-all TXBacklog Size will be larger by MAX_PEERS*TxBacklogReservedCapacityPerPeer
EnableTxBacklogRateLimiting bool `version[27]:"false" version[30]:"true"`
Expand Down
1 change: 1 addition & 0 deletions config/local_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var defaultLocal = Local{
EnableAccountUpdatesStats: false,
EnableAgreementReporting: false,
EnableAgreementTimeMetrics: false,
EnableAppTxBacklogRateLimiting: true,
EnableAssembleStats: false,
EnableBlockService: false,
EnableBlockServiceFallbackToArchiver: false,
Expand Down
24 changes: 13 additions & 11 deletions data/txHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,23 @@ func MakeTxHandler(opts TxHandlerOpts) (*TxHandler, error) {
handler.txCanonicalCache = makeDigestCache(int(opts.Config.TxIncomingFilterMaxSize))
}

if opts.Config.EnableTxBacklogRateLimiting {
if opts.Config.EnableTxBacklogRateLimiting || opts.Config.EnableAppTxBacklogRateLimiting {
if opts.Config.TxBacklogRateLimitingCongestionPct > 100 || opts.Config.TxBacklogRateLimitingCongestionPct < 0 {
return nil, fmt.Errorf("invalid value for TxBacklogRateLimitingCongestionPct: %d", opts.Config.TxBacklogRateLimitingCongestionPct)

Check warning on line 186 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L186

Added line #L186 was not covered by tests
}
if opts.Config.EnableAppTxBacklogRateLimiting && opts.Config.TxBacklogAppTxRateLimiterMaxSize == 0 {
return nil, fmt.Errorf("invalid value for TxBacklogAppTxRateLimiterMaxSize: %d. App rate limiter enabled with zero size", opts.Config.TxBacklogAppTxRateLimiterMaxSize)

Check warning on line 189 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L189

Added line #L189 was not covered by tests
}
handler.backlogCongestionThreshold = float64(opts.Config.TxBacklogRateLimitingCongestionPct) / 100

rateLimiter := util.NewElasticRateLimiter(
txBacklogSize,
opts.Config.TxBacklogReservedCapacityPerPeer,
time.Duration(opts.Config.TxBacklogServiceRateWindowSeconds)*time.Second,
txBacklogDroppedCongestionManagement,
)
handler.erl = rateLimiter

if opts.Config.TxBacklogAppTxRateLimiterMaxSize > 0 {
if opts.Config.EnableTxBacklogRateLimiting {
handler.erl = util.NewElasticRateLimiter(
txBacklogSize,
opts.Config.TxBacklogReservedCapacityPerPeer,
time.Duration(opts.Config.TxBacklogServiceRateWindowSeconds)*time.Second,
txBacklogDroppedCongestionManagement,
)
}
if opts.Config.EnableAppTxBacklogRateLimiting {
handler.appLimiter = makeAppRateLimiter(
opts.Config.TxBacklogAppTxRateLimiterMaxSize,
uint64(opts.Config.TxBacklogAppTxPerSecondRate),
Expand Down
33 changes: 29 additions & 4 deletions data/txHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2507,9 +2507,9 @@ func TestTxHandlerRestartWithBacklogAndTxPool(t *testing.T) { //nolint:parallelt
}
}

// check ERL and AppRateLimiter are either both enabled
// check ERL and AppRateLimiter enablement with separate config values,
// and the app limiter kicks in after congestion.
func TestTxHandlerAppRateLimiterERLBothEnabled(t *testing.T) {
func TestTxHandlerAppRateLimiterERLEnabled(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

Expand All @@ -2519,7 +2519,6 @@ func TestTxHandlerAppRateLimiterERLBothEnabled(t *testing.T) {
log.SetLevel(logging.Panic)

cfg := config.GetDefaultLocal()
cfg.EnableTxBacklogRateLimiting = true
cfg.TxBacklogAppTxRateLimiterMaxSize = 100
cfg.TxBacklogServiceRateWindowSeconds = 1
cfg.TxBacklogAppTxPerSecondRate = 3
Expand All @@ -2531,11 +2530,37 @@ func TestTxHandlerAppRateLimiterERLBothEnabled(t *testing.T) {
defer ledger.Close()

l := ledger

func() {
cfg.EnableTxBacklogRateLimiting = false
cfg.EnableAppTxBacklogRateLimiting = false
handler, err := makeTestTxHandler(l, cfg)
require.NoError(t, err)
defer handler.txVerificationPool.Shutdown()
defer close(handler.streamVerifierDropped)

require.Nil(t, handler.erl)
require.Nil(t, handler.appLimiter)
}()

func() {
cfg.EnableTxBacklogRateLimiting = true
cfg.EnableAppTxBacklogRateLimiting = false
handler, err := makeTestTxHandler(l, cfg)
require.NoError(t, err)
defer handler.txVerificationPool.Shutdown()
defer close(handler.streamVerifierDropped)

require.NotNil(t, handler.erl)
require.Nil(t, handler.appLimiter)
}()

cfg.EnableTxBacklogRateLimiting = true
cfg.EnableAppTxBacklogRateLimiting = true
handler, err := makeTestTxHandler(l, cfg)
require.NoError(t, err)
defer handler.txVerificationPool.Shutdown()
defer close(handler.streamVerifierDropped)

require.NotNil(t, handler.erl)
require.NotNil(t, handler.appLimiter)

Expand Down
1 change: 1 addition & 0 deletions installer/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"EnableAccountUpdatesStats": false,
"EnableAgreementReporting": false,
"EnableAgreementTimeMetrics": false,
"EnableAppTxBacklogRateLimiting": true,
"EnableAssembleStats": false,
"EnableBlockService": false,
"EnableBlockServiceFallbackToArchiver": false,
Expand Down
1 change: 1 addition & 0 deletions test/testdata/configs/config-v32.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"EnableAccountUpdatesStats": false,
"EnableAgreementReporting": false,
"EnableAgreementTimeMetrics": false,
"EnableAppTxBacklogRateLimiting": true,
"EnableAssembleStats": false,
"EnableBlockService": false,
"EnableBlockServiceFallbackToArchiver": false,
Expand Down

0 comments on commit a66abbf

Please sign in to comment.