MySQL上整个Queue?
Opened this issue · 0 comments
bingoohuang commented
问题
思考
劣势:
- Polling轮训MySQL的话显然对性能和负载都不好
- Locking锁机制导致性能低下
- Data Growth也会导致性能低下
优势:
- 不需要其它基础设施,只需要有数据库就行了
- 数据库持久化带来的基础保障
试验
CREATE TABLE `t_job_queue` (
`id` INT NOT NULL AUTO_INCREMENT,
`status` INT NOT NULL DEFAULT '0',
`params` VARCHAR(1024) NOT NULL DEFAULT '',
`result` VARCHAR(1024) NOT NULL DEFAULT '',
`update_id1` INT UNSIGNED NOT NULL DEFAULT '0',
`update_id2` INT UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
# 注意,以下两条SQL必须在同一个会话中完成
UPDATE t_job_queue SET status=STATUS_PROCESSING, id=(@id:=id) WHERE status=0 ORDER BY id ASC LIMIT 1;
SELECT id, status, params FROM t_job_queue WHERE id=@id;
动手测试一番吧
参考
- 5 SUBTLE WAYS YOU'RE USING MYSQL AS A QUEUE, AND WHY IT'LL BITE YOU
- 上文在HackerNews上的讨论
- A job queue in MySQL
- 使用 MySQL 实现无锁任务队列(using MySQL as a job queue)
- The Database As Queue Anti-Pattern
- Durable MySQL-backed queue for Clojure projects
- The best way to use a DB table as a job queue (a.k.a batch queue or message queue)
- WHY MYSQL IS NOT A QUEUE
- Redis Priority Queue offers a priority/timeline based queue for use with Redis
- EBOOK – REDIS IN ACTION Delayed tasks
- Fast circular buffer in MySQL,代码mysql-queue
- Asynchronous Processing in Web Applications, Part 1: A Database Is Not a Queue
- [译]如何优化Quartz调度器性能
- I need a dedicated message queue... or do I?、Rolling your own message/job queue in MySQL (Part 1)、Rolling your own message/job queue in MySQL (Part 2: Message Queue Initial Spec)、Rolling your own message/job queue in MySQL (Part 3: Message Queue Implementation)
- Later is a redis base delay queue
- How to Implement a Queue in SQL
- Creating a Job queue in Innodb