Last active
April 3, 2017 14:03
-
-
Save za-arthur/5d920658d8d5ea0b4808002dfab3d8aa to your computer and use it in GitHub Desktop.
bench_rsocket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import argparse | |
import csv | |
import datetime | |
import os | |
import paramiko | |
import re | |
import subprocess | |
import sys | |
import time | |
class Server(object): | |
def __init__(self, bin_path, host, user, password, port, with_rsocket): | |
self.bin_path = bin_path | |
self.host = host | |
self.user = user | |
self.password = password | |
self.port = port | |
self.with_rsocket = with_rsocket | |
def init(self): | |
client = paramiko.SSHClient() | |
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
client.connect(hostname=self.host, username=self.user, | |
password=self.password, port=self.port) | |
self.client = client | |
self.__exec_command("{0}/bin/initdb -D {0}/bench_data".format(self.bin_path)) | |
# Set configuration | |
if self.with_rsocket: | |
self.__append_conf("listen_addresses", "") | |
self.__append_conf("listen_rdma_addresses", self.host) | |
self.__append_conf("shared_buffers", "8GB") | |
self.__append_conf("work_mem", "50MB") | |
self.__append_conf("maintenance_work_mem", "2GB") | |
self.__append_conf("max_wal_size", "16GB") | |
# fsync is 'on' | |
# self.__append_conf("fsync", "off") | |
# synchronous_commit is 'on' | |
# self.__append_conf("synchronous_commit", "off") | |
self.__exec_command("""echo "host all all 0.0.0.0/0 trust" >> {0}/bench_data/pg_hba.conf""".format( | |
self.bin_path)) | |
def run(self): | |
self.__exec_command("{0}/bin/pg_ctl -w start -D {0}/bench_data -l {0}/bench_data/postgresql.log".format( | |
self.bin_path)) | |
self.__exec_command("{0}/bin/createdb pgbench".format(self.bin_path)) | |
def stop(self): | |
self.__exec_command("{0}/bin/pg_ctl -w stop -D {0}/bench_data".format(self.bin_path)) | |
self.__exec_command("rm -rf {0}/bench_data".format(self.bin_path)) | |
self.client.close() | |
def __exec_command(self, cmd): | |
stdin, stdout, stderr = self.client.exec_command(cmd) | |
if stderr.channel.recv_exit_status() != 0: | |
print(stderr.read()) | |
sys.exit("Command '{0}' failed with code: {1}".format(cmd, | |
stderr.channel.recv_exit_status())) | |
def __append_conf(self, name, value): | |
self.__exec_command("""echo "{0} = '{1}'" >> {2}/bench_data/postgresql.auto.conf""".format( | |
name, value, self.bin_path)) | |
class Shell(object): | |
def __init__(self, cmd, wait_time = 0): | |
self.cmd = cmd | |
self.stdout = None | |
self.run() | |
def run(self): | |
p = subprocess.Popen(self.cmd, shell=True, | |
stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) | |
p.wait() | |
if p.returncode != 0: | |
out, err = p.communicate() | |
print(err) | |
sys.exit("Command '{0}' failed with code: {1}".format( | |
self.cmd, p.returncode)) | |
self.stdout = "".join(p.stdout.readlines()) | |
class Result(object): | |
def __init__(self, out): | |
try: | |
self.out = out | |
m = re.search('tps = (\d+)(,|\.)(.+)including connections establishing(.+)', self.out) | |
self.tps = int(m.group(1)) | |
m = re.search('number of transactions actually processed\: (\d+)', self.out) | |
self.trans = int(m.group(1)) | |
m = re.search('latency average = (\d+)\.(\d+) ms', self.out) | |
self.avg_latency = float(m.group(1)+"."+m.group(2)) | |
except AttributeError: | |
sys.exit("Can't parse stdout:\n{0}".format(self.out)) | |
class Writer(object): | |
def __init__(self, filename): | |
self.f = open(filename, "wb") | |
fieldnames = ["clients", "tps", "trans", "avg_latency"] | |
self.writer = csv.DictWriter(self.f, fieldnames) | |
self.writer.writeheader() | |
def add_value(self, clients, tps, trans, avg_latency): | |
self.writer.writerow({"clients": clients, "tps": tps, "trans": trans, | |
"avg_latency": avg_latency}) | |
def close(self): | |
self.f.close() | |
class Test(object): | |
def __init__(self, server, scale, clients, run_time, select_only): | |
self.server = server | |
self.scale = scale | |
self.clients = clients | |
self.run_time = run_time | |
self.select_only = select_only | |
def run(self): | |
with_rsocket = "--with-rsocket" if self.server.with_rsocket else "" | |
select_only = "--select-only" if self.select_only else "" | |
filename = "{0}_{1}_clients_{2}.csv".format( | |
"rsocket" if self.server.with_rsocket else "socket", | |
self.clients, datetime.datetime.now().strftime("%Y-%m-%d_%H-%M")) | |
w = Writer(filename) | |
print("Initialize data directory...") | |
self.server.init() | |
print("Run database server...") | |
self.server.run() | |
print("Initialize pgbench database...") | |
Shell("{0}/bin/pgbench -h {1} {2} -s {3} -i pgbench".format( | |
self.server.bin_path, self.server.host, with_rsocket, self.scale)) | |
for i in range(0, self.clients + 1, 4): | |
c = 1 if i == 0 else i | |
if i != 0: | |
print("\n") | |
# Wait 2 seconds | |
time.sleep(2) | |
print("Run pgbench for {0} clients...".format(c)) | |
out = Shell("{0}/bin/pgbench -h {1} {2} {3} -c {4} -j {4} -T {5} -v pgbench".format( | |
self.server.bin_path, self.server.host, with_rsocket, select_only, c, self.run_time)) | |
res = Result(out.stdout) | |
w.add_value(c, res.tps, res.trans, res.avg_latency) | |
print("Test result: tps={0} trans={1} avg_latency={2}".format( | |
res.tps, res.trans, res.avg_latency)) | |
print("Stop database server. Remove data directory...") | |
self.server.stop() | |
w.close() | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="rsocket benchmark tool", | |
add_help=False) | |
parser.add_argument("-?", "--help", | |
action="help", | |
help="Show this help message and exit") | |
parser.add_argument("-b", "--bin-path", | |
type=str, | |
help="PostgreSQL binaries path", | |
required=True, | |
dest="bin_path") | |
parser.add_argument("-h", "--host", | |
type=str, | |
help="Database server''s host name", | |
required=True, | |
dest="host") | |
parser.add_argument("-u", "--user", | |
type=str, | |
help="User to connect through ssh and libpq", | |
required=True, | |
dest="user") | |
parser.add_argument("--password", | |
type=str, | |
help="Password to connect through ssh", | |
required=True, | |
dest="password") | |
parser.add_argument("-p", "--port", | |
type=int, | |
help="Ssh port", | |
default=22, | |
dest="port") | |
parser.add_argument("-s", "--scale", | |
type=int, | |
help="Scale of tables", | |
default=100, | |
dest="scale") | |
parser.add_argument("-t", "--time", | |
type=int, | |
help="Time for tests", | |
default=120, | |
dest="time") | |
parser.add_argument("-c", "--clients", | |
type=int, | |
help="Maximum number of clients", | |
default=100, | |
dest="clients") | |
parser.add_argument("-S", "--select-only", | |
help="Run select-only script", | |
action="store_true", | |
default=False, | |
dest="select_only") | |
args = parser.parse_args() | |
# Run rsocket test | |
serv = Server(args.bin_path, args.host, args.user, args.password, args.port, True) | |
test = Test(serv, args.scale, args.clients, args.time, args.select_only) | |
test.run() | |
# Run socket test | |
serv = Server(args.bin_path, args.host, args.user, args.password, args.port, False) | |
test = Test(serv, args.scale, args.clients, args.time, args.select_only) | |
test.run() | |
print("Finished") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import argparse | |
import csv | |
import datetime | |
import paramiko | |
import re | |
import sys | |
import subprocess | |
import tempfile | |
import time | |
class PrimaryServer(object): | |
def __init__(self, bin_path, host, scale, user, password, port, with_rsocket): | |
self.bin_path = bin_path | |
self.host = host | |
self.scale = scale | |
self.user = user | |
self.password = password | |
self.port = port | |
self.with_rsocket = with_rsocket | |
def init(self): | |
client = paramiko.SSHClient() | |
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
client.connect(hostname=self.host, username=self.user, | |
password=self.password, port=self.port) | |
self.client = client | |
self.__exec_command("{0}/bin/initdb -D {0}/repl_bench_data".format(self.bin_path)) | |
# Set configuration | |
if self.with_rsocket: | |
self.__append_conf("listen_addresses", "") | |
self.__append_conf("listen_rdma_addresses", self.host) | |
self.__append_conf("shared_buffers", "8GB") | |
self.__append_conf("work_mem", "50MB") | |
self.__append_conf("maintenance_work_mem", "2GB") | |
self.__append_conf("max_wal_size", "16GB") | |
# fsync is 'on' | |
# self.__append_conf("fsync", "off") | |
# synchronous_commit is 'on' | |
# self.__append_conf("synchronous_commit", "remote_apply") | |
def run(self): | |
self.__exec_command("{0}/bin/pg_ctl -w start -D {0}/repl_bench_data -l {0}/repl_bench_data/postgresql.log".format( | |
self.bin_path)) | |
self.__exec_command("{0}/bin/createdb pgbench".format(self.bin_path)) | |
self.__exec_command("{0}/bin/pgbench -s {1} -i pgbench".format(self.bin_path, self.scale)) | |
self.__exec_command("{0}/bin/pg_ctl -w stop -D {0}/repl_bench_data".format(self.bin_path)) | |
self.__append_conf("wal_level", "hot_standby") | |
self.__append_conf("max_wal_senders", "2") | |
self.__append_conf("synchronous_standby_names", "*") | |
self.__append_conf("hot_standby", "on") | |
self.__exec_command("""echo "local replication postgres trust" >> {0}/repl_bench_data/pg_hba.conf""".format( | |
self.bin_path)) | |
self.__exec_command("""echo "host replication postgres 0.0.0.0/0 trust" >> {0}/repl_bench_data/pg_hba.conf""".format( | |
self.bin_path)) | |
self.__exec_command("{0}/bin/pg_ctl -w start -D {0}/repl_bench_data -l {0}/repl_bench_data/postgresql.log".format( | |
self.bin_path)) | |
def stop(self): | |
self.__exec_command("{0}/bin/pg_ctl -w stop -D {0}/repl_bench_data".format(self.bin_path)) | |
self.__exec_command("rm -rf {0}/repl_bench_data".format(self.bin_path)) | |
self.client.close() | |
def __exec_command(self, cmd): | |
stdin, stdout, stderr = self.client.exec_command(cmd) | |
if stderr.channel.recv_exit_status() != 0: | |
print(stderr.read()) | |
sys.exit("Command '{0}' failed with code: {1}".format(cmd, | |
stderr.channel.recv_exit_status())) | |
def __append_conf(self, name, value): | |
self.__exec_command("""echo "{0} = '{1}'" >> {2}/repl_bench_data/postgresql.auto.conf""".format( | |
name, value, self.bin_path)) | |
class StandbyServer(object): | |
def __init__(self, bin_path, primary_host, standby_host, user, password, port, with_rsocket): | |
self.bin_path = bin_path | |
self.primary_host = primary_host | |
self.standby_host = standby_host | |
self.user = user | |
self.password = password | |
self.port = port | |
self.with_rsocket = with_rsocket | |
def init(self): | |
client = paramiko.SSHClient() | |
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
client.connect(hostname=self.standby_host, username=self.user, | |
password=self.password, port=self.port) | |
self.client = client | |
self.__exec_command(("{0}/bin/pg_basebackup -D {0}/repl_bench_data " | |
"-x -R -h {1} {2}").format(self.bin_path, self.primary_host, | |
"--with-rsocket" if self.with_rsocket else "")) | |
# Set configuration | |
self.__append_conf("listen_addresses", "*") | |
self.__append_conf("listen_rdma_addresses", "") | |
def run(self): | |
self.__exec_command("{0}/bin/pg_ctl -w start -D {0}/repl_bench_data -l {0}/repl_bench_data/postgresql.log".format( | |
self.bin_path)) | |
def stop(self): | |
self.__exec_command("{0}/bin/pg_ctl -w stop -D {0}/repl_bench_data".format(self.bin_path)) | |
self.__exec_command("rm -rf {0}/repl_bench_data".format(self.bin_path)) | |
self.client.close() | |
def __exec_command(self, cmd): | |
stdin, stdout, stderr = self.client.exec_command(cmd) | |
if stderr.channel.recv_exit_status() != 0: | |
print(stderr.read()) | |
sys.exit("Command '{0}' failed with code: {1}".format(cmd, | |
stderr.channel.recv_exit_status())) | |
def __append_conf(self, name, value): | |
self.__exec_command("""echo "{0} = '{1}'" >> {2}/repl_bench_data/postgresql.auto.conf""".format( | |
name, value, self.bin_path)) | |
class Shell(object): | |
def __init__(self, cmd, wait_time = 0): | |
self.cmd = cmd | |
self.stdout = None | |
self.run() | |
def run(self): | |
with tempfile.TemporaryFile() as out, \ | |
tempfile.TemporaryFile() as err: | |
p = subprocess.Popen(self.cmd, shell=True, | |
stdout=out, stderr=err, close_fds=True) | |
p.wait() | |
out.seek(0) | |
err.seek(0) | |
if p.returncode != 0: | |
print(out.read()) | |
print("\n") | |
print(err.read()) | |
sys.exit("Command '{0}' failed with code: {1}".format( | |
self.cmd, p.returncode)) | |
self.stdout = out.read() | |
class Result(object): | |
def __init__(self, out): | |
try: | |
self.out = out | |
m = re.search('tps = (\d+)(,|\.)(.+)including connections establishing(.+)', self.out) | |
self.tps = int(m.group(1)) | |
m = re.search('number of transactions actually processed\: (\d+)', self.out) | |
self.trans = int(m.group(1)) | |
m = re.search('latency average = (\d+)\.(\d+) ms', self.out) | |
self.avg_latency = float(m.group(1)+"."+m.group(2)) | |
except AttributeError: | |
sys.exit("Can't parse stdout:\n{0}".format(self.out)) | |
class Writer(object): | |
def __init__(self, filename): | |
self.f = open(filename, "wb") | |
fieldnames = ["clients", "tps", "trans", "avg_latency"] | |
self.writer = csv.DictWriter(self.f, fieldnames) | |
self.writer.writeheader() | |
def add_value(self, clients, tps, trans, avg_latency): | |
self.writer.writerow({"clients": clients, "tps": tps, "trans": trans, | |
"avg_latency": avg_latency}) | |
def close(self): | |
self.f.close() | |
class Test(object): | |
def __init__(self, primary_server, standby_server, clients, run_time): | |
self.primary_server = primary_server | |
self.standby_server = standby_server | |
self.clients = clients | |
self.run_time = run_time | |
def run(self): | |
filename = "{0}_{1}_clients_{2}.csv".format( | |
"rsocket" if self.primary_server.with_rsocket else "socket", | |
self.clients, datetime.datetime.now().strftime("%Y-%m-%d_%H-%M")) | |
w = Writer(filename) | |
print("Initialize primary server...") | |
self.primary_server.init() | |
print("Run primary database server...") | |
self.primary_server.run() | |
print("Initialize standby server...") | |
self.standby_server.init() | |
print("Run standby database server...") | |
self.standby_server.run() | |
for i in range(0, self.clients + 1, 4): | |
c = 1 if i == 0 else i | |
if i != 0: | |
print("\n") | |
print("Run pgbench for {0} clients...".format(c)) | |
out = Shell("{0}/bin/pgbench -h {1} {2} -c {3} -j {3} -T {4} -v pgbench".format( | |
self.primary_server.bin_path, self.primary_server.host, | |
"--with-rsocket" if self.primary_server.with_rsocket else "", | |
c, self.run_time)) | |
res = Result(out.stdout) | |
w.add_value(c, res.tps, res.trans, res.avg_latency) | |
print("Test result: tps={0} trans={1} avg_latency={2}".format( | |
res.tps, res.trans, res.avg_latency)) | |
print("Stop standby database server. Remove data directory...") | |
self.standby_server.stop() | |
print("Stop primary database server. Remove data directory...") | |
self.primary_server.stop() | |
w.close() | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="rsocket benchmark tool", | |
add_help=False) | |
parser.add_argument("-?", "--help", | |
action="help", | |
help="Show this help message and exit") | |
parser.add_argument("-b", "--bin-path", | |
type=str, | |
help="PostgreSQL binaries path", | |
required=True, | |
dest="bin_path") | |
parser.add_argument("--primary", | |
type=str, | |
help="Primary database server''s host name", | |
required=True, | |
dest="primary_host") | |
parser.add_argument("--standby", | |
type=str, | |
help="Standby database server''s host name", | |
required=True, | |
dest="standby_host") | |
parser.add_argument("-u", "--user", | |
type=str, | |
help="User to connect through ssh", | |
required=True, | |
dest="user") | |
parser.add_argument("--password", | |
type=str, | |
help="Password to connect through ssh", | |
required=True, | |
dest="password") | |
parser.add_argument("-p", "--port", | |
type=int, | |
help="Ssh port", | |
default=22, | |
dest="port") | |
parser.add_argument("-s", "--scale", | |
type=int, | |
help="Scale of tables", | |
default=100, | |
dest="scale") | |
parser.add_argument("-t", "--time", | |
type=int, | |
help="Time for tests", | |
default=120, | |
dest="time") | |
parser.add_argument("-c", "--clients", | |
type=int, | |
help="Maximum number of clients", | |
default=100, | |
dest="clients") | |
args = parser.parse_args() | |
# Run rsocket test | |
prim_serv = PrimaryServer(args.bin_path, args.primary_host, args.scale, | |
args.user, args.password, args.port, True) | |
standby_serv = StandbyServer(args.bin_path, args.primary_host, args.standby_host, | |
args.user, args.password, args.port, True) | |
test = Test(prim_serv, standby_serv, args.clients, args.time) | |
test.run() | |
# Run socket test | |
prim_serv = PrimaryServer(args.bin_path, args.primary_host, args.scale, | |
args.user, args.password, args.port, False) | |
standby_serv = StandbyServer(args.bin_path, args.primary_host, args.standby_host, | |
args.user, args.password, args.port, False) | |
test = Test(prim_serv, standby_serv, args.clients, args.time) | |
test.run() | |
print("Finished") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import argparse | |
import csv | |
import datetime | |
import os | |
import paramiko | |
import re | |
import subprocess | |
import sys | |
import time | |
class Server(object): | |
def __init__(self, bin_path, host, user, password, port, with_rsocket): | |
self.bin_path = bin_path | |
self.host = host | |
self.user = user | |
self.password = password | |
self.port = port | |
self.with_rsocket = with_rsocket | |
def init(self): | |
client = paramiko.SSHClient() | |
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
client.connect(hostname=self.host, username=self.user, | |
password=self.password, port=self.port) | |
self.client = client | |
self.__exec_command("{0}/bin/initdb -D {0}/bench_data".format(self.bin_path)) | |
# Set configuration | |
if self.with_rsocket: | |
self.__append_conf("listen_addresses", "") | |
self.__append_conf("listen_rdma_addresses", self.host) | |
self.__append_conf("shared_buffers", "8GB") | |
self.__append_conf("work_mem", "50MB") | |
self.__append_conf("maintenance_work_mem", "2GB") | |
self.__append_conf("max_wal_size", "16GB") | |
# fsync is 'on' | |
# self.__append_conf("fsync", "off") | |
# synchronous_commit is 'on' | |
# self.__append_conf("synchronous_commit", "off") | |
self.__exec_command("""echo "host all all 0.0.0.0/0 trust" >> {0}/bench_data/pg_hba.conf""".format( | |
self.bin_path)) | |
def run(self): | |
self.__exec_command("{0}/bin/pg_ctl -w start -D {0}/bench_data -l {0}/bench_data/postgresql.log".format( | |
self.bin_path)) | |
def stop(self): | |
self.__exec_command("{0}/bin/pg_ctl -w stop -D {0}/bench_data".format(self.bin_path)) | |
self.__exec_command("rm -rf {0}/bench_data".format(self.bin_path)) | |
self.client.close() | |
def __exec_command(self, cmd): | |
stdin, stdout, stderr = self.client.exec_command(cmd) | |
if stderr.channel.recv_exit_status() != 0: | |
print(stderr.read()) | |
sys.exit("Command '{0}' failed with code: {1}".format(cmd, | |
stderr.channel.recv_exit_status())) | |
def __append_conf(self, name, value): | |
self.__exec_command("""echo "{0} = '{1}'" >> {2}/bench_data/postgresql.auto.conf""".format( | |
name, value, self.bin_path)) | |
class Shell(object): | |
def __init__(self, cmd, wait_time = 0): | |
self.cmd = cmd | |
self.stdout = None | |
self.run() | |
def run(self): | |
p = subprocess.Popen(self.cmd, shell=True, | |
stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) | |
p.wait() | |
if p.returncode != 0: | |
out, err = p.communicate() | |
print(err) | |
sys.exit("Command '{0}' failed with code: {1}".format( | |
self.cmd, p.returncode)) | |
self.stdout = "".join(p.stdout.readlines()) | |
class Result(object): | |
def __init__(self, out): | |
try: | |
self.out = out | |
m = re.search('tps = (\d+)(,|\.)(.+)including connections establishing(.+)', self.out) | |
self.tps = int(m.group(1)) | |
m = re.search('number of transactions actually processed\: (\d+)', self.out) | |
self.trans = int(m.group(1)) | |
m = re.search('latency average = (\d+)\.(\d+) ms', self.out) | |
self.avg_latency = float(m.group(1)+"."+m.group(2)) | |
except AttributeError: | |
sys.exit("Can't parse stdout:\n{0}".format(self.out)) | |
class Writer(object): | |
def __init__(self, filename): | |
self.f = open(filename, "wb") | |
fieldnames = ["clients", "tps", "trans", "avg_latency"] | |
self.writer = csv.DictWriter(self.f, fieldnames) | |
self.writer.writeheader() | |
def add_value(self, clients, tps, trans, avg_latency): | |
self.writer.writerow({"clients": clients, "tps": tps, "trans": trans, | |
"avg_latency": avg_latency}) | |
def close(self): | |
self.f.close() | |
class Test(object): | |
def __init__(self, server, clients, run_time): | |
self.server = server | |
self.clients = clients | |
self.run_time = run_time | |
def run(self): | |
with_rsocket = "--with-rsocket" if self.server.with_rsocket else "" | |
filename = "{0}_{1}_clients_{2}.csv".format( | |
"rsocket" if self.server.with_rsocket else "socket", | |
self.clients, datetime.datetime.now().strftime("%Y-%m-%d_%H-%M")) | |
w = Writer(filename) | |
print("Initialize data directory...") | |
self.server.init() | |
print("Run database server...") | |
self.server.run() | |
for i in range(0, self.clients + 1, 4): | |
c = 1 if i == 0 else i | |
if i != 0: | |
print("\n") | |
print("Run pgbench for {0} clients...".format(c)) | |
out = Shell("{0}/bin/pgbench -h {1} {2} -f select1.sql -c {3} -j {3} -T {4} postgres".format( | |
self.server.bin_path, self.server.host, with_rsocket, c, self.run_time)) | |
res = Result(out.stdout) | |
w.add_value(c, res.tps, res.trans, res.avg_latency) | |
print("Test result: tps={0} trans={1} avg_latency={2}".format( | |
res.tps, res.trans, res.avg_latency)) | |
print("Stop database server. Remove data directory...") | |
self.server.stop() | |
w.close() | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="rsocket benchmark tool", | |
add_help=False) | |
parser.add_argument("-?", "--help", | |
action="help", | |
help="Show this help message and exit") | |
parser.add_argument("-b", "--bin-path", | |
type=str, | |
help="PostgreSQL binaries path", | |
required=True, | |
dest="bin_path") | |
parser.add_argument("-h", "--host", | |
type=str, | |
help="Database server''s host name", | |
required=True, | |
dest="host") | |
parser.add_argument("-u", "--user", | |
type=str, | |
help="User to connect through ssh and libpq", | |
required=True, | |
dest="user") | |
parser.add_argument("--password", | |
type=str, | |
help="Password to connect through ssh", | |
required=True, | |
dest="password") | |
parser.add_argument("-p", "--port", | |
type=int, | |
help="Ssh port", | |
default=22, | |
dest="port") | |
parser.add_argument("-t", "--time", | |
type=int, | |
help="Time for tests", | |
default=120, | |
dest="time") | |
parser.add_argument("-c", "--clients", | |
type=int, | |
help="Maximum number of clients", | |
default=100, | |
dest="clients") | |
args = parser.parse_args() | |
# Run rsocket test | |
serv = Server(args.bin_path, args.host, args.user, args.password, args.port, True) | |
test = Test(serv, args.clients, args.time) | |
test.run() | |
# Run socket test | |
serv = Server(args.bin_path, args.host, args.user, args.password, args.port, False) | |
test = Test(serv, args.clients, args.time) | |
test.run() | |
print("Finished") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import argparse | |
import matplotlib.pyplot as plt | |
def read_csv(csv_file, mode): | |
x = [] | |
y = [] | |
i = 0 | |
with open(csv_file, "rb") as f: | |
for row in f: | |
# Skip header row | |
if i == 0: | |
i += 1 | |
continue | |
s = row.split(b",", 4) | |
# Clients | |
x.append(int(s[0])) | |
# TPS | |
if mode == "tps": | |
y.append(float(s[1])) | |
# Latency | |
else: | |
y.append(float(s[3])) | |
return x, y | |
def make_graphic(rsocket_csv, socket_csv, mode): | |
rsocket_x, rsocket_y = read_csv(rsocket_csv, mode) | |
socket_x, socket_y = read_csv(socket_csv, mode) | |
f, ax = plt.subplots() | |
ax.plot(rsocket_x, rsocket_y, color="blue", marker="s", label="rsocket") | |
ax.plot(socket_x, socket_y, color="red", marker="s", label="socket") | |
ax.set_title("pgbench, -s 350 -c 80 -T 120") | |
ax.set_xlabel("Number of clients") | |
if mode == "tps": | |
ax.set_ylabel("TPS") | |
else: | |
ax.set_ylabel("Latency, ms") | |
# Lower left corner | |
ax.legend(loc=4) | |
ax.grid(True) | |
plt.savefig("bench_rsocket.svg") | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description="Graphics creator") | |
parser.add_argument("-r", "--rsocket-csv", | |
type=str, | |
help="rsocket benchmark result", | |
required=True, | |
dest="rsocket_csv") | |
parser.add_argument("-s", "--socket-csv", | |
type=str, | |
help="socket benchmark result", | |
required=True, | |
dest="socket_csv") | |
parser.add_argument("-m", "--mode", | |
type=str, | |
help="TPS or Latency visualization", | |
default="tps", | |
choices=['tps', 'latency'], | |
dest="mode") | |
args = parser.parse_args() | |
make_graphic(args.rsocket_csv, args.socket_csv, args.mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment