def AllocProcessToCores(start_core, end_core, out, proc_command): """Allocate processes to designated stretch of cores. Always runs a process in background curently. Args: start_core: the start of the stretch of cores to allocate to the process. end_core: the end of the stretch of cores to allocate to the process. out: file name or output stream for redirection purpose. proc_command: the command to run on designated cores. Returns: The taskset process id is returned """ taskset_command_args = ["-ac", "{}-{}".format(start_core, end_core)] taskset_command_args.extend(proc_command) taskset_proc = Process("taskset", out, args=taskset_command_args) taskset_proc.RunProcess() return taskset_proc
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("envoy_binary_path", help="the path to the binary file of Envoy") parser.add_argument("envoy_config_path", help="the path to the config file which Envoy should use") parser.add_argument("result", help="the name of the result file where benchmarking " "results will be written") parser.add_argument("--nginx_cores", help="the start and end core numbers for Nginx server to " "run, separated by a comma.", default="0,10") parser.add_argument("--envoy_cores", help="the start and end core numbers for" " Envoy to run, separated by a comma.", default="11,18") parser.add_argument("--h2load_cores", help="the start and end core numbers for " "h2load to run, separated by a comma.", default="19,19") parser.add_argument("--h2load_warmup", help="period of time in seconds to warm up for h2load", default="5") parser.add_argument("--h2load_clients", help="number of h2load clients.", default="10") parser.add_argument("--h2load_con_conn", help=("number of h2load concurrent" " connections."), default="10") parser.add_argument("--h2load_duration", help=("period of time in seconds for" " measurements in h2load"), default="5") # TODO(sohamcodes): range for port number should be checked parser.add_argument("--direct_port", help="the direct port for benchmarking.", type=int, default=4500) parser.add_argument("--envoy_port", help="the Envoy proxy port for benchmarking", type=int, default=9000) parser.add_argument("--num_iter", help="the number of times h2load will be run", type=int, default=5) parser.add_argument("--h2load_timeout", help="the maximum number of seconds to wait for h2load" " to return some result", type=int, default=120) parser.add_argument("--arrangement", help=("the type of arrangement in" " this experiment."), default="single-vm-permanent") utils.CreateBooleanArgument(parser, "ssl", ("turn on if you want" " to enable ssl for the benchmarking"), ssl=True) utils.CreateBooleanArgument(parser, "h1", ("turn on if you want" " to enable HTTP1.1, instead of default h2"), h1=False) args = parser.parse_args() print args.h1 if args.nginx_cores: nginx_start_core, nginx_end_core = args.nginx_cores.split(",") if args.envoy_cores: envoy_start_core, envoy_end_core = args.envoy_cores.split(",") if args.h2load_cores: h2load_start_core, h2load_end_core = args.h2load_cores.split(",") h2load_threads = int(h2load_end_core) - int(h2load_start_core) + 1 # allocate nginx to designated cores output = "nginx_out.log" nginx_command = ["nginx"] nginx_command.extend(GetNginxCommandLineArguments()) nginx_process = AllocProcessToCores(nginx_start_core, nginx_end_core, output, nginx_command) print "nginx process id is {}".format(nginx_process.pid) # allocate envoy to designated cores envoy_thread_number = int(envoy_end_core) - int(envoy_start_core) + 1 envoy_command = [args.envoy_binary_path] envoy_command.extend(GetEnvoyCommandLineArguments(args.envoy_config_path, envoy_thread_number)) outfile = "envoy_out.log" # this is envoy output file envoy_process = AllocProcessToCores(envoy_start_core, envoy_end_core, outfile, envoy_command) print "envoy process id is {}".format(envoy_process.pid) result_json = defaultdict(list) logfile = open("h2load_log.log", "ab+") mplog_direct = open("mpstat_direct.log", "ab+") mplog_envoy = open("mpstat_envoy.log", "ab+") cores_string = "{},{},{}".format( GetCoreRange(nginx_start_core, nginx_end_core), GetCoreRange(h2load_start_core, h2load_end_core), GetCoreRange(envoy_start_core, envoy_end_core)) for _ in xrange(args.num_iter): # allocate h2load to designated cores as foreground process mpstat_direct = Process("mpstat -P {} 1".format( cores_string), mplog_direct) mpstat_direct.RunProcess() h2load_command = ("taskset -ac {}-{} " "h2load http{ssl}://localhost:{} -n 0 --warm-up-time {}" " -c{} -D {} -t{} -m{} {http2}").format( h2load_start_core, h2load_end_core, args.direct_port, args.h2load_warmup, args.h2load_clients, args.h2load_duration, h2load_threads, args.h2load_con_conn, ssl="s" if args.ssl else "", http2="--h1" if args.h1 else "") result_json["direct-{}".format(args.arrangement)].append(RunAndParseH2Load( h2load_command, args.h2load_timeout, logfile=logfile)) mpstat_direct.KillProcess("-SIGINT") print "h2load direct is done." mpstat_envoy = Process("mpstat -P {} 1".format( cores_string), mplog_envoy) mpstat_envoy.RunProcess() h2load_command = ("taskset -ac {}-{} " "h2load http{ssl}://localhost:{} -n 0 --warm-up-time {}" " -c{} -D {} -t{} -m{} {http2}").format( h2load_start_core, h2load_end_core, args.envoy_port, args.h2load_warmup, args.h2load_clients, args.h2load_duration, h2load_threads, args.h2load_con_conn, ssl="s" if args.ssl else "", http2="--h1" if args.h1 else "") result_json["envoy-{}".format(args.arrangement)].append(RunAndParseH2Load( h2load_command, args.h2load_timeout, logfile=logfile)) mpstat_envoy.KillProcess("-SIGINT") print "h2load with envoy is done." # killing nginx, envoy processes nginx_process.KillProcess("-QUIT") envoy_process.KillProcess() with open(args.result, "w") as f: json.dump(result_json, f)