Skip to content

Commit 03b6188

Browse files
committed
Rate limit number of DB writes per memory account
1 parent e3abff9 commit 03b6188

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

geyser/handler_memory.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (h *MemoryAccountWithDataUpdateHandler) backupWorker(ctx context.Context) e
108108
for {
109109
select {
110110
case <-time.After(h.backupWorkerInterval):
111-
var addresses []string
111+
addresses := []string{"F9RMtR2mjk7aRiLLjYGajvAeyPqn4BNDPy49amgCmyZh", "Cmd2UP1qDMMUvdLVN1Q2TxsqcdE2otneZHWbTsrq6cF7", "9tR1Q8GL5dUhNBMN1dENsiVVNCtvcUUhiFV8YtNPc2gg"}
112112
for vm := range h.observableVmAccounts {
113113
log := log.WithField("vm", vm)
114114

@@ -348,7 +348,7 @@ func (h *MemoryAccountWithDataUpdateHandler) onStateObserved(ctx context.Context
348348
// Update the DB with the delta changes to the memory account state
349349
var wg sync.WaitGroup
350350
var cachedMemoryAccountStateUpdateMu sync.Mutex
351-
for _, dbUpdate := range dbUpdates {
351+
for i, dbUpdate := range dbUpdates {
352352
wg.Add(1)
353353

354354
go func(dbUpdate *cachedVirtualAccount) {
@@ -384,6 +384,10 @@ func (h *MemoryAccountWithDataUpdateHandler) onStateObserved(ctx context.Context
384384
log.WithError(err).Warn("failure updating db record")
385385
}
386386
}(dbUpdate)
387+
388+
if i%250 == 0 {
389+
time.Sleep(time.Second / 4)
390+
}
387391
}
388392
wg.Wait()
389393

0 commit comments

Comments
 (0)