Skip to content

Commit 1817398

Browse files
committed
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.
1 parent 96ac26e commit 1817398

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

test/functional/test_framework/mininode.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,7 @@ def __init__(self, dstaddr, dstport, rpc, callback, net="regtest", services=NODE
16541654
self.dstaddr = dstaddr
16551655
self.dstport = dstport
16561656
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
1657+
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
16571658
self.sendbuf = b""
16581659
self.recvbuf = b""
16591660
self.ver_send = 209
@@ -1792,7 +1793,14 @@ def send_message(self, message, pushbuf=False):
17921793
tmsg += h[:4]
17931794
tmsg += data
17941795
with mininode_lock:
1795-
self.sendbuf += tmsg
1796+
if (len(self.sendbuf) == 0 and not pushbuf):
1797+
try:
1798+
sent = self.send(tmsg)
1799+
self.sendbuf = tmsg[sent:]
1800+
except BlockingIOError:
1801+
self.sendbuf = tmsg
1802+
else:
1803+
self.sendbuf += tmsg
17961804
self.last_sent = time.time()
17971805

17981806
def got_message(self, message):

0 commit comments

Comments
 (0)