Skip to content

Commit 292c9cc

Browse files
committed
reduce the frequency of new request attempts, they are expensive when the discovered history is large.
1 parent 933d78a commit 292c9cc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/mesh/agents/state/history/HistorySynchronizer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { RequestMsg, ResponseMsg, CancelRequestMsg } from './HistoryProvider';
1717

1818
const MaxRequestsPerRemote = 2;
1919
const MaxPendingOps = 1024;
20+
const MinRequestedOps = 128;
2021

2122
const RequestTimeout = 32;
2223
const LiteralArrivalTimeout = 16;
@@ -205,12 +206,16 @@ class HistorySynchronizer {
205206

206207
this.controlLog.debug('\n'+this.logPrefix+'\nAttempting new request...');
207208

208-
if (this.discoveredHistory.contents.size === 0) {
209-
209+
if (this.discoveredHistory.contents.size === 0) {
210210
this.controlLog.debug('\n'+this.logPrefix+'\nThere is nothing to request.');
211211
return;
212212
}
213213

214+
if (this.requestedOps.contents.size > MinRequestedOps) {
215+
this.controlLog.debug('\n'+this.logPrefix+'\nDelaying request, too many pending ops.');
216+
return;
217+
}
218+
214219
if (this.stateLog.level <= LogLevel.DEBUG) {
215220

216221
let debugInfo = '\n'+this.logPrefix+'\nState info before attempt:\n';

0 commit comments

Comments
 (0)