当前位置:网站首页>Common implementation schemes of delay message
Common implementation schemes of delay message
2022-04-23 22:01:00 【InfoQ】
Preface
Implementation scheme
1. Scheme based on external storage

be based on database ( Such as MySQL)
CREATE TABLE `delay_msg` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`delivery_time` DATETIME NOT NULL COMMENT ' Delivery time ',
`payloads` blob COMMENT ' The message content ',
PRIMARY KEY (`id`),
KEY `time_index` (`delivery_time`)
)- Implement a simple ;
- B+Tree The index is not suitable for a large number of writes in the message scenario ;
be based on RocksDB

- RocksDB LSM The tree is very suitable for a large number of message scenarios ;
- The implementation scheme is heavy , If you adopt this scheme , You have to implement it yourself RocksDB Data disaster recovery logic ;
be based on Redis

- Messages Pool All delay messages are stored , The structure is KV structure ,key For message ID,value For a specific message( Choose here Redis Hash The structure is mainly because hash Structure can store a large amount of data , When there is a lot of data, it will be carried out gradually rehash Capacity expansion , And for the HSET and HGET The time complexity of commands is O(1))
- Delayed Queue yes 16 An ordered queue ( The queue supports horizontal expansion ), The structure is ZSET,value by messages pool Chinese News ID,score For expiration time **( It is divided into multiple queues to improve the scanning speed )**
- Worker Represents a processing thread , Scan through scheduled tasks Delayed Queue Messages due in
- Redis ZSET It is very suitable for implementing delay queue
- Performance issues , although ZSET Insert is a O(logn) The operation of , however Redis Based on memory operation , And many internal performance optimizations have been made .
Defects and improvement of timed thread inspection
2. Open source MQ Implementation scheme in
RocketMQ

- Level The number is fixed , Every Level Have your own timer , It's not expensive
- take Level Put the same message into the same Queue in , Ensure the same Level The order of the message ; Different Level Put it in a different place Queue in , Ensure the accuracy of delivery time ;
- By supporting only fixed Level, The sorting of messages with different delays is changed into fixed Level Topic Additional write operation
- Level Configuration modification is too expensive , Fix Level inflexible
- CommitLog Because of the existence of delayed messages
Pulsar

- ** Memory overhead :** The queue that maintains the delayed message index is placed in out of heap memory , And this queue is based on subscription group (Kafka Consumer groups in ) For the dimension of , Like you Topic Yes N Subscription groups , So if you this Topic Delayed messages are used , Will be created N individual queue ; And with the increase of delayed messages , Increase in time span , The memory usage of each queue will also increase .( Yes , Under this scheme , Supporting arbitrary delayed messages may make this defect more serious )
- ** The rebuild time cost of delaying the message index queue after failover :** For large-scale delay messages with long span time , Reconstruction time may be at the hour level .( Excerpt from Pulsar The official account of the public )
- Storage overhead : The time span of delayed messages will affect Pulsar Space recycling of consumed message data in . For example , Yours Topic If the business requires to support a one month delay message , Then you sent a message with a delay of one month , So you this Topic The middle and bottom storage will retain message data for a whole month , Even this month 99% The normal news has been consumed .

QMQ

- The time wheel algorithm is suitable for delay / Timing message scenario , Eliminate the sorting of delayed messages , Insert and delete operations are O(1) Time complexity of ;
- Through multi-level time wheel design , It supports delay messages with large time span ;
- Load by delay , There will only be messages to be consumed recently in memory , Longer latency messages are stored on disk , Memory friendly ;
- Delay messages are stored separately (schedule log), It will not affect the space recycling of normal messages ;
summary
版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232156502028.html
边栏推荐
- Tencent cloud has two sides in an hour, which is almost as terrible as one side..
- JS to get the browser and screen height
- 21. Basic usage of MariaDB
- Tsinghua University | webface260m: benchmark for million level deep face recognition (tpami2022)
- Pipes and xargs
- Database Experiment 8 trigger experiment
- Detectron2 using custom datasets
- How to make Jenkins job run automatically after startup
- MySQL back to table
- [leetcode refers to offer 25. Merge two sorted linked lists (simple)]
猜你喜欢

Hystrix components

openfeign集成Hystrix的备选方案处理

Online Excel to CSV tool

Oracle updates the data of different table structures and fields to another table, and then inserts it into the new table

Mixed use of Oracle column row conversion and comma truncated string

2. Finishing huazi Mianjing -- 2

延时消息常见实现方案

Tsinghua University | webface260m: benchmark for million level deep face recognition (tpami2022)

Database Experiment 3 data update experiment

Ribbon负载均衡策略
随机推荐
Online Excel to CSV tool
[leetcode refers to offer 18. Delete the node of the linked list (simple)]
C # problem of updating data: dynamic SQL generation is not supported for multiple base tables
从严从重从快 上海全面加强疫情期间食品安全监管
Error message: b04access.00f eve'. Read of address 000001B4
延时消息常见实现方案
OpenFeign的参数传递之数组和集合类型
一文解决浏览器跨域问题
2022-04-24日報:在生物科學領域應用深度學習的當前進展和開放挑戰
How Axure installs a catalog
在线时序流程图制作工具
Ali has another "against the sky" container framework! This kubernetes advanced manual is too complete
DW basic tutorial (I)
开发consul 客户端即微服务
A solution of C batch query
hystrix dashboard的使用
Detectron2 using custom datasets
JS prototype and prototype chain
OpenFeign的细节展示
OpenFeign调用详细日志展示