当前位置:网站首页>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
边栏推荐
- consul 开启健康监控检查
- IIS cannot load * woff,*. woff2,*. Solution of SVG file
- Plato Farm元宇宙IEO上线四大,链上交易颇高
- 服务雪崩效应
- Lightweight project management ideas
- 2022-04-24日報:在生物科學領域應用深度學習的當前進展和開放挑戰
- April 24, 2022 Daily: current progress and open challenges of applying deep learning in the field of Bioscience
- [※ leetcode refers to offer 32 - II. Print binary tree II from top to bottom (simple)]
- Preliminary analysis of Airbase
- Leaf Smecta
猜你喜欢

MySQL back to table

JUnit unit test ---- a good tool for testing a single method

Cvpr2022 | efficient pre training based on knowledge distillation

Ribbon组件负载均衡调用和使用

Ribbon组件基本介绍和使用

Database Experiment 5 Security Language Experiment

Oracle ora-01033: Oracle initialization or shutdown in progressprocess solution

服务间通信方式

RestTemplate 服务调用

Cancel the default open project setting of idea
随机推荐
[leetcode refers to offer 21. Adjust the array order so that odd numbers precede even numbers (simple)]
April 24, 2022 Daily: current progress and open challenges of applying deep learning in the field of Bioscience
Online timing flow chart making tool
在线时序流程图制作工具
Flomo software recommendation
NVM introduction, NVM download, installation and use (node version management)
Hystrix components
Plato Farm元宇宙IEO上线四大,链上交易颇高
Database Experiment 2 data query
Sklearn function: Train_ Test_ Split (split training set and test set)
分布式系统服务熔断
Introduction to hystrix and implementation of server fuse
A series of problems of C DataGridView binding list
How to make Jenkins job run automatically after startup
Swift import third-party library reports an error no such module““
[leetcode refers to offer 27. Image of binary tree (simple)]
Sqlserver edits data in the query interface (similar to Oracle's edit and ROWID)
openfeign集成Hystrix的备选方案处理
JUnit unit test ---- a good tool for testing a single method
在线Excel转CSV工具