本文整理汇总了Python中oslo_concurrency.processutils.get_worker_count方法的典型用法代码示例。如果您正苦于以下问题:Python processutils.get_worker_count方法的具体用法?Python processutils.get_worker_count怎么用?Python processutils.get_worker_count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_concurrency.processutils
的用法示例。
在下文中一共展示了processutils.get_worker_count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def __init__(self, name, use_ssl=False):
"""Initialize, but do not start the WSGI server.
:param name: The name of the WSGI server given to the loader.
:param use_ssl: Wraps the socket in an SSL context if True.
:returns: None
"""
self.name = name
self.app = app.load_app()
self.workers = (CONF.api.workers or processutils.get_worker_count())
if self.workers and self.workers < 1:
raise exception.ConfigInvalid(
_("api_workers value of %d is invalid, "
"must be greater than 0.") % self.workers)
self.server = wsgi.Server(CONF, name, self.app,
host=CONF.api.host_ip,
port=CONF.api.port,
use_ssl=use_ssl)
示例2: __init__
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def __init__(self, name):
self._host = CONF.api_listen
self._port = CONF.api_listen_port
if platform.system() == "Windows":
self._workers = 1
else:
self._workers = (
CONF.api_workers or processutils.get_worker_count())
self._loader = wsgi.Loader(CONF)
self._app = self._loader.load_app(name)
self._server = wsgi.Server(CONF,
name,
self._app,
host=self._host,
port=self._port)
示例3: test_api_https
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def test_api_https(self, mock_prep, mock_app, mock_run,
mock_exist, mock_base):
self.config(enabled_ssl=True,
ssl_cert_file='tmp_crt',
ssl_key_file='tmp_key',
group='api')
mock_exist.side_effect = [True, True]
api.main()
app = mock_app.load_app.return_value
mock_prep.assert_called_once_with(mock.ANY)
mock_app.load_app.assert_called_once_with()
mock_exist.assert_has_calls([mock.call('tmp_crt'),
mock.call('tmp_key')])
workers = processutils.get_worker_count()
mock_run.assert_called_once_with(base.CONF.api.host,
base.CONF.api.port, app,
processes=workers,
ssl_context=('tmp_crt', 'tmp_key'))
示例4: get_config_opts
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def get_config_opts(cls):
return [
cfg.IntOpt(
'max_workers',
default=processutils.get_worker_count(),
min=1,
required=True,
help='Number of workers for taskflow engine '
'to execute actions.'),
cfg.DictOpt(
'action_execution_rule',
default={},
help='The execution rule for linked actions,'
'the key is strategy name and '
'value ALWAYS means all actions will be executed,'
'value ANY means if previous action executes '
'success, the next action will be ignored.'
'None means ALWAYS.')
]
示例5: __init__
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def __init__(self, name):
self._host = CONF.api_migration_listen
self._port = CONF.api_migration_listen_port
if platform.system() == "Windows":
self._workers = 1
else:
self._workers = (
CONF.api_migration_workers or processutils.get_worker_count())
self._loader = wsgi.Loader(CONF)
self._app = self._loader.load_app(name)
self._server = wsgi.Server(CONF,
name,
self._app,
host=self._host,
port=self._port)
示例6: __init__
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def __init__(self, name, use_ssl=False):
"""Initialize, but do not start the WSGI server.
:param name: The name of the WSGI server given to the loader.
:param use_ssl: Wraps the socket in an SSL context if True.
:returns: None
"""
self.name = name
self.app = app.load_app()
self.workers = (CONF.api.api_workers or
processutils.get_worker_count())
if self.workers and self.workers < 1:
raise exception.ConfigInvalid(
_("api_workers value of %d is invalid, "
"must be greater than 0.") % self.workers)
self.server = wsgi.Server(CONF, self.name, self.app,
host=CONF.api.host_ip,
port=CONF.api.port,
use_ssl=use_ssl)
示例7: __init__
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def __init__(self):
self.app = app.setup_app()
self.workers = CONF.api.api_workers
if self.workers is not None and self.workers < 1:
LOG.warning(
"Value of config option api_workers must be integer "
"greater than 1. Input value ignored."
)
self.workers = None
self.workers = self.workers or processutils.get_worker_count()
self.server = wsgi.Server(
cfg.CONF,
"qinling_api",
self.app,
host=cfg.CONF.api.host,
port=cfg.CONF.api.port,
use_ssl=cfg.CONF.api.enable_ssl_api
)
示例8: run_tasks
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def run_tasks(self):
if not self.upload_tasks:
return
local_images = []
# Pull a single image first, to avoid duplicate pulls of the
# same base layers
local_images.extend(upload_task(args=self.upload_tasks.pop()))
# workers will be half the CPU count, to a minimum of 2
workers = max(2, (processutils.get_worker_count() - 1))
with futures.ThreadPoolExecutor(max_workers=workers) as p:
for result in p.map(upload_task, self.upload_tasks):
local_images.extend(result)
LOG.info('result %s' % local_images)
# Do cleanup after all the uploads so common layers don't get deleted
# repeatedly
self.cleanup(local_images)
示例9: _get_executor
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def _get_executor(self):
"""Get executor type based on lock object
We check to see if the lock object is not set or if it is a threading
lock. We cannot check if it is a ProcessLock due to the side effect
of trying to include ProcessLock when running under Mistral breaks
Mistral.
"""
if not self.lock or isinstance(self.lock, threadinglock.ThreadingLock):
# workers will scale from 2 to 8 based on the cpu count // 2
workers = min(max(2, processutils.get_worker_count() // 2), 8)
return futures.ThreadPoolExecutor(max_workers=workers)
else:
# there really isn't an improvement with > 4 workers due to the
# container layer overlaps. The higher the workers, the more
# RAM required which can lead to OOMs. It's best to limit to 4
return futures.ProcessPoolExecutor(max_workers=4)
示例10: __init__
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def __init__(self, name, loader=None, max_url_len=None):
"""Initialize, but do not start the WSGI server.
:param name: The name of the WSGI server given to the loader.
:param loader: Loads the WSGI application using the given name.
:returns: None
"""
self.name = name
self.manager = self._get_manager()
self.loader = loader or wsgi.Loader()
self.app = self.loader.load_app(name)
self.host = getattr(CONF, '%s_listen' % name, "0.0.0.0")
self.port = getattr(CONF, '%s_listen_port' % name, 0)
self.use_ssl = getattr(CONF, '%s_use_ssl' % name, False)
self.workers = (getattr(CONF, '%s_workers' % name, None) or
processutils.get_worker_count())
if self.workers and self.workers < 1:
worker_name = '%s_workers' % name
msg = (_("%(worker_name)s value of %(workers)s is invalid, "
"must be greater than 0") %
{'worker_name': worker_name,
'workers': str(self.workers)})
raise exception.InvalidInput(msg)
self.server = wsgi.Server(name,
self.app,
host=self.host,
port=self.port,
use_ssl=self.use_ssl,
max_url_len=max_url_len)
# Pull back actual port used
self.port = self.server.port
示例11: test_api_http
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def test_api_http(self, mock_prep, mock_app, mock_run, mock_base):
api.main()
app = mock_app.load_app.return_value
mock_prep.assert_called_once_with(mock.ANY)
mock_app.load_app.assert_called_once_with()
workers = processutils.get_worker_count()
mock_run.assert_called_once_with(base.CONF.api.host,
base.CONF.api.port,
app, processes=workers,
ssl_context=None)
示例12: test_conductor
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def test_conductor(self, mock_prep, mock_rpc, mock_launch):
conductor.main()
server = mock_rpc.Service.create.return_value
launcher = mock_launch.return_value
mock_prep.assert_called_once_with(mock.ANY)
mock_rpc.Service.create.assert_called_once_with(
base.CONF.conductor.topic,
mock.ANY, mock.ANY, binary='magnum-conductor')
workers = processutils.get_worker_count()
mock_launch.assert_called_once_with(base.CONF, server,
workers=workers)
launcher.wait.assert_called_once_with()
示例13: main
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def main():
magnum_service.prepare_service(sys.argv)
gmr.TextGuruMeditation.setup_autorun(version)
LOG.info('Starting server in PID %s', os.getpid())
LOG.debug("Configuration:")
CONF.log_opt_values(LOG, logging.DEBUG)
conductor_id = short_id.generate_id()
endpoints = [
indirection_api.Handler(),
cluster_conductor.Handler(),
conductor_listener.Handler(),
ca_conductor.Handler(),
federation_conductor.Handler(),
nodegroup_conductor.Handler(),
]
server = rpc_service.Service.create(CONF.conductor.topic,
conductor_id, endpoints,
binary='magnum-conductor')
workers = CONF.conductor.workers
if not workers:
workers = processutils.get_worker_count()
launcher = service.launch(CONF, server, workers=workers)
# NOTE(mnaser): We create the periodic tasks here so that they
# can be attached to the main process and not
# duplicated in all the children if multiple
# workers are being used.
server.create_periodic_tasks()
server.start()
launcher.wait()
示例14: main
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def main():
service.prepare_service(sys.argv)
gmr.TextGuruMeditation.setup_autorun(version)
# Enable object backporting via the conductor
base.MagnumObject.indirection_api = base.MagnumObjectIndirectionAPI()
app = api_app.load_app()
# Setup OSprofiler for WSGI service
profiler.setup('magnum-api', CONF.host)
# SSL configuration
use_ssl = CONF.api.enabled_ssl
# Create the WSGI server and start it
host, port = CONF.api.host, CONF.api.port
LOG.info('Starting server in PID %s', os.getpid())
LOG.debug("Configuration:")
CONF.log_opt_values(LOG, logging.DEBUG)
LOG.info('Serving on %(proto)s://%(host)s:%(port)s',
dict(proto="https" if use_ssl else "http", host=host, port=port))
workers = CONF.api.workers
if not workers:
workers = processutils.get_worker_count()
LOG.info('Server will handle each request in a new process up to'
' %s concurrent processes', workers)
serving.run_simple(host, port, app, processes=workers,
ssl_context=_get_ssl_configs(use_ssl))
示例15: test_workers_set_default
# 需要导入模块: from oslo_concurrency import processutils [as 别名]
# 或者: from oslo_concurrency.processutils import get_worker_count [as 别名]
def test_workers_set_default(self):
test_service = service.WSGIService("masakari_api")
self.assertEqual(test_service.workers, processutils.get_worker_count())