Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve transaction inclusion when block is nearly full #111

Closed
wants to merge 2 commits into from

Conversation

jstarry
Copy link

@jstarry jstarry commented Mar 6, 2024

Problem

When a leader prepares a transaction batch for execution, it needs to check if the accounts for each transaction can be locked and it needs to check if the transaction will fit within the cost tracker limits. Currently the banking stage consumer first selects transactions that can fit within remaining block space and THEN locks the accounts. If any account locking fails, the consumer is needlessly holding onto reserved block space until the consumer finishes processing that batch of transactions.

Summary of Changes

  • Updated process_and_record_transactions_with_pre_results to first lock as many transactions as possible in a batch, then reserve block space, and then finally unlock any transactions that didn't fit in the block.

Fixes solana-labs#34825

@jstarry jstarry force-pushed the fix/improve-block-inclusion branch from 3d2d30a to 5891408 Compare March 7, 2024 07:15
@jstarry jstarry requested review from apfitzge and tao-stones March 7, 2024 07:20
tao-stones
tao-stones previously approved these changes Mar 7, 2024
Copy link

@tao-stones tao-stones left a comment

Choose a reason for hiding this comment

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

looks great!

Copy link

@apfitzge apfitzge left a comment

Choose a reason for hiding this comment

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

Happy with the change, some minor suggestions/follow-up and a question about performance impact. If you observe no significant impact on performance, this seems like a great change that can help the legacy banking stage

core/src/banking_stage/consumer.rs Show resolved Hide resolved
@@ -470,33 +470,40 @@ impl Consumer {
chunk_offset: usize,
pre_results: impl Iterator<Item = Result<(), TransactionError>>,
) -> ProcessTransactionBatchOutput {
// Lock accounts so that other threads cannot encode transactions that
Copy link

Choose a reason for hiding this comment

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

Follow-up(?): seems these 3 operations are essentially creating a batch (lock, cost model, unlock).
Do you think this makes sense to create a function for?

})
));
// Unlock accounts for any transactions that were not selected for the block;
batch.unlock_failures(
Copy link

Choose a reason for hiding this comment

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

I doubt it outweighs the benefits of this, but did you measure the impact of this change on performance when we have many small batches? Maybe run bench-tps as a sanity check on this, using --num-conflict-groups 1

We're grabbing the account locks lock 3 times instead of twice per batch now, so could lead to more contention for that lock.

Copy link

Choose a reason for hiding this comment

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

banking-bench will be better probably to highlight any differences.

Copy link
Author

Choose a reason for hiding this comment

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

I ran the banking-bench with write lock contention and this change brings in a pretty consistent perf hit that I can't really debug. After discussing with @sakridge I think it's best to just skip this change to avoid the backport risk to v1.17 and wait until v1.18 and the new scheduler..

cargo run --release --manifest-path banking-bench/Cargo.toml -- --write-lock-contention full --iterations 100

before

[total_sent: 115200, base_tx_count: 36864, txs_processed: 140306, txs_landed: 103442, total_us: 6721644, tx_total_us: 6620406]
{'name': 'banking_bench_total', 'median': '17138.66'}
{'name': 'banking_bench_tx_total', 'median': '17400.75'}
{'name': 'banking_bench_success_tx_total', 'median': '15389.39'}

after

[total_sent: 115200, base_tx_count: 36864, txs_processed: 142769, txs_landed: 105905, total_us: 7230649, tx_total_us: 7135781]
{'name': 'banking_bench_total', 'median': '15932.18'}
{'name': 'banking_bench_tx_total', 'median': '16143.99'}
{'name': 'banking_bench_success_tx_total', 'median': '14646.68'}

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.8%. Comparing base (adefcbb) to head (31a0c6d).
Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##           master     #111     +/-   ##
=========================================
- Coverage    81.8%    81.8%   -0.1%     
=========================================
  Files         838      838             
  Lines      225913   226002     +89     
=========================================
+ Hits       184935   184967     +32     
- Misses      40978    41035     +57     

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.

Transaction locking fails prematurely due to cost tracker constraints
5 participants