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

core: TxPool simplifications and improvements #46

Merged
merged 3 commits into from
Mar 7, 2018
Merged

Conversation

jmank88
Copy link
Contributor

@jmank88 jmank88 commented Mar 7, 2018

This change simplifies and improves some things surrounding core.TxPool

for _, tx := range pool.queue[addr].Flatten() {
list := pool.queue[addr]
list.txs.ensureCache()
for _, tx := range list.txs.cache {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't alloc a slice just to iterate.

core/tx_pool.go Outdated
@@ -544,10 +540,12 @@ func (pool *TxPool) local() map[common.Address]types.Transactions {
txs := make(map[common.Address]types.Transactions)
for addr := range pool.locals.accounts {
if pending := pool.pending[addr]; pending != nil {
txs[addr] = append(txs[addr], pending.Flatten()...)
pending.txs.ensureCache()
txs[addr] = append(txs[addr], pending.txs.cache...)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't alloc a slice just to copy.

from, _ := types.Sender(pool.signer, tx) // already validated
dirty[from] = struct{}{}
}
var errs []error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't alloc. Errors should be rare.

pool.promoteExecutable(addr, list)
}
pool.finishPromotion()
}
Copy link
Contributor Author

@jmank88 jmank88 Mar 7, 2018

Choose a reason for hiding this comment

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

Separate method to directly iterate, rather than a nil special case below which allocs a slice to iterate over.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The diff below looks messy, but it was just broken into two helper methods.

@@ -1054,7 +1063,8 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {

// Drop all transactions if they are less than the overflow
if size := uint64(list.Len()); size <= drop {
for _, tx := range list.Flatten() {
list.txs.ensureCache()
for _, tx := range list.txs.cache {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't alloc a slice just to iterate.

@@ -341,15 +341,6 @@ func (pool *TxPool) loop() {
}
}

// lockedReset is a wrapper around reset to allow calling it in a thread safe
// manner. This method is only ever used in the tester!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to test file.

defer pool.mu.RUnlock()

return new(big.Int).Set(pool.gasPrice)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused.

Pending() map[common.Address]types.Transactions

// PendingList is like Pending, but only txs.
PendingList() types.Transactions
Copy link
Contributor Author

@jmank88 jmank88 Mar 7, 2018

Choose a reason for hiding this comment

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

Some callers were just copying map values from Pending into their own slices. This helper does it directly, to avoid extra copying into an intermediate map.

@@ -101,7 +101,10 @@ type txPool interface {

// Pending should return pending transactions.
// The slice should be modifiable by the caller.
Pending() (map[common.Address]types.Transactions, error)
Pending() map[common.Address]types.Transactions
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both impls always returned nil error.

@jmank88
Copy link
Contributor Author

jmank88 commented Mar 7, 2018

With this branch I was able to do ~400tps smoothly for 5 minutes:

Block #3655 has 808 transactions - 1520388514
Block #3656 has 2683 transactions - 1520388519
Block #3657 has 2483 transactions - 1520388524
Block #3658 has 1784 transactions - 1520388529
Block #3659 has 1039 transactions - 1520388534
Block #3660 has 1686 transactions - 1520388539
Block #3661 has 2433 transactions - 1520388544
Block #3662 has 2167 transactions - 1520388549
Block #3663 has 1741 transactions - 1520388554
Block #3664 has 2018 transactions - 1520388559
Block #3665 has 2090 transactions - 1520388564
Block #3666 has 2068 transactions - 1520388569
Block #3667 has 1995 transactions - 1520388574
Block #3668 has 1998 transactions - 1520388579
Block #3669 has 2027 transactions - 1520388584
Block #3670 has 2336 transactions - 1520388589
Block #3671 has 1634 transactions - 1520388594
Block #3672 has 1730 transactions - 1520388599
Block #3673 has 2185 transactions - 1520388604
Block #3674 has 2056 transactions - 1520388609
Block #3675 has 2047 transactions - 1520388614
Block #3676 has 1996 transactions - 1520388619
Block #3677 has 1874 transactions - 1520388624
Block #3678 has 1777 transactions - 1520388629
Block #3679 has 2261 transactions - 1520388634
Block #3680 has 1991 transactions - 1520388639
Block #3681 has 1882 transactions - 1520388644
Block #3682 has 1962 transactions - 1520388649
Block #3683 has 2090 transactions - 1520388654
Block #3684 has 1795 transactions - 1520388659
Block #3685 has 2080 transactions - 1520388664
Block #3686 has 2285 transactions - 1520388669
Block #3687 has 1946 transactions - 1520388674
Block #3688 has 1817 transactions - 1520388679
Block #3689 has 2053 transactions - 1520388684
Block #3690 has 1942 transactions - 1520388689
Block #3691 has 1861 transactions - 1520388694
Block #3692 has 2095 transactions - 1520388699
Block #3693 has 2002 transactions - 1520388704
Block #3694 has 634 transactions - 1520388709
Block #3695 has 2729 transactions - 1520388714
Block #3696 has 2856 transactions - 1520388719
Block #3697 has 2194 transactions - 1520388724
Block #3698 has 1549 transactions - 1520388729
Block #3700 has 3229 transactions - 1520388739
Block #3701 has 3229 transactions - 1520388744
Block #3702 has 2376 transactions - 1520388749
Block #3703 has 3536 transactions - 1520388757
Block #3704 has 1556 transactions - 1520388762
Block #3705 has 1007 transactions - 1520388767
Block #3706 has 1661 transactions - 1520388772
Block #3707 has 2403 transactions - 1520388777
Block #3708 has 2223 transactions - 1520388782
Block #3709 has 2326 transactions - 1520388787
Block #3710 has 1707 transactions - 1520388792
Block #3711 has 2206 transactions - 1520388797
Block #3712 has 1891 transactions - 1520388802
Block #3713 has 1675 transactions - 1520388807
Block #3714 has 1376 transactions - 1520388812
Total txs: 119080
Time(s): 303
Tx/s: 393

@jmank88
Copy link
Contributor Author

jmank88 commented Mar 7, 2018

Attempted 500 tps for 5 minutes. Ingestion rate was ~472tps, but processing was a bit slower, at 419tps. CPU nearly maxed as well. Blocks are larger, but also slower.

Block #3754 has 2193 transactions - 1520389012
Block #3755 has 3654 transactions - 1520389017
Block #3756 has 3577 transactions - 1520389024
Block #3757 has 4128 transactions - 1520389031
Block #3760 has 7027 transactions - 1520389049
Block #3761 has 9567 transactions - 1520389064
Block #3762 has 9630 transactions - 1520389084
Block #3763 has 9732 transactions - 1520389109
Block #3764 has 2399 transactions - 1520389133
Block #3765 has 10017 transactions - 1520389155
Block #3766 has 10022 transactions - 1520389171
Block #3767 has 7626 transactions - 1520389194
Block #3768 has 10028 transactions - 1520389210
Block #3769 has 10033 transactions - 1520389243
Block #3771 has 7673 transactions - 1520389282
Block #3772 has 10030 transactions - 1520389304
Block #3773 has 10034 transactions - 1520389321
Block #3774 has 2890 transactions - 1520389336
Block #3775 has 6396 transactions - 1520389344
Block #3776 has 7494 transactions - 1520389351
Total txs: 144150
Time(s): 344
Tx/s: 419

@@ -112,7 +111,7 @@ func (journal *txJournal) insert(tx *types.Transaction) error {

// rotate regenerates the transaction journal based on the current contents of
// the transaction pool.
func (journal *txJournal) rotate(all map[common.Address]types.Transactions) error {
func (journal *txJournal) rotate(acts int, all types.Transactions) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did they have the map in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't see an obvious reason. May have just wound up that way from incremental changes, or maybe it was meant to be more readable

@jmank88
Copy link
Contributor Author

jmank88 commented Mar 7, 2018

By freeing up some more resources, I was able to do 5m@500tps:

Block #4522 has 2200 transactions - 1520427056
Block #4523 has 3505 transactions - 1520427061
Block #4524 has 2935 transactions - 1520427066
Block #4525 has 2340 transactions - 1520427071
Block #4526 has 5887 transactions - 1520427080
Block #4527 has 2906 transactions - 1520427086
Block #4528 has 1474 transactions - 1520427091
Block #4529 has 1522 transactions - 1520427096
Block #4530 has 2763 transactions - 1520427101
Block #4532 has 4118 transactions - 1520427111
Block #4533 has 4826 transactions - 1520427116
Block #4534 has 3531 transactions - 1520427122
Block #4535 has 2801 transactions - 1520427128
Block #4536 has 4773 transactions - 1520427137
Block #4537 has 2366 transactions - 1520427142
Block #4538 has 4960 transactions - 1520427152
Block #4539 has 3197 transactions - 1520427159
Block #4540 has 4297 transactions - 1520427167
Block #4541 has 6407 transactions - 1520427180
Block #4542 has 5900 transactions - 1520427192
Block #4543 has 4200 transactions - 1520427200
Block #4544 has 4499 transactions - 1520427209
Block #4545 has 2464 transactions - 1520427214
Block #4546 has 1098 transactions - 1520427219
Block #4547 has 1493 transactions - 1520427224
Block #4548 has 6004 transactions - 1520427232
Block #4549 has 6145 transactions - 1520427244
Block #4550 has 8053 transactions - 1520427260
Block #4551 has 5943 transactions - 1520427272
Block #4552 has 7041 transactions - 1520427286
Block #4553 has 4117 transactions - 1520427294
Block #4554 has 2785 transactions - 1520427300
Block #4555 has 2116 transactions - 1520427305
Block #4556 has 1734 transactions - 1520427310
Block #4557 has 1800 transactions - 1520427315
Block #4558 has 6581 transactions - 1520427324
Block #4559 has 6010 transactions - 1520427337
Total txs: 144791
Time(s): 286
Tx/s: 506

@jmank88
Copy link
Contributor Author

jmank88 commented Mar 7, 2018

Aiming for 5m@550 - Ingested at 534, processed at 455. Big slow blocks.

Block #4720 has 53 transactions - 1520428634
Block #4721 has 2762 transactions - 1520428639
Block #4722 has 5458 transactions - 1520428644
Block #4723 has 5289 transactions - 1520428654
Block #4724 has 10010 transactions - 1520428673
Block #4725 has 10015 transactions - 1520428693
Block #4726 has 10020 transactions - 1520428728
Block #4727 has 10024 transactions - 1520428744
Block #4728 has 10029 transactions - 1520428765
Block #4729 has 8734 transactions - 1520428779
Block #4731 has 4060 transactions - 1520428801
Block #4732 has 9948 transactions - 1520428814
Block #4733 has 10028 transactions - 1520428838
Block #4734 has 10033 transactions - 1520428871
Block #4735 has 10038 transactions - 1520428886
Block #4738 has 10023 transactions - 1520428930
Block #4739 has 10028 transactions - 1520428938
Block #4740 has 10033 transactions - 1520428953
Block #4741 has 4115 transactions - 1520428964
Block #4742 has 5270 transactions - 1520428970
Block #4744 has 6500 transactions - 1520428986
Total txs: 162470
Time(s): 357
Tx/s: 455

if err := pool.journal.load(pool.AddLocal); err != nil {
if err := pool.journal.load(func(txs types.Transactions) []error {
// No need to lock since we're still setting up.
return pool.addTxsLocked(txs, !pool.config.NoLocals)
Copy link
Contributor Author

@jmank88 jmank88 Mar 7, 2018

Choose a reason for hiding this comment

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

Don't lock during setup. Add batches instead of one at a time and promoting executables on each one.

@jmank88 jmank88 merged commit f22e281 into master Mar 7, 2018
@jmank88 jmank88 deleted the perf-tx-pool branch March 7, 2018 16:37
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.

None yet

2 participants