Commit 6cc2aaf0 authored by Yury Selivanov's avatar Yury Selivanov

Add new benchmark type -- readline

parent a244696c
...@@ -40,6 +40,8 @@ if __name__ == '__main__': ...@@ -40,6 +40,8 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--msize', default=1000, type=int, parser.add_argument('--msize', default=1000, type=int,
help='message size in bytes') help='message size in bytes')
parser.add_argument('--mpr', default=1, type=int,
help='messages per request')
parser.add_argument('--duration', '-T', default=30, type=int, parser.add_argument('--duration', '-T', default=30, type=int,
help='duration of test in seconds') help='duration of test in seconds')
parser.add_argument('--concurrency', default=3, type=int, parser.add_argument('--concurrency', default=3, type=int,
...@@ -62,8 +64,9 @@ if __name__ == '__main__': ...@@ -62,8 +64,9 @@ if __name__ == '__main__':
addr = tuple(addr) addr = tuple(addr)
MSGSIZE = args.msize MSGSIZE = args.msize
msg = (b'x' * (MSGSIZE - 1) + b'\n') * args.mpr
msg = b'x' * MSGSIZE REQSIZE = MSGSIZE * args.mpr
timeout = args.timeout * 1000 timeout = args.timeout * 1000
...@@ -85,8 +88,8 @@ if __name__ == '__main__': ...@@ -85,8 +88,8 @@ if __name__ == '__main__':
req_start = time.monotonic() req_start = time.monotonic()
sock.sendall(msg) sock.sendall(msg)
nrecv = 0 nrecv = 0
while nrecv < MSGSIZE: while nrecv < REQSIZE:
resp = sock.recv(MSGSIZE) resp = sock.recv(REQSIZE)
if not resp: if not resp:
raise SystemExit() raise SystemExit()
nrecv += len(resp) nrecv += len(resp)
...@@ -98,6 +101,11 @@ if __name__ == '__main__': ...@@ -98,6 +101,11 @@ if __name__ == '__main__':
latency_stats[req_time] += 1 latency_stats[req_time] += 1
n += 1 n += 1
try:
sock.close()
except OSError:
pass
return n, latency_stats, min_latency, max_latency return n, latency_stats, min_latency, max_latency
N = args.concurrency N = args.concurrency
......
...@@ -40,6 +40,7 @@ tcp_client = echo_client + ['--addr={}'.format(tcp_address)] ...@@ -40,6 +40,7 @@ tcp_client = echo_client + ['--addr={}'.format(tcp_address)]
unix_client = echo_client + ['--addr={}'.format(unix_address)] unix_client = echo_client + ['--addr={}'.format(unix_address)]
http_client = ['./http_client', '--output-format=json', http_client = ['./http_client', '--output-format=json',
'--addr={}'.format(tcp_address)] '--addr={}'.format(tcp_address)]
readline_client = tcp_client + ['--mpr=5']
benchmarks = [{ benchmarks = [{
'name': 'tcpecho-gevent-sockets', 'name': 'tcpecho-gevent-sockets',
...@@ -53,6 +54,12 @@ benchmarks = [{ ...@@ -53,6 +54,12 @@ benchmarks = [{
'server': python + ['/usr/src/servers/torecho.py'], 'server': python + ['/usr/src/servers/torecho.py'],
'server_address': tcp_address, 'server_address': tcp_address,
'client': tcp_client, 'client': tcp_client,
}, {
'name': 'readline-tornado',
'title': 'Streams readline (tornado)',
'server': python + ['/usr/src/servers/torecho_readline.py'],
'server_address': tcp_address,
'client': readline_client,
}, { }, {
'name': 'tcpecho-twisted-protocol', 'name': 'tcpecho-twisted-protocol',
'title': 'TCP echo server (twisted)', 'title': 'TCP echo server (twisted)',
...@@ -66,11 +73,11 @@ benchmarks = [{ ...@@ -66,11 +73,11 @@ benchmarks = [{
'server_address': tcp_address, 'server_address': tcp_address,
'client': tcp_client, 'client': tcp_client,
}, { }, {
'name': 'tcpecho-curio-streams', 'name': 'readline-curio',
'title': 'TCP echo server (curio/streams)', 'title': 'Streams readline (curio)',
'server': python + ['/usr/src/servers/curioecho_streams.py'], 'server': python + ['/usr/src/servers/curioecho_streams.py'],
'server_address': tcp_address, 'server_address': tcp_address,
'client': tcp_client, 'client': readline_client,
}, { }, {
'name': 'tcpecho-nodejs-streams', 'name': 'tcpecho-nodejs-streams',
'title': 'TCP echo server (nodejs)', 'title': 'TCP echo server (nodejs)',
...@@ -92,13 +99,13 @@ benchmarks = [{ ...@@ -92,13 +99,13 @@ benchmarks = [{
'server_address': tcp_address, 'server_address': tcp_address,
'client': tcp_client, 'client': tcp_client,
}, { }, {
'name': 'tcpecho-asyncio-streams', 'name': 'readline-asyncio',
'title': 'TCP echo server (asyncio/streams)', 'title': 'Streams readline (asyncio)',
'server': python + ['/usr/src/servers/asyncioecho.py', 'server': python + ['/usr/src/servers/asyncioecho.py',
'--addr=0.0.0.0:25000', '--addr=0.0.0.0:25000',
'--streams'], '--streams'],
'server_address': tcp_address, 'server_address': tcp_address,
'client': tcp_client, 'client': readline_client,
}, { }, {
'name': 'tcpecho-asyncio-sockets', 'name': 'tcpecho-asyncio-sockets',
'title': 'TCP echo server (asyncio/sockets)', 'title': 'TCP echo server (asyncio/sockets)',
...@@ -131,13 +138,13 @@ benchmarks = [{ ...@@ -131,13 +138,13 @@ benchmarks = [{
'server_address': tcp_address, 'server_address': tcp_address,
'client': tcp_client, 'client': tcp_client,
}, { }, {
'name': 'tcpecho-uvloop-streams', 'name': 'readline-uvloop',
'title': 'TCP echo server (uvloop/streams)', 'title': 'Streams readline (uvloop)',
'server': python + ['/usr/src/servers/asyncioecho.py', 'server': python + ['/usr/src/servers/asyncioecho.py',
'--addr=0.0.0.0:25000', '--addr=0.0.0.0:25000',
'--streams', '--uvloop'], '--streams', '--uvloop'],
'server_address': tcp_address, 'server_address': tcp_address,
'client': tcp_client, 'client': readline_client,
}, { }, {
'name': 'tcpecho-uvloop-sockets', 'name': 'tcpecho-uvloop-sockets',
'title': 'TCP echo server (uvloop/sockets)', 'title': 'TCP echo server (uvloop/sockets)',
......
...@@ -54,7 +54,7 @@ async def echo_client_streams(reader, writer): ...@@ -54,7 +54,7 @@ async def echo_client_streams(reader, writer):
if PRINT: if PRINT:
print('Connection from', sock.getpeername()) print('Connection from', sock.getpeername())
while True: while True:
data = await reader.read(102400) data = await reader.readline()
if not data: if not data:
break break
writer.write(data) writer.write(data)
...@@ -133,10 +133,12 @@ if __name__ == '__main__': ...@@ -133,10 +133,12 @@ if __name__ == '__main__':
print('using asyncio/streams') print('using asyncio/streams')
if unix: if unix:
coro = asyncio.start_unix_server(echo_client_streams, coro = asyncio.start_unix_server(echo_client_streams,
addr, loop=loop) addr, loop=loop,
limit=1024 * 1024)
else: else:
coro = asyncio.start_server(echo_client_streams, coro = asyncio.start_server(echo_client_streams,
*addr, loop=loop) *addr, loop=loop,
limit=1024 * 1024)
srv = loop.run_until_complete(coro) srv = loop.run_until_complete(coro)
elif args.proto: elif args.proto:
if args.streams: if args.streams:
......
...@@ -9,7 +9,7 @@ async def echo_handler(client, addr): ...@@ -9,7 +9,7 @@ async def echo_handler(client, addr):
pass pass
s = client.as_stream() s = client.as_stream()
while True: while True:
data = await s.read(102400) data = await s.readline()
if not data: if not data:
break break
await s.write(data) await s.write(data)
......
from tornado.ioloop import IOLoop
from tornado.tcpserver import TCPServer
class StreamHandler:
def __init__(self, stream):
self._stream = stream
stream.set_nodelay(True)
self._stream.read_until(b'\n', self._handle_read)
def _handle_read(self, data):
self._stream.write(data)
self._stream.read_until(b'\n', self._handle_read)
class EchoServer(TCPServer):
def handle_stream(self, stream, address):
StreamHandler(stream)
if __name__ == '__main__':
server = EchoServer()
server.bind(25000)
server.start(1)
IOLoop.instance().start()
IOLoop.instance().close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment