예제 #1
0
 def testSetGet(self):
     benchmark_spec = mock.MagicMock()
     context.SetThreadBenchmarkSpec(benchmark_spec)
     self.assertEqual(benchmark_spec, context.GetThreadBenchmarkSpec())
예제 #2
0
  def _GetTags(self):
    """Gets a list of tags to be used with the --tags param of Azure CLI."""
    benchmark_spec = context.GetThreadBenchmarkSpec()
    tags = self.FormatTags(benchmark_spec.GetResourceTags(self.timeout_minutes))

    return tags
예제 #3
0
 def __init__(self):
     self.benchmark_spec = context.GetThreadBenchmarkSpec()
     self.log_context = log_util.GetThreadLogContext()
예제 #4
0
 def __init__(self, container_spec, name, resource_group):
     super(AciContainer, self).__init__(container_spec)
     self.name = name
     self.resource_group = resource_group
     benchmark_spec = context.GetThreadBenchmarkSpec()
     self.registry = benchmark_spec.container_registry
예제 #5
0
def RunParallelThreads(target_arg_tuples, max_concurrency):
    """Executes function calls concurrently in separate threads.

  Args:
    target_arg_tuples: list of (target, args, kwargs) tuples. Each tuple
        contains the function to call and the arguments to pass it.
    max_concurrency: int or None. The maximum number of concurrent new
        threads.

  Returns:
    list of function return values in the order corresponding to the order of
    target_arg_tuples.

  Raises:
    errors.VmUtil.ThreadException: When an exception occurred in any of the
        called functions.
  """
    queue = Queue.Queue()
    log_context = log_util.GetThreadLogContext()
    benchmark_spec = context.GetThreadBenchmarkSpec()
    max_concurrency = min(max_concurrency, len(target_arg_tuples))
    results = [None] * len(target_arg_tuples)
    error_strings = []
    for call_id in xrange(max_concurrency):
        target_arg_tuple = target_arg_tuples[call_id]
        thread = threading.Thread(target=_ExecuteThreadCall,
                                  args=(target_arg_tuple, call_id, queue,
                                        log_context, benchmark_spec))
        thread.daemon = True
        thread.start()
    active_thread_count = max_concurrency
    next_call_id = max_concurrency
    while active_thread_count:
        try:
            # Using a timeout makes this wait interruptable.
            call_id, result, stacktrace = queue.get(block=True, timeout=1000)
        except Queue.Empty:
            continue
        results[call_id] = result
        if stacktrace:
            msg = ('Exception occurred while calling {0}:{1}{2}'.format(
                _GetCallString(target_arg_tuples[call_id]), os.linesep,
                stacktrace))
            logging.error(msg)
            error_strings.append(msg)
        if next_call_id == len(target_arg_tuples):
            active_thread_count -= 1
        else:
            target_arg_tuple = target_arg_tuples[next_call_id]
            thread = threading.Thread(target=_ExecuteThreadCall,
                                      args=(target_arg_tuple, next_call_id,
                                            queue, log_context,
                                            benchmark_spec))
            thread.daemon = True
            thread.start()
            next_call_id += 1
    if error_strings:
        raise errors.VmUtil.ThreadException(
            'The following exceptions occurred during threaded execution:'
            '{0}{1}'.format(os.linesep, os.linesep.join(error_strings)))
    return results