本文整理汇总了Python中perfrunner.helpers.remote.RemoteHelper.terminate_client_processes方法的典型用法代码示例。如果您正苦于以下问题:Python RemoteHelper.terminate_client_processes方法的具体用法?Python RemoteHelper.terminate_client_processes怎么用?Python RemoteHelper.terminate_client_processes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类perfrunner.helpers.remote.RemoteHelper
的用法示例。
在下文中一共展示了RemoteHelper.terminate_client_processes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from perfrunner.helpers.remote import RemoteHelper [as 别名]
# 或者: from perfrunner.helpers.remote.RemoteHelper import terminate_client_processes [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()