Skip to content

Commit

Permalink
mininode: add an optimistic write and disable nagle
Browse files Browse the repository at this point in the history
Summary:
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.

Backport of Core PR11323

Co-authored-by: Jason B. Cox <[email protected]>

Test Plan: test_runner.py --extended

Reviewers: deadalnix, schancel, #bitcoin_abc

Reviewed By: deadalnix, schancel, #bitcoin_abc

Subscribers: teamcity

Differential Revision: https://reviews.bitcoinabc.org/D1962
  • Loading branch information
theuni authored and jasonbcox committed Oct 25, 2018
1 parent b514f80 commit bf55554
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/functional/test_framework/mininode.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,7 @@ def __init__(self, dstaddr, dstport, rpc, callback, net="regtest", services=NODE
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
Expand Down Expand Up @@ -1719,7 +1720,14 @@ def send_message(self, message, pushbuf=False):
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):
Expand Down

0 comments on commit bf55554

Please sign in to comment.