Delayq
DelayQ is a Go library that provides a performant, reliable, distributed delay-queue using Redis.
Install / Use
/learn @spy16/DelayqREADME
DelayQ
DelayQ is a Go library that provides job-queue (time-constrained) primitives.
Currently following implementations are supported:
inmem.DelayQ: An in-memory queue using modified min-heap for time-constrained dequeue.redis.DelayQ: A production-tested queue using Redis (supports both single-node & cluster) that uses sorted-sets.sql.DelayQ: An implementation backed by any SQL database.
Features
- Simple - More like a queue primitive to build job-queue instead of being a feature-rich job-queue system.
- Distributed (with
redisorsqldb) - Multiple producer/consumer processes connect to a Redis node or cluster. - Reliable -
at-least-oncesemantics (exactly-once in most cases except for when there are worker crashes) - Good performance (See Benchmarks).
Usage
For enqueueing items on the delay queue:
package main
func main() {
err := dq.Enqueue(context.Background(), []delayq.Item{
{
At: time.Now().Add(1 * time.Hour),
Value: "Item 1!",
},
{
At: time.Now().Add(2 * time.Hour),
Value: "Item 2!",
},
}...)
}
Creating a worker to process:
package main
import "github.com/spy16/delayq"
func worker(dq delayq.DelayQ) {
w := &delayq.Worker{
Queue: dq,
Invoke: onReady,
}
// run worker threads that invoke myFunc for every item.
if err := w.Run(context.Background()); err != nil {
log.Fatalf("run exited: %v", err)
}
}
func onReady(ctx context.Context, item delayq.Item) error {
log.Printf("got message: %v", item)
return nil
}
Benchmarks
Benchmarks can be re-produced using the example application in ./example.
Following are few actual benchmark results that I got:
Both Redis and worker are running on single node with following specs:
- CPU :
2.8 GHz Quad-Core Intel Core i7- Memory:
16 GB 2133 MHz LPDDR3
- With 3 worker processes (30 goroutines, prefetch count 100, poll interval 5ms):
- 10k jobs are delivered on the exact requested second (~3300 req/second each.)
- 100k jobs are delivered within 3 seconds. (upto 12000 req/second each.)
- With 2 worker processes (20 goroutines, prefetch count 1000, poll interval 5ms):
- 10k jobs are delivered on the exact requested second (~5000 req/second each.)
- 100k jobs are delivered within 3 seconds. (upto 20000 req/second each.)
Related Skills
node-connect
339.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR
