Skip to content

optimize blockchain subsystem scanning with threaded loading and parallel tx fetch#186

Open
abdevil05 wants to merge 2 commits intoBeldex-Coin:devfrom
abdevil05:scan-optimization
Open

optimize blockchain subsystem scanning with threaded loading and parallel tx fetch#186
abdevil05 wants to merge 2 commits intoBeldex-Coin:devfrom
abdevil05:scan-optimization

Conversation

@abdevil05
Copy link
Copy Markdown

Purpose

  • Improve performance of blockchain subsystem scanning (MNL and BNS)
  • Reduce total scan time during node startup and resync
  • Introduce parallelism and better resource utilization

Core Changes

  • Refactored load_missing_blocks_into_beldex_subsystems()
  • Added parameters:
    • const std::atomic* abort
    • bool use_threaded_load
  • Enables controlled execution and optional threaded mode

Threaded Block Loading (Pipeline Execution)

  • Loader thread preloads block chunks from DB
  • Main thread processes blocks into subsystems
  • Introduced block_load_context with bounded queue (MAX_QUEUE_SIZE)
  • Used std::mutex and std::condition_variable for synchronization
  • Overlaps I/O (block fetching) with computation (processing)
  • Reduces idle CPU time and improves throughput

Parallel Transaction Fetching

  • Replaced sequential transaction loading with threadpool-based parallel fetching
  • Each transaction in a block is fetched concurrently using tools::threadpool
  • prevents excessive memory usage and improves stability

Improved Logging and Metrics

  • Added detailed performance metrics:
    • blocks per second
    • bytes per second
  • timing breakdown (block loading, MNL, BNS)
  • Periodic logging (~10 seconds) for better visibility during long scan

Periodic State Persistence

  • Introduced periodic MNL state storage (~5 minute interval)
  • Reduces risk of losing progress during long-running scan

Performance Impact

  • Reduced scanning time due to:
    • parallel transaction fetching
    • pipelined block loading
  • Improved CPU utilization and I/O efficiency
  • Better scalability for large chains

Testing Performed

  • Full blockchain rescan
  • Partial rescan from mid-height
  • Threaded vs non-threaded execution
  • Abort during execution
  • High transaction volume scenarios

Summary

  • Converts scanning from a sequential bottleneck into a parallel, pipelined system
  • Results in faster scans, improved performance, and better reliability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant