Minimal implementation of anti-intersection delay to wait before getdata
This commit is contained in:
parent
1dfe98cf1f
commit
6558245a32
|
@ -3,6 +3,7 @@
|
||||||
import base64
|
import base64
|
||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
import random
|
import random
|
||||||
import select
|
import select
|
||||||
import socket
|
import socket
|
||||||
|
@ -64,6 +65,7 @@ class Connection(threading.Thread):
|
||||||
|
|
||||||
self.last_message_received = time.time()
|
self.last_message_received = time.time()
|
||||||
self.last_message_sent = time.time()
|
self.last_message_sent = time.time()
|
||||||
|
self.wait_until = 0
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.s is None:
|
if self.s is None:
|
||||||
|
@ -429,7 +431,14 @@ class Connection(threading.Thread):
|
||||||
def _request_objects(self):
|
def _request_objects(self):
|
||||||
if self.vectors_to_get and len(self.vectors_requested) < 100:
|
if self.vectors_to_get and len(self.vectors_requested) < 100:
|
||||||
self.vectors_to_get.difference_update(shared.objects.keys())
|
self.vectors_to_get.difference_update(shared.objects.keys())
|
||||||
if self.vectors_to_get:
|
if not self.wait_until:
|
||||||
|
nodes_count = (
|
||||||
|
len(shared.node_pool) + len(shared.unchecked_node_pool))
|
||||||
|
logging.debug('Nodes count is %i', nodes_count)
|
||||||
|
delay = math.ceil(math.log(nodes_count + 2, 20)) * 5.2
|
||||||
|
self.wait_until = time.time() + delay
|
||||||
|
logging.debug('Skip sending getdata for %.2fs', delay)
|
||||||
|
if self.vectors_to_get and self.wait_until < time.time():
|
||||||
logging.info(
|
logging.info(
|
||||||
'Queued %s vectors to get', len(self.vectors_to_get))
|
'Queued %s vectors to get', len(self.vectors_to_get))
|
||||||
if len(self.vectors_to_get) > 64:
|
if len(self.vectors_to_get) > 64:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user