aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/mininode.py
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2017-09-13 13:24:38 -0400
committerCory Fields <cory-nospam-@coryfields.com>2017-09-13 13:31:44 -0400
commit1817398b397afebcc857c40a16d201c84878cb89 (patch)
tree6a16153e0fe885496c31844e40079a1adebe43f3 /test/functional/test_framework/mininode.py
parent96ac26e56627f0c24213fcd3a1cce9fc95f1f661 (diff)
mininode: add an optimistic write and disable nagle
Because the poll/select loop may pause for 100msec before actually doing a send, and we have no way to force the loop awake, try sending from the calling thread if the queue is empty. Also, disable nagle as all sends should be either full messages or unfinished sends. This shaves an average of ~1 minute or so off of my accumulated runtime, and 10-15 seconds off of actual runtime.
Diffstat (limited to 'test/functional/test_framework/mininode.py')
-rwxr-xr-xtest/functional/test_framework/mininode.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py
index 2607b9b07c..03b7c6e50c 100755
--- a/test/functional/test_framework/mininode.py
+++ b/test/functional/test_framework/mininode.py
@@ -1654,6 +1654,7 @@ class NodeConn(asyncore.dispatcher):
self.dstaddr = dstaddr
self.dstport = dstport
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
self.sendbuf = b""
self.recvbuf = b""
self.ver_send = 209
@@ -1792,7 +1793,14 @@ class NodeConn(asyncore.dispatcher):
tmsg += h[:4]
tmsg += data
with mininode_lock:
- self.sendbuf += tmsg
+ if (len(self.sendbuf) == 0 and not pushbuf):
+ try:
+ sent = self.send(tmsg)
+ self.sendbuf = tmsg[sent:]
+ except BlockingIOError:
+ self.sendbuf = tmsg
+ else:
+ self.sendbuf += tmsg
self.last_sent = time.time()
def got_message(self, message):