Esempio n. 1
0
    def _run_scenario(self, cls, method, context, args):
        """Runs the specified scenario with given arguments.

        :param cls: The Scenario class where the scenario is implemented
        :param method: Name of the method that implements the scenario
        :param context: context that contains users, admin & other
                        information, that was created before scenario is
                        execution starts.
        :param args: Arguments to call the scenario method with

        :returns: List of results fore each single scenario iteration,
                  where each result is a dictionary
        """
        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        duration = self.config.get("duration")

        # FIXME(andreykurilin): unify `_worker_process`, use it here and remove
        #     usage of `multiprocessing.Pool`(usage of separate process for
        #     each concurrent iteration is redundant).
        pool = multiprocessing.Pool(concurrency)
        manager = multiprocessing.Manager()
        event_queue = manager.Queue()
        stop_event_listener = threading.Event()

        def event_listener():
            while not stop_event_listener.isSet():
                while not event_queue.empty():
                    self.send_event(**event_queue.get())
                else:
                    time.sleep(0.01)

        event_listener_thread = threading.Thread(target=event_listener)
        event_listener_thread.start()

        run_args = butils.infinite_run_args_generator(
            self._iter_scenario_args(cls, method, context, args, event_queue,
                                     self.aborted))
        iter_result = pool.imap(_run_scenario_once_with_unpack_args, run_args)

        start = time.time()
        try:
            while True:
                try:
                    result = iter_result.next(timeout)
                except multiprocessing.TimeoutError as e:
                    result = runner.format_result_on_timeout(e, timeout)
                except StopIteration:
                    break

                self._send_result(result)

                if time.time() - start > duration:
                    break
        finally:
            stop_event_listener.set()
            event_listener_thread.join()
            pool.terminate()
            pool.join()
            self._flush_results()
Esempio n. 2
0
    def _run_scenario(self, cls, method, context, args):
        """Runs the specified scenario with given arguments.

        :param cls: The Scenario class where the scenario is implemented
        :param method: Name of the method that implements the scenario
        :param context: context that contains users, admin & other
                        information, that was created before scenario is
                        execution starts.
        :param args: Arguments to call the scenario method with

        :returns: List of results fore each single scenario iteration,
                  where each result is a dictionary
        """
        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        duration = self.config.get("duration")

        # FIXME(andreykurilin): unify `_worker_process`, use it here and remove
        #     usage of `multiprocessing.Pool`(usage of separate process for
        #     each concurrent iteration is redundant).
        pool = multiprocessing.Pool(concurrency)
        manager = multiprocessing.Manager()
        event_queue = manager.Queue()
        stop_event_listener = threading.Event()

        def event_listener():
            while not stop_event_listener.isSet():
                while not event_queue.empty():
                    self.send_event(**event_queue.get())
                else:
                    time.sleep(0.01)

        event_listener_thread = threading.Thread(target=event_listener)
        event_listener_thread.start()

        run_args = butils.infinite_run_args_generator(
            self._iter_scenario_args(
                cls, method, context, args, event_queue, self.aborted))
        iter_result = pool.imap(_run_scenario_once_with_unpack_args, run_args)

        start = time.time()
        try:
            while True:
                try:
                    result = iter_result.next(timeout)
                except multiprocessing.TimeoutError as e:
                    result = runner.format_result_on_timeout(e, timeout)
                except StopIteration:
                    break

                self._send_result(result)

                if time.time() - start > duration:
                    break
        finally:
            stop_event_listener.set()
            event_listener_thread.join()
            pool.terminate()
            pool.join()
            self._flush_results()
Esempio n. 3
0
    def _run_scenario(self, cls, method, context, args):
        """Runs the specified benchmark scenario with given arguments.

        :param cls: The Scenario class where the scenario is implemented
        :param method: Name of the method that implements the scenario
        :param context: Benchmark context that contains users, admin & other
                        information, that was created before benchmark started.
        :param args: Arguments to call the scenario method with

        :returns: List of results fore each single scenario iteration,
                  where each result is a dictionary
        """
        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        duration = self.config.get("duration")

        # FIXME(andreykurilin): unify `_worker_process`, use it here and remove
        #     usage of `multiprocessing.Pool`(usage of separate process for
        #     each concurrent iteration is redundant).
        pool = multiprocessing.Pool(concurrency)

        run_args = butils.infinite_run_args_generator(
            self._iter_scenario_args(cls, method, context, args, self.aborted))
        iter_result = pool.imap(_run_scenario_once_with_unpack_args, run_args)

        start = time.time()
        while True:
            try:
                result = iter_result.next(timeout)
            except multiprocessing.TimeoutError as e:
                result = runner.format_result_on_timeout(e, timeout)
            except StopIteration:
                break

            self._send_result(result)

            if time.time() - start > duration:
                break

        pool.terminate()
        pool.join()
        self._flush_results()
Esempio n. 4
0
    def _run_scenario(self, cls, method, context, args):
        """Runs the specified benchmark scenario with given arguments.

        :param cls: The Scenario class where the scenario is implemented
        :param method: Name of the method that implements the scenario
        :param context: Benchmark context that contains users, admin & other
                        information, that was created before benchmark started.
        :param args: Arguments to call the scenario method with

        :returns: List of results fore each single scenario iteration,
                  where each result is a dictionary
        """
        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        duration = self.config.get("duration")

        # FIXME(andreykurilin): unify `_worker_process`, use it here and remove
        #     usage of `multiprocessing.Pool`(usage of separate process for
        #     each concurrent iteration is redundant).
        pool = multiprocessing.Pool(concurrency)

        run_args = butils.infinite_run_args_generator(
            self._iter_scenario_args(cls, method, context, args, self.aborted))
        iter_result = pool.imap(_run_scenario_once_with_unpack_args, run_args)

        start = time.time()
        while True:
            try:
                result = iter_result.next(timeout)
            except multiprocessing.TimeoutError as e:
                result = runner.format_result_on_timeout(e, timeout)
            except StopIteration:
                break

            self._send_result(result)

            if time.time() - start > duration:
                break

        pool.terminate()
        pool.join()
        self._flush_results()
    def _run_scenario(self, cls, method, context, args):
        """Runs the specified benchmark scenario with given arguments.

        :param cls: The Scenario class where the scenario is implemented
        :param method_name: Name of the method that implements the scenario
        :param context: Benchmark context that contains users, admin & other
                        information, that was created before benchmark started.
        :param args: Arguments to call the scenario method with

        :returns: List of results fore each single scenario iteration,
                  where each result is a dictionary
        """
        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        duration = self.config.get("duration")
        pause = self.config.get("pause", 0.5)

        pool = multiprocessing.Pool(concurrency)

        run_args = butils.infinite_run_args_generator(
            self._iter_scenario_args(cls, method, context, args,
                                     self.aborted, pause))
        iter_result = pool.imap(_run_scenario_once_with_sleep, run_args)

        start = time.time()
        while True:
            try:
                result = iter_result.next(timeout)
            except multiprocessing.TimeoutError as e:
                result = runner.format_result_on_timeout(e, timeout)
            except StopIteration:
                break

            self._send_result(result)

            if time.time() - start > duration:
                break

        pool.terminate()
        pool.join()
Esempio n. 6
0
 def test_infinite_run_args_generator(self):
     args = lambda x: (x, "a", "b", 123)
     for i, real_args in enumerate(utils.infinite_run_args_generator(args)):
         self.assertEqual((i, "a", "b", 123), real_args)
         if i > 5:
             break
Esempio n. 7
0
 def test_infinite_run_args_generator(self):
     args = lambda x: (x, "a", "b", 123)
     for i, real_args in enumerate(utils.infinite_run_args_generator(args)):
         self.assertEqual((i, "a", "b", 123), real_args)
         if i > 5:
             break