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

miner: avoid unnecessary work #15883

Merged
merged 1 commit into from
Jan 15, 2018
Merged

miner: avoid unnecessary work #15883

merged 1 commit into from
Jan 15, 2018

Conversation

mcdee
Copy link
Contributor

@mcdee mcdee commented Jan 14, 2018

At current the miner worker's commitTransactions() attempts to add every pending transaction from a transaction set in to the block. If a node has hundreds or thousands of pending transactions then the block quickly fills up but the loop continues to set up and run each of the remaining transactions even though they are guaranteed to fail.

This patch adds a condition to the loop such that if the remaining gas in the pool falls below the base transaction cost i.e. is out of space then it breaks out of the loop, saving CPU and memory.

@karalabe
Copy link
Member

Could you somehow measure the performance gain/loss?

The miner inclusion code works per sender, not per transaction (since if a transaction is skipped, none of the subsequent ones from the same account can be executed either). As such, the inclusion logic is linear in accounts, not transactions.

I don't see any problem in including this optimization in itself, but I'd really like to see some benchmarks put in place to put a number on them. My hunch is that it's negligible, but if not, I'd like to see the impact.

@mcdee
Copy link
Contributor Author

mcdee commented Jan 15, 2018

I can give you some anecdotal information. Running on my local node (which is pretty beefy) and leaving out the optimisation I let it run for an while to obtain a decent number of transactions in the pool and see:

INFO [01-15|10:26:03] Txset has 10754 transactions
INFO [01-15|10:26:17] Committed 245 transactions in 13.947120023s
INFO [01-15|10:26:21] Txset has 10669 transactions
INFO [01-15|10:26:35] Committed 199 transactions in 14.111734951s
INFO [01-15|10:31:43] Txset has 10790 transactions
INFO [01-15|10:31:58] Committed 206 transactions in 14.567871696s
INFO [01-15|10:32:03] Txset has 10753 transactions
INFO [01-15|10:32:17] Committed 107 transactions in 13.824062347s
INFO [01-15|10:32:23] Txset has 10719 transactions
INFO [01-15|10:32:36] Committed 124 transactions in 13.221693639s
INFO [01-15|10:32:42] Txset has 10673 transactions
INFO [01-15|10:32:56] Committed 137 transactions in 14.15466732s
INFO [01-15|10:33:01] Txset has 10672 transactions
INFO [01-15|10:33:27] Committed 192 transactions in 25.325009953s
INFO [01-15|10:33:31] Txset has 10662 transactions
INFO [01-15|10:33:43] Committed 157 transactions in 12.369058898s

With the optimisation as per this PR I see:

INFO [01-15|10:37:32] Txset has 9907 transactions
INFO [01-15|10:37:35] Committed 232 transactions in 2.269386231s
INFO [01-15|10:37:57] Txset has 9828 transactions
INFO [01-15|10:37:58] Committed 160 transactions in 1.404357208s
INFO [01-15|10:38:24] Txset has 9824 transactions
INFO [01-15|10:38:25] Committed 185 transactions in 867.471752ms
INFO [01-15|10:38:42] Txset has 9810 transactions
INFO [01-15|10:38:43] Committed 193 transactions in 958.709958ms
INFO [01-15|10:40:18] Txset has 10472 transactions
INFO [01-15|10:40:19] Committed 268 transactions in 1.000916276s         
INFO [01-15|10:40:49] Txset has 10295 transactions
INFO [01-15|10:40:51] Committed 309 transactions in 1.911952839s
INFO [01-15|10:41:06] Txset has 10338 transactions
INFO [01-15|10:41:09] Committed 241 transactions in 2.948498107s
INFO [01-15|10:41:27] Txset has 10302 transactions
INFO [01-15|10:41:28] Committed 246 transactions in 1.142915064s
INFO [01-15|10:43:10] Txset has 9795 transactions
INFO [01-15|10:43:12] Committed 163 transactions in 2.093603477s          

@mcdee
Copy link
Contributor Author

mcdee commented Jan 15, 2018

And for the records the spec of the machine that these tests were run on:

CPU: i7-4770 @ 3.4GHz
Memory: 32GB
Storage: dual 240GB SSDs running software RAID-0

@karalabe
Copy link
Member

Whoah

@karalabe karalabe added this to the 1.8.0 milestone Jan 15, 2018
@karalabe karalabe merged commit 18a7d31 into ethereum:master Jan 15, 2018
mariameda pushed a commit to NiluPlatform/go-nilu that referenced this pull request Aug 23, 2018
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