You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import time
import spinach
sp = spinach.Engine(spinach.RedisBroker())
@sp.task(name='nap', max_retries=1, max_concurrency=8)
def nap(job_id):
print(f"{job_id:3} Zzzz...")
time.sleep(5)
batch = spinach.Batch()
for i in range(32):
batch.schedule('nap', i)
sp.schedule_batch(batch)
sp.start_workers(32, stop_when_queue_empty=True)
Steps to reproduce
docker-compose -f spinach/tests/docker-compose.yml up -d
Run the script above, it should process the queue 8-at-a-time
Run redis-cli and execute the command HSET spinach/_max_concurrency nap 32
Run the script again
Expected result
The second run of the script runs all 32 tasks simultaneously, like we told it to
Actual behavior
The second run of the script processes the queue 8-at-a-time
Miscellany
This is not a bug; it is 100% intentional behavior, with comments in the set_concurrency_keys.lua script explaining that it is done on purpose.
Our app has several Spinach tasks with max_concurrency set to "baseline" values, and Operations occasionally has a need to tune the values up or down, for reasons.
This is highly inconvenient for things like flask_spinach running under Gunicorn; when Gunicorn cycles out workers, the new workers start and destroy any runtime adjustments to the Redis that operators may have made; and it does so with no warning.
Conversely, it is highly convenient if an Operator wants to, e.g., set a "burst" value for a Spinach task, and immediately forget about it; the software will put itself back on its own.
This one is a bit complicated, but:
Preamble
A test case script:
Steps to reproduce
docker-compose -f spinach/tests/docker-compose.yml up -dredis-cliand execute the commandHSET spinach/_max_concurrency nap 32Expected result
The second run of the script runs all 32 tasks simultaneously, like we told it to
Actual behavior
The second run of the script processes the queue 8-at-a-time
Miscellany
set_concurrency_keys.luascript explaining that it is done on purpose.max_concurrencyset to "baseline" values, and Operations occasionally has a need to tune the values up or down, for reasons.flask_spinachrunning under Gunicorn; when Gunicorn cycles out workers, the new workers start and destroy any runtime adjustments to the Redis that operators may have made; and it does so with no warning._max_concurrencykey, but Issue Jobs without concurrency limits generate current_concurrency hash keys in redis #15 makes it not work very well.Any thoughts and insights on how to best address this would be appreciated.