当前位置: 首页>>代码示例>>Python>>正文


Python RemoteHelper.start_celery_worker方法代码示例

本文整理汇总了Python中perfrunner.helpers.remote.RemoteHelper.start_celery_worker方法的典型用法代码示例。如果您正苦于以下问题:Python RemoteHelper.start_celery_worker方法的具体用法?Python RemoteHelper.start_celery_worker怎么用?Python RemoteHelper.start_celery_worker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在perfrunner.helpers.remote.RemoteHelper的用法示例。


在下文中一共展示了RemoteHelper.start_celery_worker方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from perfrunner.helpers.remote import RemoteHelper [as 别名]
# 或者: from perfrunner.helpers.remote.RemoteHelper import start_celery_worker [as 别名]
class RemoteWorkerManager:

    WORKER_HOME = '/tmp/perfrunner'

    PING_INTERVAL = 1

    def __init__(self, cluster_spec: ClusterSpec, test_config: TestConfig,
                 verbose: bool):
        self.cluster_spec = cluster_spec
        self.test_config = test_config
        self.remote = RemoteHelper(cluster_spec, verbose)

        self.workers = cycle(self.cluster_spec.workers)

        self.terminate()
        self.start()
        self.wait_until_workers_are_ready()

    @property
    def is_remote(self) -> bool:
        return True

    def next_worker(self) -> str:
        return next(self.workers)

    def reset_workers(self):
        self.workers = cycle(self.cluster_spec.workers)

    def start(self):
        logger.info('Initializing remote worker environment')
        self.remote.init_repo(self.WORKER_HOME)

        for worker in self.cluster_spec.workers:
            logger.info('Starting remote Celery worker, host={}'.format(worker))
            perfrunner_home = os.path.join(self.WORKER_HOME, 'perfrunner')
            self.remote.start_celery_worker(worker, perfrunner_home)

    def wait_until_workers_are_ready(self):
        workers = ['[email protected]{}'.format(worker)
                   for worker in self.cluster_spec.workers]
        while True:
            responses = celery.control.ping(workers)
            if len(responses) == len(workers):
                break
            time.sleep(self.PING_INTERVAL)
        logger.info('All remote Celery workers are ready')

    def run_tasks(self,
                  task: Callable,
                  task_settings: PhaseSettings,
                  target_iterator: TargetIterator,
                  timer: int = None):
        if self.test_config.test_case.reset_workers:
            self.reset_workers()

        self.async_results = []
        for target in target_iterator:
            for instance in range(task_settings.workload_instances):
                worker = self.next_worker()
                logger.info('Running the task on {}'.format(worker))
                async_result = task.apply_async(
                    args=(task_settings, target, timer, instance),
                    queue=worker, expires=timer,
                )
                self.async_results.append(async_result)

    def wait_for_workers(self):
        logger.info('Waiting for all tasks to finish')
        for async_result in self.async_results:
            async_result.get()
        logger.info('All tasks are done')

    def download_celery_logs(self):
        if not os.path.exists('celery'):
            os.mkdir('celery')
        self.remote.get_celery_logs(self.WORKER_HOME)

    def abort(self):
        pass

    def terminate(self):
        logger.info('Terminating Celery workers')
        self.remote.terminate_client_processes()
开发者ID:couchbase,项目名称:perfrunner,代码行数:85,代码来源:worker.py


注:本文中的perfrunner.helpers.remote.RemoteHelper.start_celery_worker方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。