Skip to content

Commit

Permalink
Offload threads.
Browse files Browse the repository at this point in the history
  • Loading branch information
idlesign committed Jul 12, 2017
1 parent dadd019 commit 77acb5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/options/test_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_workers_basics(assert_lines):

assert_lines([
'threads = 2',
], Section().workers.set_thread_params(per_worker=2))
], Section().workers.set_thread_params(count=2))

assert_lines([
'min-worker-lifetime = 10',
Expand Down
21 changes: 16 additions & 5 deletions uwsgiconf/options/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,43 @@ def set_count_auto(self, count=None):

return self._section

def set_thread_params(self, enable_threads=None, per_worker=None, stack_size=None, no_wait=None):
def set_thread_params(
self, enable_threads=None, count=None, count_offload=None, stack_size=None, no_wait=None):
"""Sets threads related params.
:param bool enable_threads: Enable threads in the embedded languages.
This will allow to spawn threads in your app.
Threads will simply *not work* if this option is not enabled. There will likely be no error,
just no execution of your thread code.
:param int per_worker: Run each worker in prethreaded mode with the specified number
:param int count: Run each worker in prethreaded mode with the specified number
of threads per worker.
.. warning:: Do not use with ``gevent``.
.. note:: Enables threads automatically.
:param int count_offload: Set the number of threads (per-worker) to spawn
for offloading. Default: 0.
These threads run such tasks in a non-blocking/evented way allowing
for a huge amount of concurrency. Various components of the uWSGI stack
are offload-friendly.
* http://uwsgi-docs.readthedocs.io/en/latest/OffloadSubsystem.html
:param int stack_size: Set threads stacksize.
:param bool no_wait: Do not wait for threads cancellation on quit/reload.
"""
self._set('enable-threads', enable_threads, cast=bool)
self._set('no-threads-wait', no_wait, cast=bool)
self._set('threads', per_worker)
self._set('threads', count)
self._set('offload-threads', count_offload)

if per_worker:
self._section.print_out('Threads per worker: %s' % per_worker)
if count:
self._section.print_out('Threads per worker: %s' % count)

self._set('threads-stacksize', stack_size)

Expand Down
2 changes: 1 addition & 1 deletion uwsgiconf/presets/nice.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, name=None, touch_reload=None, workers=None, threads=None, mul
else:
self.workers.set_count_auto()

self.workers.set_thread_params(per_worker=threads)
self.workers.set_thread_params(count=threads)
self.workers.set_mules_params(mules=mules)
self.main_process.set_basic_params(vacuum=True)
self.main_process.set_naming_params(autonaming=True)
Expand Down

0 comments on commit 77acb5a

Please sign in to comment.