<s> """<STR_LIT>""" <EOL> import collections <EOL> import logging <EOL> from perfkitbenchmarker import configs <EOL> from perfkitbenchmarker import errors <EOL> from perfkitbenchmarker import flags <EOL> from perfkitbenchmarker import sample <EOL> from perfkitbenchmarker import vm_util <EOL> from perfkitbenchmarker . linux_packages import redis_server <EOL> flags . DEFINE_integer ( '<STR_LIT>' , <NUM_LIT:1> , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> flags . DEFINE_integer ( '<STR_LIT>' , <NUM_LIT:5> , '<STR_LIT>' ) <EOL> flags . DEFINE_string ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> MEMTIER_COMMIT = '<STR_LIT>' <EOL> FIRST_PORT = <NUM_LIT> <EOL> FLAGS = flags . FLAGS <EOL> BENCHMARK_NAME = '<STR_LIT>' <EOL> BENCHMARK_CONFIG = """<STR_LIT>""" <EOL> def GetConfig ( user_config ) : <EOL> config = configs . LoadConfig ( BENCHMARK_CONFIG , user_config , BENCHMARK_NAME ) <EOL> config [ '<STR_LIT>' ] [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> + FLAGS . redis_clients <EOL> return config <EOL> def PrepareLoadgen ( load_vm ) : <EOL> load_vm . Install ( '<STR_LIT>' ) <EOL> def Prepare ( benchmark_spec ) : <EOL> """<STR_LIT>""" <EOL> vms = benchmark_spec . vms <EOL> redis_vm = vms [ <NUM_LIT:0> ] <EOL> redis_vm . Install ( '<STR_LIT>' ) <EOL> sed_cmd = ( r"<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> redis_vm . RemoteCommand ( sed_cmd % redis_server . REDIS_DIR ) <EOL> for i in range ( redis_vm . num_cpus * FLAGS . redis_numprocesses ) : <EOL> port = FIRST_PORT + i <EOL> redis_vm . RemoteCommand ( <EOL> '<STR_LIT>' % <EOL> ( redis_server . REDIS_DIR , redis_server . REDIS_DIR , port ) ) <EOL> redis_vm . RemoteCommand ( <EOL> r'<STR_LIT>' % <EOL> ( port , redis_server . REDIS_DIR , port ) ) <EOL> redis_vm . RemoteCommand ( <EOL> '<STR_LIT>' % <EOL> ( redis_server . REDIS_DIR , redis_server . REDIS_DIR , port ) ) <EOL> args = [ ( ( vm , ) , { } ) for vm in vms [ <NUM_LIT:1> : ] ] <EOL> vm_util . RunThreaded ( PrepareLoadgen , args ) <EOL> RedisResult = collections . namedtuple ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def RunLoad ( redis_vm , load_vm , threads , port , test_id ) : <EOL> """<STR_LIT>""" <EOL> if threads == <NUM_LIT:0> : <EOL> return None <EOL> base_cmd = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> final_cmd = ( base_cmd % ( redis_vm . internal_ip , port , <EOL> FLAGS . redis_setgetratio , threads , <NUM_LIT:10> , <EOL> '<STR_LIT>' ) + <EOL> base_cmd % ( redis_vm . internal_ip , port , <EOL> FLAGS . redis_setgetratio , threads , <NUM_LIT:20> , <EOL> '<STR_LIT>' % test_id ) + <EOL> base_cmd % ( redis_vm . internal_ip , port , <EOL> FLAGS . redis_setgetratio , threads , <NUM_LIT:10> , <EOL> '<STR_LIT>' ) ) <EOL> load_vm . RemoteCommand ( final_cmd ) <EOL> output , _ = load_vm . RemoteCommand ( '<STR_LIT>' <EOL> '<STR_LIT>' % test_id ) <EOL> throughput = float ( output ) <EOL> output , _ = load_vm . RemoteCommand ( '<STR_LIT>' <EOL> '<STR_LIT>' % test_id ) <EOL> latency = float ( output ) <EOL> output , _ = load_vm . RemoteCommand ( '<STR_LIT>' % test_id ) <EOL> logging . info ( output ) <EOL> return RedisResult ( throughput , latency ) <EOL> def Run ( benchmark_spec ) : <EOL> """<STR_LIT>""" <EOL> vms = benchmark_spec . vms <EOL> redis_vm = vms [ <NUM_LIT:0> ] <EOL> load_vms = vms [ <NUM_LIT:1> : ] <EOL> latency = <NUM_LIT:0.0> <EOL> latency_threshold = <NUM_LIT> <EOL> threads = <NUM_LIT:0> <EOL> results = [ ] <EOL> num_servers = redis_vm . num_cpus * FLAGS . redis_numprocesses <EOL> max_throughput_for_completion_latency_under_1ms = <NUM_LIT:0.0> <EOL> while latency < latency_threshold : <EOL> threads += max ( <NUM_LIT:1> , int ( threads * <NUM_LIT> ) ) <EOL> num_loaders = len ( load_vms ) * num_servers <EOL> args = [ ( ( redis_vm , load_vms [ i % len ( load_vms ) ] , threads / num_loaders + <EOL> ( <NUM_LIT:0> if ( i + <NUM_LIT:1> ) > threads % num_loaders else <NUM_LIT:1> ) , <EOL> FIRST_PORT + i % num_servers , i ) , <EOL> { } ) for i in range ( num_loaders ) ] <EOL> client_results = [ i for i in vm_util . RunThreaded ( RunLoad , args ) <EOL> if i is not None ] <EOL> logging . info ( '<STR_LIT>' , client_results ) <EOL> throughput = sum ( r . throughput for r in client_results ) <EOL> if not throughput : <EOL> raise errors . Benchmarks . RunError ( <EOL> '<STR_LIT>' . format ( threads , client_results ) ) <EOL> latency = ( sum ( client_latency * client_throughput <EOL> for client_latency , client_throughput in client_results ) / <EOL> throughput ) <EOL> if latency < <NUM_LIT:1.0> : <EOL> max_throughput_for_completion_latency_under_1ms = max ( <EOL> max_throughput_for_completion_latency_under_1ms , <EOL> throughput ) <EOL> results . append ( sample . Sample ( '<STR_LIT>' , throughput , '<STR_LIT>' , <EOL> { '<STR_LIT>' : latency , '<STR_LIT>' : threads } ) ) <EOL> logging . info ( '<STR_LIT>' , threads , throughput , latency , <EOL> latency_threshold ) <EOL> if threads == <NUM_LIT:1> : <EOL> latency_threshold = latency * <NUM_LIT:20> <EOL> results . append ( sample . Sample ( <EOL> '<STR_LIT>' , <EOL> max_throughput_for_completion_latency_under_1ms , <EOL> '<STR_LIT>' ) ) <EOL> return results <EOL> def Cleanup ( benchmark_spec ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
