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

eth, p2p: send txs and new blocks to peers in parallel #147

Merged
merged 1 commit into from
Apr 29, 2018
Merged

Conversation

jmank88
Copy link
Contributor

@jmank88 jmank88 commented Apr 29, 2018

Broadcast Tx, send new block, and send new block hash were all executing sends to multiple peers in serial and re-encoding identical message payloads each time. Now all three spawn goroutines so we 1) send in parallel, 2) share a single encoded payload, and 3) don't block the caller. With 1 &2 we're both doing less work (and allocating less memory), and doing it concurrently, which should be much faster in general, and prevent slow peers from affecting fast peers. With 3, we free up the caller to return almost immediately, which could otherwise e.g. clog up the rest of the event subscriber system.

Related to #138

@rkononov
Copy link
Contributor

rkononov commented Apr 29, 2018

LGTM, @benbjohnson could you please review too?

@treeder
Copy link
Collaborator

treeder commented Apr 29, 2018

I'll merge for now, but @benbjohnson would still be good to get your review.

@treeder treeder merged commit 7ced3bd into master Apr 29, 2018
@jmank88 jmank88 deleted the par-send branch April 29, 2018 23:59
@@ -201,37 +203,72 @@ func (p *peer) SendTransactions(txs types.Transactions) error {
return err
}

// parallelPeers coordinates efficient parallel sends.
type parallelPeers []*peer
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think adding a new type adds much value. It seems easier and clearer just to add new functions.

e.g.

SendTransactionParallel(peers []*peer, tx *types.Transaction) 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.

}(p)
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Firing off goroutines without managing their lifecycle makes me nervous but it's done quite a lot in the go-ethereum code base. That seems like a bigger discussion though and outside the scope of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Though if you dig in to (p *MsgPipeRW) WriteMsg(), it's not so bad. These will block ...until the receiver has consumed the message payload., and will cancel out and exit gracefully if the peer connection is closed.

It would be better if we kept track of them - we can always emit some kind of metrics.

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.

4 participants