Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #704 from carver/limit-block-import-batch
Browse files Browse the repository at this point in the history
Add a maximum batch size for regular sync imports
  • Loading branch information
carver authored Jun 7, 2019
2 parents b2f5af1 + ce93aea commit 953cfb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions trinity/sync/full/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
from trinity.sync.full.constants import (
HEADER_QUEUE_SIZE_TARGET,
BLOCK_QUEUE_SIZE_TARGET,
BLOCK_IMPORT_QUEUE_SIZE_TARGET,
)
from trinity._utils.datastructures import (
BaseOrderedTaskPreparation,
Expand Down Expand Up @@ -1040,8 +1041,10 @@ async def _import_ready_blocks(self) -> None:
while self.is_operational:
timer = Timer()

# wait for block bodies to become ready for execution
completed_headers = await self.wait(self._block_import_tracker.ready_tasks())
# This tracker waits for all prerequisites to be complete, and returns headers in
# order, so that each header's parent is already persisted.
get_ready_coro = self._block_import_tracker.ready_tasks(BLOCK_IMPORT_QUEUE_SIZE_TARGET)
completed_headers = await self.wait(get_ready_coro)

if self._block_import_tracker.has_ready_tasks():
# Even after clearing out a big batch, there is no available capacity, so
Expand Down
7 changes: 7 additions & 0 deletions trinity/sync/full/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@
# How many blocks to persist at a time
# Only need a few seconds of buffer on the DB write side.
BLOCK_QUEUE_SIZE_TARGET = 1000

# How many blocks to import at a time
# Only need a few seconds of buffer on the DB side
# This is specifically for blocks where execution happens locally.
# So each block might have a pretty significant execution time, on
# the order of seconds.
BLOCK_IMPORT_QUEUE_SIZE_TARGET = 10

0 comments on commit 953cfb3

Please sign in to comment.