Skip to content

Commit 9fe1a65

Browse files
committed
examples/bench: Fix client to use TCP_NODELAY and end messages with b'\n'
1 parent 48a6b18 commit 9fe1a65

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

examples/bench/echoclient.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Copied with minimal modifications from curio
22
# https://github.com/dabeaz/curio
33

4-
from concurrent.futures import ProcessPoolExecutor
54

65
import argparse
7-
from socket import *
86
import time
9-
import sys
7+
8+
from concurrent.futures import ProcessPoolExecutor
9+
from socket import *
10+
1011

1112
if __name__ == '__main__':
1213
parser = argparse.ArgumentParser()
@@ -34,14 +35,20 @@
3435

3536
MSGSIZE = args.msize
3637

37-
msg = b'x'*MSGSIZE
38+
msg = b'x'*(MSGSIZE - 1) + b'\n'
3839

3940
def run_test(n):
4041
print('Sending', NMESSAGES, 'messages')
4142
if unix:
4243
sock = socket(AF_UNIX, SOCK_STREAM)
4344
else:
4445
sock = socket(AF_INET, SOCK_STREAM)
46+
47+
try:
48+
sock.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
49+
except (OSError, NameError):
50+
pass
51+
4552
sock.connect(addr)
4653
while n > 0:
4754
sock.sendall(msg)

0 commit comments

Comments
 (0)