Skip to content

Commit 2bf186a

Browse files
committed
Added command execution time measurement
This will be useful to keep track of possible performance degradation when code changes.
1 parent 8a25cb3 commit 2bf186a

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

testgres/performance_test.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from .plugins.pg_probackup2.pg_probackup2.tests.basic_test import ProbackupTest
2+
3+
class PerformanceTest(ProbackupTest):
4+
5+
def test_full_backup_perf_basic(self):
6+
"""
7+
Full backup in 4 threads should be faster than in 1 thread
8+
"""
9+
node = self.pg_node.make_simple('node', pg_options={"fsync": "off", "synchronous_commit": "off"})
10+
11+
self.pb.init()
12+
self.pb.add_instance('node', node)
13+
self.pb.set_archiving('node', node)
14+
node.slow_start()
15+
16+
# Fill with data
17+
node.pgbench_init(scale=100, no_vacuum=True)
18+
19+
# FULL
20+
backup_id_1t = self.pb.backup_node('node', node, options=["--no-validate"], check_time=True)
21+
elapsed_time_1t = backup_id_1t.execution_time
22+
# Full in 4 threads
23+
backup_id_4t = self.pb.backup_node('node', node, options=["-j", "4", "--no-validate"], check_time=True)
24+
elapsed_time_4t = backup_id_4t.execution_time
25+
26+
# Full by basebackup
27+
backup = node.backup(check_time=True)
28+
elapsed_time_base = backup.elapsed_time
29+
30+
print(f"elapsed_time_1t: {elapsed_time_1t}, elapsed_time_4t: {elapsed_time_4t}, elapsed_time_base: {elapsed_time_base}")
31+
self.assertLess(elapsed_time_4t, elapsed_time_base, "Full backup in 4 threads should be faster than pg_basebackup")
32+
self.assertLess(elapsed_time_4t, elapsed_time_1t, "Full backup in 4 threads should be faster than in 1 thread")
33+
self.assertLess(elapsed_time_1t, elapsed_time_base, "Full backup should be faster than pg_basebackup")

testgres/plugins/pg_probackup2/pg_probackup2/app.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __str__(self):
4343
class ProbackupApp:
4444

4545
def __init__(self, test_class: unittest.TestCase,
46-
pg_node, pb_log_path, test_env, auto_compress_alg, backup_dir):
46+
pg_node, pb_log_path, test_env, auto_compress_alg, backup_dir, execution_time):
4747
self.test_class = test_class
4848
self.pg_node = pg_node
4949
self.pb_log_path = pb_log_path
@@ -56,9 +56,10 @@ def __init__(self, test_class: unittest.TestCase,
5656
self.verbose = init_params.verbose
5757
self.archive_compress = init_params.archive_compress
5858
self.test_class.output = None
59+
self.execution_time = execution_time
5960

6061
def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
61-
skip_log_directory=False, expect_error=False, use_backup_dir=True):
62+
skip_log_directory=False, expect_error=False, use_backup_dir=True, execution_time=False):
6263
"""
6364
Run pg_probackup
6465
backup_dir: target directory for making backup
@@ -113,11 +114,22 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
113114
cmdline = ['gdbserver'] + ['localhost:' + str(gdb_port)] + cmdline
114115
print("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}".format(gdb_port))
115116

116-
self.test_class.output = subprocess.check_output(
117-
cmdline,
118-
stderr=subprocess.STDOUT,
119-
env=env
120-
).decode('utf-8', errors='replace')
117+
if execution_time:
118+
start_time = time.time()
119+
self.test_class.output = subprocess.check_output(
120+
cmdline,
121+
stderr=subprocess.STDOUT,
122+
env=env
123+
).decode('utf-8', errors='replace')
124+
end_time = time.time()
125+
self.execution_time = end_time - start_time
126+
else:
127+
self.test_class.output = subprocess.check_output(
128+
cmdline,
129+
stderr=subprocess.STDOUT,
130+
env=env
131+
).decode('utf-8', errors='replace')
132+
121133
if command[0] == 'backup' and return_id:
122134
# return backup ID
123135
for line in self.test_class.output.splitlines():
@@ -213,7 +225,8 @@ def backup_node(
213225
old_binary=False, return_id=True, no_remote=False,
214226
env=None,
215227
expect_error=False,
216-
sync=False
228+
sync=False,
229+
execution_time=False
217230
):
218231
if options is None:
219232
options = []
@@ -253,7 +266,7 @@ def backup_node(
253266
cmd_list += ['--no-sync']
254267

255268
return self.run(cmd_list + options, gdb, old_binary, return_id, env=env,
256-
expect_error=expect_error)
269+
expect_error=expect_error, execution_time=execution_time)
257270

258271
def backup_replica_node(self, instance, node, data_dir=False, *,
259272
master, backup_type='full', datname=False,

0 commit comments

Comments
 (0)