def Run()

in perfkitbenchmarker/linux_packages/mcperf.py [0:0]


def Run(vms, server_ip, server_port, num_instances):
  """Runs the mcperf benchmark on the vm."""
  samples = []
  master = vms[0]
  runtime_options = {}
  samples = []
  measure_flags = []
  additional_flags = ['--%s' % option for option in FLAGS.mcperf_options]

  if FLAGS.mcperf_measure_connections:
    runtime_options['measure_connections'] = FLAGS.mcperf_measure_connections
    measure_flags.append(
        '--measure_connections=%s' % FLAGS.mcperf_measure_connections
    )
  if FLAGS.mcperf_measure_threads:
    runtime_options['measure_threads'] = FLAGS.mcperf_measure_threads
  if FLAGS.mcperf_measure_qps:
    runtime_options['measure_qps'] = FLAGS.mcperf_measure_qps
    measure_flags.append('--measure_qps=%s' % FLAGS.mcperf_measure_qps)
  if FLAGS.mcperf_measure_depth:
    runtime_options['measure_depth'] = FLAGS.mcperf_measure_depth
    measure_flags.append('--measure_depth=%s' % FLAGS.mcperf_measure_depth)

  for thread_count in FLAGS.mcperf_threads:
    runtime_options['threads'] = thread_count
    for vm in vms[1:]:
      RestartAgent(vm, thread_count)
    for connection_count in FLAGS.mcperf_connections:
      runtime_options['connections'] = connection_count
      for depth in FLAGS.mcperf_depths:
        runtime_options['depth'] = depth

        target_qps_list = FLAGS.mcperf_qps[:] or [0]
        while True:
          target_qps = int(target_qps_list[0])
          runtime_options['qps'] = target_qps or 'peak'
          remote_agents = ['--agent=%s' % vm.internal_ip for vm in vms[1:]]
          cmd = BuildCmd(
              server_ip,
              server_port,
              num_instances,
              [
                  '--noload',
                  '--qps=%s' % target_qps,
                  '--time=%s' % FLAGS.mcperf_time,
                  '--update=%s' % FLAGS.mcperf_ratio,
                  '--threads=%s'
                  % (FLAGS.mcperf_measure_threads or thread_count),
                  '--connections=%s' % connection_count,
                  '--depth=%s' % depth,
              ]
              + remote_agents
              + measure_flags
              + additional_flags,
          )

          try:
            stdout, _, retcode = master.RemoteHostCommandWithReturnCode(
                ' '.join(cmd),
                timeout=FLAGS.mcperf_time * 2,
                ignore_failure=True,
            )
          except errors.VmUtil.IssueCommandTimeoutError:
            break
          if retcode:
            break
          metadata = GetMetadata()
          metadata.update(runtime_options)
          run_samples, actual_qps = ParseResults(stdout, metadata)
          samples.extend(run_samples)

          if _INCREMENTAL_LOAD.value and (
              actual_qps / target_qps > (1 - _INCREMENTAL_LOAD.value * 2)
          ):
            target_qps_list.append(
                int(target_qps) * (1 + _INCREMENTAL_LOAD.value)
            )
          target_qps_list.pop(0)
          if not target_qps_list:
            break
  return samples