Skip to content

Commit

Permalink
bugfix: Added lock around block writes to reduce memory pressure
Browse files Browse the repository at this point in the history
Since downloader insert is an asynchronous process, writing thousands of
large blocks into the DB at the same time is very memory intensive.
Adding this lock will make sure that only one block is written at a time
and from the testing in the garden environment this has shown improved
performance in memory use while syncing
  • Loading branch information
gameofpointers committed Sep 12, 2023
1 parent 7d32a65 commit 8d8c4d2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Core struct {
appendQueue *lru.Cache
processingCache *lru.Cache

writeBlockLock sync.RWMutex

quit chan struct{} // core quit channel
}

Expand Down Expand Up @@ -352,6 +354,9 @@ func (c *Core) Stop() {

// WriteBlock write the block to the bodydb database
func (c *Core) WriteBlock(block *types.Block) {
c.writeBlockLock.Lock()
defer c.writeBlockLock.Unlock()

if c.sl.IsBlockHashABadHash(block.Hash()) {
return
}
Expand Down

0 comments on commit 8d8c4d2

Please sign in to comment.