Skip to content

Commit

Permalink
single or multi threaded block cache filling
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Sep 24, 2024
1 parent 3705aba commit 756a8bb
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,24 @@ trait ExtraIndexerBase extends Actor with Stash with ScorexLogging {
if (height % 1000 == 0) blockCache.keySet.filter(_ < height).map(blockCache.remove)
if (readingUpTo - height < 300 && chainHeight - height > 1000) {
readingUpTo = math.min(height + 1001, chainHeight)
val blockNums = height + 1 to readingUpTo
Future {
blockNums.foreach { blockNum =>
history.bestBlockTransactionsAt(blockNum).map(blockCache.put(blockNum, _))

if(height < history.fullBlockHeight - 1000) {
val blockNums = height + 1 to readingUpTo by 250
blockNums.zip(blockNums.tail).map { range => // ranges of 250 blocks for each thread to read
Future {
(range._1 until range._2).foreach { blockNum =>
history.bestBlockTransactionsAt(blockNum).map(blockCache.put(blockNum, _))
}
}(context.dispatcher)
}
}(context.dispatcher)
} else {
val blockNums = height + 1 to readingUpTo
Future {
blockNums.foreach { blockNum =>
history.bestBlockTransactionsAt(blockNum).map(blockCache.put(blockNum, _))
}
}(context.dispatcher)
}
}
txs
}
Expand Down

0 comments on commit 756a8bb

Please sign in to comment.