Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer...
Transcript of Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer...
![Page 1: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/1.jpg)
Redis as a Reliable Work Queue Percona University 2015-02-12
![Page 2: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/2.jpg)
Introduction
Tom DeWire Principal Software Engineer Bronto Software
Chris Thunes Senior Software Engineer Bronto Software
![Page 3: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/3.jpg)
Introduction
![Page 4: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/4.jpg)
Introduction
![Page 5: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/5.jpg)
Introduction
Bronto Features
§ Communication • Email • Social • SMS
§ Contact Management
• Manual • Segmentation
§ Marketing Automation • Workflows
§ Commerce Integration • Purchase History • Cart Recovery
§ Integration
• SOAP/REST API • Third Party Connectors
![Page 6: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/6.jpg)
Introduction
Cyber Monday 2014
Peak Daily Totals
Peak Hourly Totals
Emails Sent Events Processed
~170M per Day ~400M per Day
~2000 per Second ~4700 per Second
Emails Sent Events Processed
~14M per Hour ~32M per Hour
~3900 per Second ~8900 per Second
![Page 7: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/7.jpg)
Distributed Work Queueing
Service
Service
Service
Client
Local work queues…
![Page 8: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/8.jpg)
Distributed Work Queueing
Service
Service
Service
Client
Lost or Orphaned
Excessive Growth
Local work queues…handle failure poorly
![Page 9: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/9.jpg)
Distributed Work Queueing
Service
Service
Service
Client
UnbalancedGrowth
Local work queues…handle unbalanced loads poorly
![Page 10: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/10.jpg)
Distributed Work Queueing
Service
Service
Service
Client
Local work queues… may be bad neighbors
![Page 11: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/11.jpg)
Distributed Work Queueing
Service
Service
Service
Client
What about putting the work in a relational database?
![Page 12: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/12.jpg)
Distributed Work Queueing
Service
Service
Service
Client
What about putting the work in a relational database?
Please don’t do that…
Why are they doing this to
me?
![Page 13: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/13.jpg)
Distributed Work Queueing
Service Producer Client
Service Consumer
Queue
Distributed work queues…
![Page 14: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/14.jpg)
Distributed Work Queueing
Service Producer
Service Producer
Service Producer
Client
Service Consumer
Service Consumer
Service Consumer
Service Consumer
Service Consumer
Queue
Distributed work queues…decouple producers and consumers
![Page 15: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/15.jpg)
Distributed Work Queueing
Service Producer
Service Producer
Service Producer
Client
Service Consumer
Service Consumer
Service Consumer
Service Consumer
Service Consumer
Queue
Distributed work queues…are more fault tolerant
![Page 16: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/16.jpg)
Distributed Work Queueing
Service Producer
Service Producer
Client
Service Consumer
Service Consumer
Queue
Queue
Distributed work queues… partition for availability and/or scale
![Page 17: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/17.jpg)
Distributed Work Queueing
Great… But where can I get one?
§ Kafka § Kestrel § Starling § BeanstalkD § SwiftMQ § RabbitMQ § ActiveMQ § Qpid § Apollo § SQS (Simple Queue Service) § …and lots more I’ve simply forgotten or ignored
There are plenty of options in this space.
![Page 18: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/18.jpg)
Distributed Work Queueing
Why did we go with Redis?
§ Existing deployment § Existing operational experience § Existing development experience § Works well without specialized hardware § Favorable balance of throughput vs. durability § Flexibility to support alternate queue schemes (e.g. with key-
based aggregation)
We don’t regret building this on Redis, and we feel it will be a solid contribution to the open source ecosystem.
![Page 19: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/19.jpg)
Redis
The fundamentals…
§ NoSQL database § Key/Value style § Data structures § Memory only § Durable to disk § Fast, fast, fast
![Page 20: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/20.jpg)
Redis
Under the covers…
§ C application § Single threaded § Strongly consistent § Durability via snapshots (RDB) § Durability via redo logs (AOF) § Scriptable on server-side (LUA) § Simple protocol § Replication
![Page 21: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/21.jpg)
Redis
Is it ACID? No… Single Operations
§ Atomic § Consistent § Isolated
Multi Operation Transactions
§ Atomic § Isolated Server Scripted Transactions § Atomic § Isolated Redis is not consistent per ACID because it does not support rollbacks. Redis is not durable per ACID because it does not require persistence to disk.
![Page 22: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/22.jpg)
Redis
Durability in Redis RDB (Redis Database)
§ Point in time snapshot § Scheduled or on-demand § Performed in a forked process § Compact file format § Fastest restore time § Larger window for data loss
There are workloads that can make good use of the scheduled and/or explicit RDB snapshots, but the queue case is not one of them.
![Page 23: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/23.jpg)
Redis
Durability in Redis AOF (Append Only File)
§ Streaming log of operations § Periodic log rewriting from live data via fork § Reduced chance of corruption due to append only strategy § Multiple fsync() policies
• Never • Every second • Every operation
§ Slightly reduced performance due to more frequent disk interaction
AOF with the ‘every second’ fsync policy is a good fit for us.
§ No expected data loss due to process failure § One second of potential data loss due to machine failure
![Page 24: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/24.jpg)
Redis
Naïve Queueing
Service Producer
Service Consumer
Producer creates work payload
work
![Page 25: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/25.jpg)
Redis
Naïve Queueing
Service Producer
Service Consumer
LPUSH my_queue work
my_queue (list) work
![Page 26: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/26.jpg)
Redis
Naïve Queueing
Service Producer
Service Consumer
RPOP my_queue
my_queue (list)
work
![Page 27: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/27.jpg)
Redis
Naïve Queueing
Service Producer
Service Consumer
Consumer processes work
work
![Page 28: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/28.jpg)
Redis
Naïve Queueing
Service Producer
Service Consumer
…but what if something goes wrong?
work
![Page 29: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/29.jpg)
Reliable Queueing
Created Pending Working enqueue
Complete dequeue release
requeue
Created Pending enqueue
Complete dequeue
Naïve Queueing
Reliable Queueing
Delayed
delay time
![Page 30: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/30.jpg)
Reliable Queueing
Redis and LUA Scripting
Think of it as a stored procedure. § Loaded via EVAL § Invoked via EVALSHA § Atomic execution
-- Move the ready UUIDs from the delayed set back into the pending list. -- These UUIDs are ready when their ZSCORE is less than that of the current time "now", -- passed in as a parameter to this function. -- They will be added back to the front of the pending list, rather than the end of it. local function requeueDelayed(pendingList, delayedZSet, now) -- Get the UUIDs of the items ready to be requeued from the delayed set local ready_uuids = redis.call('ZRANGEBYSCORE', delayedZSet, 0, now) if #ready_uuids == 0 then return 0 end -- Move the items from the delayed set to the front of the pending list zrem_safe(delayedZSet, ready_uuids) rpush_safe(pendingList, ready_uuids) return #ready_uuids end
![Page 31: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/31.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
enqueue()
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
![Page 32: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/32.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
enqueue() 1. Generate {UUID} 2. LPUSH my_queue_pending {UUID} 3. HSET my_queue_values {UUID} {work}
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID
![Page 33: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/33.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
The work is now in the pending state.
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID
![Page 34: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/34.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
dequeue()
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID
![Page 35: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/35.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
dequeue() 1. RPOP my_queue_pending 2. ZADD my_queue_working {timestamp} {UUID} 3. HGET my_queue_values {UUID} 4. Return {work} to consumer
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID
work
UUID
![Page 36: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/36.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
The work is now in the working state, safely dequeued, with an immutable copy still on the Redis server.
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID
work
![Page 37: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/37.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
release()
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID
![Page 38: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/38.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
release() 1. ZREM my_queue_working {UUID} 2. HDEL my_queue_values {UUID}
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID
![Page 39: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/39.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
The work is now in the completed state, completely processed, with no copy remaining in Redis.
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
![Page 40: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/40.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
What if something goes wrong during processing?
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID
work
![Page 41: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/41.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
requeue()
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID
![Page 42: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/42.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
requeue() 1. ZREM {UUID} 2. LPUSH {UUID}
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID
UUID
![Page 43: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/43.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
The work has now returned to the pending state, and will be reissued as soon as it returns to the head of the queue.
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work UUID
UUID
![Page 44: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/44.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
What if something really goes wrong during processing?
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID
work
![Page 45: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/45.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
sweep()
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID work
Service Consumer
![Page 46: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/46.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
sweep() 1. ZRANGEBYSCORE my_queue_working 0 {timestamp – stale} 2. LPUSH my_queue_pending {UUIDs} 3. ZREM {UUIDs}
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID work
Service Consumer
UUID
![Page 47: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/47.jpg)
Redis
Reliable Queueing
Service Producer
Service Consumer
The work has now returned to the pending state, and will be reissued as soon as it returns to the head of the queue.
my_queue (LUA)
my_queue_pending (LIST)
my_queue_values (MAP)
my_queue_working (ZSET)
work
UUID
UUID work
Service Consumer
![Page 48: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/48.jpg)
Reliable Queueing
The real implementation does a lot more…
§ Asynchronous API § Operation pipelining § Opportunistic batching § Pre-fetching § Per-item deferment § Per-item statistics
• Enqueue time • Dequeue time / count • Requeue time / count
§ Metrics instrumentation • Queue throughput & timing • Batching effectiveness
• Queue size • Queue lag
![Page 49: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/49.jpg)
Reliable Queueing
Some benchmarks…
§ Bronto’s Redis Client implementation § Bronto’s Reliable Queue implementation § Redis running on Intel(R) Xeon(R) CPU E5-2430 @ 2.20GHz § All tests are single threaded, with one connection § All tests use single byte queue name and item payload
Scenario Enqueue Dequeue & Release
No pipelining, No batching
6,700 items/sec 2,900 items/sec
Pipelining (1024), No batching
62,040 items/sec 14,029 items/sec
Pipelining (1024), Batching (256)
236,922 items/sec 70,706 items/sec
![Page 50: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/50.jpg)
Bronto Open Source
We are planning on releasing the entire suite to the open source community.
§ Redis Client • Asynchronous • Pipelining • Protocol access • Scripting supports
§ Redis Benchmarking Tools
• Scriptable benchmark runs • Support for rapid LUA iteration and testing
§ Bronto’s Reliable Queue implementation • Everything you just heard about
![Page 51: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/51.jpg)
Bronto Open Source
We are planning on releasing the entire suite to the open source community.
§ Redis Client • Asynchronous • Pipelining • Protocol access • Scripting supports
§ Redis Benchmarking Tools
• Scriptable benchmark runs • Support for rapid LUA iteration and testing
§ Bronto’s Reliable Queue implementation • Everything you just heard about
Coming this Spring.
![Page 52: Redis as a Reliable Work Queue - Percona Redis as a... · Redis Reliable Queueing Service Producer ... Bronto’s Reliable Queue implementation ! Redis running on Intel(R) Xeon(R)](https://reader030.fdocuments.net/reader030/viewer/2022012313/5b1654a17f8b9a776d8b51ff/html5/thumbnails/52.jpg)
Thanks for listening!
Questions?