p2p/pex: Connect to peers from a seed node immediately#2115
Conversation
This is to reduce wait times when initially connecting. This still runs checks such as whether you still want additional peers. A test case has been created, which fails if this change is not included.
Codecov Report
@@ Coverage Diff @@
## develop #2115 +/- ##
===========================================
- Coverage 62.37% 62.36% -0.02%
===========================================
Files 215 215
Lines 17388 17383 -5
===========================================
- Hits 10846 10841 -5
- Misses 5653 5655 +2
+ Partials 889 887 -2
|
Ideally, you should update p2p pex spec https://github.com/tendermint/tendermint/blob/develop/docs/spec/reactors/pex/pex.md |
xla
left a comment
There was a problem hiding this comment.
👍
🍡
Some minor improvements and I think we can be more efficient with the seed lookup.
CHANGELOG_PENDING.md
Outdated
| - only process one block at a time to avoid starving | ||
| - [crypto] Switch hkdfchachapoly1305 to xchachapoly1305 | ||
| - [common] bit array functions which take in another parameter are now thread safe | ||
| - [p2p] \#2093 begin connecting to peers as soon a seed node provides them to you |
There was a problem hiding this comment.
Let's create a markdown link to the issue and have it at the end.
There was a problem hiding this comment.
Not sure what you mean by "have it at the end". Do you mean make this a bug fix?
There was a problem hiding this comment.
Sorry I was ambiguous. Make the issue reference an actual link and have it at the end of the line, like this:
[p2p] begin connecting to peers as soon a seed node provides them to you ([#2093](https://github.com/tendermint/tendermint/issues/2093))
p2p/pex/pex_reactor_test.go
Outdated
|
|
||
| // Creates a seed which knows about the provided addresses / source address pairs. | ||
| // Starting and stopping the seed is left to the caller | ||
| func createSeed(dir string, id int, knownAddrs, srcAddrs []*p2p.NetAddress) *p2p.Switch { |
There was a problem hiding this comment.
We should make clear this is for testing purposes with a test prefix to avoid collision.
p2p/pex/pex_reactor_test.go
Outdated
|
|
||
| // Creates a peer which knows about the provided seed. | ||
| // Starting and stopping the peer is left to the caller | ||
| func createPeerWithSeed(dir string, id int, seed *p2p.Switch) *p2p.Switch { |
p2p/pex/pex_reactor.go
Outdated
|
|
||
| // If this address came from a seed node, try to connect to it without waiting. | ||
| // TODO: Change this to an O(log(N)) check on a sorted seedAddr list | ||
| seedAddrs, _ := p2p.NewNetAddressStrings(r.config.Seeds) |
There was a problem hiding this comment.
As seeds are not changing throughout the lifecycle of the process wouldn't it make sense to create a lookup (map[NetAddress]struct{}) once and use that instead.
There was a problem hiding this comment.
I'll change it to this for now, but on further thought I'm worried that the constant overhead of a hash function may make this less efficient in the expected case of a few seeds. But this is definitely on the order of things we can optimize post launch!
There was a problem hiding this comment.
Which hash function are you referring to?
There was a problem hiding this comment.
the internal hash function which will be used in the hashmap. (Namely its memhash here on 64 bit systems: https://golang.org/src/runtime/hash64.go)
There was a problem hiding this comment.
I don't think this is something we need to optimise for, even post-launch.
There was a problem hiding this comment.
Just ran the golang source runtime benchmarks. Slightly skewed speeds on my system, since it has the very nice hardware AES hash :)
BenchmarkHash5-8 200000000 9.12 ns/op 548.11 MB/s
BenchmarkHash16-8 200000000 9.59 ns/op 1668.44 MB/s
BenchmarkHash64-8 100000000 13.4 ns/op 4777.66 MB/s
BenchmarkHash1024-8 20000000 76.0 ns/op 13467.29 MB/s
BenchmarkHash65536-8 300000 4340 ns/op 15097.94 MB/s
For a small number of seeds, a linear scan would probably be faster. Would it be worth benchmarking this, or should I just switch to a hashmap for better asymptotics, and we can optimize this later?
There was a problem hiding this comment.
Sorry didn't see your comment. Okay, I'll just switch to a hashmap!
There was a problem hiding this comment.
I kept this as a linear scan due to that seeming more readable to me + that being reusable in dialseeds. If you'd prefer a map for readability, I can definitely switch to that :)
This is to reduce wait times when initially connecting. This still runs checks
such as whether you still want additional peers.
A test case has been created, which fails if this change is not included.
This is to reduce wait times when initially connecting. This still runs checks
such as whether you still want additional peers.
A test case has been created, which fails if this change is not included.
Closes #2093