Skip to content

Commit

Permalink
fix: map memory overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryTong65 committed Jul 19, 2024
1 parent ded2966 commit 0ac2741
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (

LoopSleepTime = 10 * time.Millisecond
WaitSleepTime = 100 * time.Millisecond
MapSleepTime = 5 * time.Second
MapSleepTime = 3 * time.Second
BSCPauseTime = 3 * time.Second

ETHPauseTime = 90 * time.Second
Expand Down Expand Up @@ -96,16 +96,16 @@ func NewBlockIndexer(
}

func (b *BlockIndexer) StartConcurrentSync() {
if len(b.blocks) > 1000 {
logging.Logger.Infof("Map size:%d exceeds 1000. Pausing for a while before starting workers.", len(b.blocks))
time.Sleep(MapSleepTime)
}
var wg sync.WaitGroup
for i := 0; i < b.config.ConcurrencyLimit; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for {
if len(b.blocks) > 1000 {
logging.Logger.Infof("Map size:%d exceeds 1000. Pausing for a while before starting workers.", len(b.blocks))
time.Sleep(MapSleepTime)
}
var blockID uint64
b.blockHeightLock.Lock()
blockID = b.indexBlockHeight
Expand All @@ -121,7 +121,7 @@ func (b *BlockIndexer) StartConcurrentSync() {
}
break
}
logging.Logger.Infof("Successfully fetched and incremented block ID to %d", blockID)
logging.Logger.Infof("Successfully fetched and incremented block ID to %d, Map size:%d", blockID, len(b.blocks))
}
}()
}
Expand All @@ -133,12 +133,12 @@ func (b *BlockIndexer) StartLoop() {
// nextBlockID defines the block number (BSC)
var nextBlockID uint64
var err error
for retries := 0; retries < DBRetryTimes; retries++ {
for {
nextBlockID, err = b.getNextBlockNum()
if err == nil {
break
}
logging.Logger.Errorf("Failed to get next block number: %v. Retrying... (%d/3)", err, retries+1)
logging.Logger.Errorf("Failed to get next block number: %v.", err)
time.Sleep(time.Second * 2) // Wait for 2 seconds before retrying
}
if err != nil {
Expand Down

0 comments on commit 0ac2741

Please sign in to comment.