diff --git a/perfkitbenchmarker/linux_benchmarks/sysbench_benchmark.py b/perfkitbenchmarker/linux_benchmarks/sysbench_benchmark.py index 6df359a321..e38a526d18 100644 --- a/perfkitbenchmarker/linux_benchmarks/sysbench_benchmark.py +++ b/perfkitbenchmarker/linux_benchmarks/sysbench_benchmark.py @@ -158,6 +158,13 @@ ' benchmark mode to work', ) +_SYSBENCH_OPEN_FILE_LIMIT = flags.DEFINE_integer( + 'sysbench_open_file_limit', + None, + 'Override the default linux open file limit (ulimit -n) for sysbench' + ' execution.', +) + _SCALEUP_CLIENTS_TEST_NUM_CLIENTS = flags.DEFINE_integer( 'sysbench_scaleup_clients_test_num_clients', 1, @@ -381,14 +388,24 @@ def _IsValidFlag(flag): ) +def _GetUlimitCommand() -> str: + """Returns the ulimit command prefix if an open file limit is set.""" + if _SYSBENCH_OPEN_FILE_LIMIT.value: + return f'ulimit -n {_SYSBENCH_OPEN_FILE_LIMIT.value} && ' + return '' + + def _GetSysbenchPrepareCommand( db: relational_db.BaseRelationalDb, num_vms: int, vm_index: int ) -> str: """Returns the sysbench command used to load the database.""" # TODO(ruwa): Migrate to use sysbench.BuildLoadCommand() + ulimit_cmd = _GetUlimitCommand() data_load_cmd_tokens = [ - 'cd ~/sysbench/ && nice', # run with a niceness of lower priority - '-15', # to encourage cpu time for ssh commands + # Run with a niceness of lower priority to encourage CPU time for SSH + # commands. + f'cd ~/sysbench/ && {ulimit_cmd}nice', + '-15', 'sysbench', _GetSysbenchTestParameter(), '--tables=%d' % FLAGS.sysbench_tables, @@ -662,6 +679,7 @@ def _GetSysbenchRunCommand( if duration <= 0: raise ValueError('Duration must be greater than zero.') + ulimit_cmd = _GetUlimitCommand() run_cmd_tokens = [ 'nice', # run with a niceness of lower priority '-15', # to encourage cpu time for ssh commands @@ -696,7 +714,7 @@ def _GetSysbenchRunCommand( ) and not spanner_read_committed: run_cmd_tokens.append('--trx_level=%s' % _TXN_ISOLATION_LEVEL.value) run_cmd = ' '.join(run_cmd_tokens + _GetCommonSysbenchOptions(db) + ['run']) - run_cmd = 'cd ~/sysbench/ && ' + run_cmd + run_cmd = f'cd ~/sysbench/ && {ulimit_cmd}' + run_cmd return run_cmd diff --git a/perfkitbenchmarker/linux_packages/pgbench.py b/perfkitbenchmarker/linux_packages/pgbench.py index 3c08dac3c2..d7def721ce 100644 --- a/perfkitbenchmarker/linux_packages/pgbench.py +++ b/perfkitbenchmarker/linux_packages/pgbench.py @@ -17,10 +17,18 @@ import socket import statistics import time +from absl import flags from perfkitbenchmarker import publisher from perfkitbenchmarker import sample from perfkitbenchmarker import sql_engine_utils +_PGBENCH_OPEN_FILE_LIMIT = flags.DEFINE_integer( + 'pgbench_open_file_limit', + None, + 'Override the default linux open file limit (ulimit -n) for pgbench' + ' execution.', +) + APT_PACKAGES = ( 'postgresql-client-common', 'postgresql-client', @@ -176,8 +184,13 @@ def RunPgBench( jobs = min(client, 16) start_time = datetime.datetime.now() + ulimit_cmd = ( + f'ulimit -n {_PGBENCH_OPEN_FILE_LIMIT.value} && ' + if _PGBENCH_OPEN_FILE_LIMIT.value + else '' + ) command = ( - f'ulimit -n 10000 && pgbench {connection_string} --client={client} ' + f'{ulimit_cmd}pgbench {connection_string} --client={client} ' f'--jobs={jobs} --time={seconds_per_test} --progress=1 ' '-r' + extended_protocol