-
Notifications
You must be signed in to change notification settings - Fork 209
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
Reduce pings and dns lookups #993
base: next
Are you sure you want to change the base?
Conversation
That sorting can cause Pings to be sent. Now sorting is only done when receiving a new noderef and at random intervals. This should make the node less visible in DNS requests and Pings (more typical pattern instead of requesting all peers at the same time). Also it fixes the startup time regression by not doing a ping in the PeerNode constructor. The sorting result in the constructor was overwritten anyway …
Next thing I like to have is custom DNS server & DNS over HTTPS via dnsjava, to secure the DNS requests. |
@@ -788,9 +779,17 @@ private boolean parseARK(SimpleFieldSet fs, boolean onStartup, boolean forDiffNo | |||
*/ | |||
@Override | |||
public synchronized Peer getPeer() { | |||
if (detectedPeer == null && !nominalPeer.isEmpty()) { | |||
sortNominalPeer(); | |||
detectedPeer = nominalPeer.get(0); |
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.
The shortToString
includes the detectedPeer
and should updated accordingly.
This should either call updateShortToString
after setting detectedPeer
, or a to be introduced setter that does that. Alternatively, we should get rid of the the cached shortToString and just compute it in shortToString()
.
@@ -56,23 +56,24 @@ public void run() { | |||
private void realRun() { | |||
PeerNode[] nodes = node.getPeers().myPeers(); | |||
long now = System.currentTimeMillis(); | |||
if((now - lastLogTime) > 1000) { | |||
if(logMINOR) | |||
if((now - lastLogTime) > 100) { |
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.
Can we move this (and the entire currentTimeMillis dance) into the if (logMINOR) { ... }
? We don't need the result if minor logging is disabled.
pn.maybeUpdateHandshakeIPs(false); | ||
} | ||
// check a randomly chosen node to avoid sending bursts of DNS requests | ||
PeerNode pn = nodes[node.getFastWeakRandom().nextInt(nodes.length)]; |
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.
This approach turns the peer node DNS resolving into the Coupon collector's problem. For 80 peer nodes, the expected number of tries before all are hit is 397 (taking roughly 8 minutes), and it takes 563 attempts (~10 minutes) before 95% probability is reached - even assuming the peer node list is static, which it is not. This may not be desirable.
This can be resolved by ignoring connected nodes prior to random selection.
Only sort the list nominalPeer when necessary.
That sorting can cause Pings to be sent. Now sorting is only done when
receiving a new noderef and at random intervals.
This should make the node less visible in DNS requests and Pings (more
typical pattern instead of requesting all peers at the same time).
Also it fixes the startup time regression by not doing a ping in the
PeerNode constructor.
The sorting result in the constructor was overwritten anyway …