The uWSGI queue framework¶
In addition to the caching framework, uWSGI includes a shared queue.
At the low level it is a simple block-based shared array, with two optional counters, one for stack-style, LIFO usage, the other one for FIFO.
The array is circular, so when one of the two pointers reaches the end (or the beginning), it is reset. Remember this!
To enable the queue, use the queue option. Queue blocks are 8 KiB by default. Use queue-blocksize to change this.
# 100 slots, 8 KiB of data each
uwsgi --socket :3031 --queue 100
# 42 slots, 128 KiB of data each
uwsgi --socket :3031 --queue 42 --queue-blocksize 131072
Using the queue as a FIFO queue¶
Note
Currently you can only pull, not push. To enqueue an item, use uwsgi.queue_set().
# Grab an item from the queue
uwsgi.queue_pull()
# Get the current pull/slot position (this is independent from the stack-based one)
print uwsgi.queue_pull_slot()
Notes¶
- You can get the queue size with uwsgi.queue_size.
- Use the queue-store option to persist the queue on disk. Use queue-store-sync (in master cycles – usually seconds) to force disk syncing of the queue.
- The tests/queue.py application is a fully working example.