Skip to content

Make Soroban metric batching code lock-free. - #5436

Merged
graydon merged 1 commit into
stellar:masterfrom
dmkozh:apply_metrics_no_sync
Sep 19, 2026
Merged

graydon merged 1 commit into
stellar:masterfrom
dmkozh:apply_metrics_no_sync

Conversation

@dmkozh

@dmkozh dmkozh commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Description

The previous attempt at batching Soroban metrics still had some locks and was overall more convoluted than it needs to be. With this change we simply give every thread its own metrics batch to write to, and then cleanly move the batches to the publish step for the merge and Medida export. This is slightly more plumbing, but as a result we get much more straightforward code.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

Copilot AI balanced review requested due to automatic review settings August 28, 2026 21:07
@dmkozh
dmkozh force-pushed the apply_metrics_no_sync branch from 716025f to 0ce3397 Compare August 28, 2026 21:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors Soroban metrics collection to use thread-local accumulators and publish merged results after ledger close.

Changes:

  • Introduces SorobanApplyMetrics and SorobanMetricsRegistry.
  • Plumbs accumulators through transaction and operation apply paths.
  • Merges worker metrics before Medida publication.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/transactions/TransactionFrameBase.h Extends apply interfaces with metrics.
src/transactions/TransactionFrame.h Updates transaction method declarations.
src/transactions/TransactionFrame.cpp Records metrics in supplied accumulators.
src/transactions/test/TransactionTestFrame.h Updates test wrapper interfaces.
src/transactions/test/TransactionTestFrame.cpp Supplies test-local accumulators.
src/transactions/RestoreFootprintOpFrame.h Updates restore-operation interfaces.
src/transactions/RestoreFootprintOpFrame.cpp Redirects restore metrics.
src/transactions/ParallelApplyUtils.h Extends parallel-state interfaces.
src/transactions/ParallelApplyUtils.cpp Passes metrics during pre-apply.
src/transactions/OperationFrame.h Extends operation apply interfaces.
src/transactions/OperationFrame.cpp Forwards operation metrics.
src/transactions/InvokeHostFunctionOpFrame.h Updates host-function interfaces.
src/transactions/InvokeHostFunctionOpFrame.cpp Accumulates host-function metrics locally.
src/transactions/FeeBumpTransactionFrame.h Updates fee-bump interfaces.
src/transactions/FeeBumpTransactionFrame.cpp Forwards metrics to inner transactions.
src/transactions/ExtendFootprintTTLOpFrame.h Updates TTL-extension interfaces.
src/transactions/ExtendFootprintTTLOpFrame.cpp Redirects TTL metrics.
src/test/fuzz/targets/TxFuzzTarget.cpp Supplies fuzz-local metrics.
src/main/AppConnector.h Exposes renamed metrics registry.
src/main/AppConnector.cpp Returns renamed registry type.
src/ledger/SorobanMetrics.h Defines accumulators and registry.
src/ledger/SorobanMetrics.cpp Implements merging and publication.
src/ledger/LedgerManagerImpl.h Extends ledger-apply metrics plumbing.
src/ledger/LedgerManagerImpl.cpp Collects, merges, and publishes metrics.
src/ledger/LedgerManager.h Updates ledger manager interfaces.
src/ledger/InMemorySorobanState.h Uses renamed registry type.
src/ledger/InMemorySorobanState.cpp Updates registry parameters.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/transactions/TransactionFrame.cpp Resolved
Comment thread src/transactions/TransactionFrame.cpp Resolved
Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
Comment thread src/ledger/SorobanMetrics.h Resolved
Copilot AI review requested due to automatic review settings August 28, 2026 21:12
@dmkozh
dmkozh force-pushed the apply_metrics_no_sync branch from 0ce3397 to 68520aa Compare August 28, 2026 21:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.

Suppressed comments (2)

src/transactions/TransactionFrame.cpp:2167

  • This timer no longer honors DISABLE_SOROBAN_METRICS_FOR_TESTING: the clock reads and vector append still run and the samples are published, even though this switch exists specifically to remove metric overhead from apply-load benchmarks. The previous BatchedTimerScope was also RAII, whereas the append at line 2198 is skipped when the exception handler below converts an apply exception into txINTERNAL_ERROR. Please make the local timer conditional and scope-based so disabled runs do no timing/allocation and exceptional applies retain their timer sample.
        auto applyStart = std::chrono::steady_clock::now();

src/ledger/LedgerManagerImpl.cpp:2632

  • This transaction timer now runs unconditionally, so DISABLE_SOROBAN_METRICS_FOR_TESTING still pays for two clock reads, vector growth, and later Medida publication per parallel transaction. That regresses the benchmark switch’s documented purpose and differs from the sequential apply timer, which still checks the flag. Guard both timing and sample insertion with config.DISABLE_SOROBAN_METRICS_FOR_TESTING.
        auto applyStart = std::chrono::steady_clock::now();

Comment thread src/ledger/LedgerManagerImpl.cpp Resolved
Copilot AI review requested due to automatic review settings August 28, 2026 22:30
@dmkozh
dmkozh force-pushed the apply_metrics_no_sync branch from 68520aa to 144c332 Compare August 28, 2026 22:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/ledger/LedgerManagerImpl.cpp:2682

  • This is a performance-focused change to the parallel apply hot path, but the PR provides no benchmark evidence that it improves throughput/latency without regression. CONTRIBUTING.md:56-60 requires such evidence for performance-impacting changes; please include representative before/after results, especially since the new per-cluster vector storage and merge may trade lock contention for allocation/cache costs.
    // Stages may contain a different number of clusters, so we ensure that
    // there is a corresponding metrics entry for each cluster.
    if (sorobanApplyMetricsPerThread.size() < stage.numClusters())
    {
        sorobanApplyMetricsPerThread.resize(stage.numClusters());

The previous attempt at batching Soroban metrics still had some locks and was overall more convoluted than it needs to be. With this change we simply give every thread its own metrics batch to write to, and then cleanly move the batches to the publish step for the merge and Medida export. This is slightly more plumbing, but as a result we get much more straightforward code.
Copilot AI review requested due to automatic review settings September 18, 2026 17:41
@dmkozh
dmkozh force-pushed the apply_metrics_no_sync branch from 144c332 to bb32c8a Compare September 18, 2026 17:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The performance-focused change lacks the repository-required comparison against master or release.

Review details

Suppressed comments (1)

src/ledger/LedgerManagerImpl.cpp:2683

  • This PR explicitly changes the hot apply path to improve performance, but the description provides no before/after measurements and leaves the performance-evidence checklist item unchecked. The repository's performance guidance requires comparison with the latest master or release for network-performance changes (performance-eval/performance-eval.md:3-5). Please attach representative parallel-Soroban throughput/CPU results and confirm there is no regression before merging.
    // Stages may contain a different number of clusters, so we ensure that
    // there is a corresponding metrics entry for each cluster.
    if (sorobanApplyMetricsPerThread.size() < stage.numClusters())
    {
        sorobanApplyMetricsPerThread.resize(stage.numClusters());
  • Files reviewed: 27/27 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@graydon
graydon added this pull request to the merge queue Sep 19, 2026
Merged via the queue into stellar:master with commit 5587daf Sep 19, 2026
75 of 78 checks passed
SirTyson added a commit to SirTyson/stellar-core that referenced this pull request Nov 9, 2026
Brings overlay-v2-shared up to date with master. The previous master
merge (b90d48e, stellar#5428) was recorded with master's tip 100cc38 missing
from its parents, so this merge used 100cc38 as its base (temporary
graft of b90d48e, removed afterwards).

Notable master changes brought in:
- Protocol 30: CURRENT_LEDGER_PROTOCOL_VERSION follows
  MAX_SUPPORTED_PROTOCOL_VERSION; CAP-0084 and CAP-0087 ungated, p29 and
  p30 Soroban hosts (stellar#5472, stellar#5478, stellar#5484, stellar#5483).
- Millisecond-resolution close times at protocol 30 (stellar#5423):
  ConsensusTime/ApplyTime types, STELLAR_VALUE_SIGNED_MS and
  STELLAR_VALUE_EMPTY_TX_SET_MS.
- Tx set validity hardening (stellar#5481), lower max message size in protocol
  29 (stellar#733), sub-second ledger edge-case fixes.
- Simplified ledger view hierarchy (stellar#5461); the overlay-only-mode
  sequence number skip now lives in TransactionFrame::checkValid.
- Banned accounts deprecated (CAP-0077 is active).
- Apply-path performance work (stellar#5402, stellar#5411, stellar#5414, stellar#5415, stellar#5418, stellar#5421,
  stellar#5436, stellar#5286), apply-load tx set construction mode (stellar#5448), --check-lcm
  (stellar#5435), v29.0.0 release merge.

Conflict resolution:
- Files overlay-v2-shared deleted and master modified (the C++ overlay,
  TransactionQueue, TransactionQueueTests, UpgradesTests, private/Horizon/RPC
  workflows): kept deleted. Master's changes to them are C++ overlay
  peer/flow-control logic, tx queue admission and tests for those.
- Herder: kept the Rust-overlay submission path (recvTransaction returns
  TxSubmitStatus) and dropped the deprecated `force` parameter as master did.
  triggerNextLedger keeps the prepared/built tx set path from the Rust
  mempool, now with ConsensusTime close times and master's apply-time
  close-time offset. The early tx set preparation path (prepareTxSet,
  buildTxSet, setupTriggerNextLedger) takes ConsensusTime. Kept master's
  mNominatedTxSetOverride test hook (applied before the tx set is cached in
  the Rust overlay) and the herder.txset.build timer (now timing
  buildTxSet). Dropped the banned-accounts setup and tx queue maintenance.
- AppConnector: dropped both ov2's maybeUpdateImmutableLedgerView and
  master's C++-overlay getOverlayThreadSnapshot.
- LoadGenerator: master's CachedTestAccountPtr with ov2's TxSubmitStatus.
- Tests: kept ov2's removal of tests that need the C++ overlay, standalone
  mode or the tx queue (standalone, manualclose, flooding, tx queue limits,
  far-future slot cleanup, herderExternalizesValuesWithProtocol, MAX_SAC_TPS,
  custom token, soroswap and noisy binary search apply-load tests). Added
  master's ms close time HerderTests and the non-canonical empty tx set test
  on ov2's Rust-overlay topologies. The tx set size test checks against
  overlay-v2's own tx set allowance. The sub-second
  getUpperBoundCloseTimeOffset test checks the offset directly, since there
  is no C++ tx queue admission. Tests that used CheckValidLedgerViewWrapper
  now use getLCLView().
- Cargo.lock: master's lockfile plus the overlay crate's packages,
  regenerated by cargo; semver-compatible duplicates take the newer
  version.
- Build: Makefile.am keeps the Rust overlay rules and adds tracy
  import-chrome; ci-build.sh keeps ASAN off and takes master's -g1.
- Needed to compile: PendingEnvelopes.cpp includes LedgerManager.h
  (master got it through the C++ OverlayManager.h); ov2's early-nomination
  and checkpoint-slot tests use ConsensusTime/ApplyTimeOffset; OverlayIPC
  tests take ledger views from the LedgerManager.
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.

3 participants