-
Notifications
You must be signed in to change notification settings - Fork 1.7k
A last bunch of txqueue performance optimizations #9024
Conversation
miner/src/pool/queue.rs
Outdated
|
||
let removed = self.pool.write().cull(None, state_readiness); | ||
let mut removed = 0; | ||
let senders: Vec<Address> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a set? Otherwise we may cull the same sender more than once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the senders to be ordered by priority (so that we cull best senders first - more probability that it will have any effect on the queue), best_transactions
in the pool (That we take the senders from) contains exactly one transaction per sender.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth adding a comment here to that effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize best_transactions
only had the best tx from each sender 👍.
ethcore/src/miner/pool_client.rs
Outdated
|
||
const MAX_NONCE_CACHE_SIZE: usize = 4096; | ||
const EXPECTED_NONCE_CACHE_SIZE: usize = 2048; | ||
type NoncesCache = (RwLock<HashMap<Address, U256>>, usize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably create a struct for this at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Needs a merge/rebase from master |
@ascjones Rebased. |
Needs another rebase now that #9026 was merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good. How have the efficacy of these optimisations been measured? Presumably these are the ones you were testing with Fred's node on mainnet?
@ascjones yes, I was running the node and observing 3 things:
All three things are obviously related to each other, long pauses are usually caused by high CPU load in some place, which in turn leads to peer timeouts and drops. But overall chunkig the senders causes each chunk to be processed in roughly 200ms, and in between we can easily import incoming transactions or propagate the pending ones. |
Thanks @tomusdrw. I see that node has now taken the top spot! Build needs fixing though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I fixed the compilation error but the tests are failing now on the merged wasm test.
@niklasad1 caused by me hijacking @tomusdrw 's branch to fix the build (see above). |
No worries, it's my fault. I've didn't try to compile after merge. |
* Clear cache only when block is enacted. * Add tracing for cull. * Cull split. * Cull after creating pending block. * Add constant, remove sync::read tracing. * Reset debug. * Remove excessive tracing. * Use struct for NonceCache. * Fix build * Remove warnings. * Fix build again.
* parity-version: bump beta to 1.11.6 * scripts: remove md5 checksums (#8884) * Add support for --chain tobalaba * Convert indents to tabs :) * Fixes for misbehavior reporting in AuthorityRound (#8998) * aura: only report after checking for repeated skipped primaries * aura: refactor duplicate code for getting epoch validator set * aura: verify_external: report on validator set contract instance * aura: use correct validator set epoch number when reporting * aura: use epoch set when verifying blocks * aura: report skipped primaries when generating seal * aura: handle immediate transitions * aura: don't report skipped steps from genesis to first block * aura: fix reporting test * aura: refactor duplicate code to handle immediate_transitions * aura: let reporting fail on verify_block_basic * aura: add comment about possible failure of reporting * Only return error log for rustls (#9025) * Transaction Pool improvements (#8470) * Don't use ethereum_types in transaction pool. * Hide internal insertion_id. * Fix tests. * Review grumbles. * Improve should_replace on NonceAndGasPrice (#8980) * Additional tests for NonceAndGasPrice::should_replace. * Fix should_replace in the distinct sender case. * Use natural priority ordering to simplify should_replace. * Minimal effective gas price in the queue (#8934) * Minimal effective gas price. * Fix naming, add test * Fix minimal entry score and add test. * Fix worst_transaction. * Remove effective gas price threshold. * Don't leak gas_price decisions out of Scoring. * Never drop local transactions from different senders. (#9002) * Recently rejected cache for transaction queue (#9005) * Store recently rejected transactions. * Don't cache AlreadyImported rejections. * Make the size of transaction verification queue dependent on pool size. * Add a test for recently rejected. * Fix logging for recently rejected. * Make rejection cache smaller. * obsolete test removed * obsolete test removed * Construct cache with_capacity. * Optimize pending transactions filter (#9026) * rpc: return unordered transactions in pending transactions filter * ethcore: use LruCache for nonce cache Only clear the nonce cache when a block is retracted * Revert "ethcore: use LruCache for nonce cache" This reverts commit b382c19. * Use only cached nonces when computing pending hashes. * Give filters their own locks, so that they don't block one another. * Fix pending transaction count if not sealing. * Clear cache only when block is enacted. * Fix RPC tests. * Address review comments. * A last bunch of txqueue performance optimizations (#9024) * Clear cache only when block is enacted. * Add tracing for cull. * Cull split. * Cull after creating pending block. * Add constant, remove sync::read tracing. * Reset debug. * Remove excessive tracing. * Use struct for NonceCache. * Fix build * Remove warnings. * Fix build again. * miner: add missing macro use for trace_time * ci: remove md5 merge leftovers
…rp_sync_on_light_client * 'master' of https://github.com/paritytech/parity: Fixes for misbehavior reporting in AuthorityRound (openethereum#8998) A last bunch of txqueue performance optimizations (openethereum#9024) reduce number of constraints for triedb types (openethereum#9043) bump fs-swap to 0.2.3 so it is compatible with osx 10.11 again (openethereum#9050) Recursive test (openethereum#9042) Introduce more optional features in ethcore (openethereum#9020) Update ETSC bootnodes (openethereum#9038) Optimize pending transactions filter (openethereum#9026) eip160/eip161 spec: u64 -> BlockNumber (openethereum#9044)
Nonce cache size dependent on the pool size. Currently it was hardcoded to 4k entires, now it depends on the size of the pool (but never less than 4k). I've noticed that the cache was very often saturated when we run with large pool size.
Optimize order of
cull
andupdate_sealing
inminer::chain_new_blocks
. Sincecull
can take significant amount of time (seconds, for large pools) it's better to first attempt to construct pending block. We only need couple (hundreds) of best transactions andReadiness
will make sure that they are not stale anyway. After pending block is created we attempt to clean up the pool. This should allow miners to start mining on the new block much earlier and reduce orphan rate because of that.Split
cull
into chunks. To prevent acquiringwrite()
lock of the queue for long time we are cleaning up the queue in chunks (1024 senders each chunk). This allows other threads to jump in between.