当前位置:网站首页>In depth analysis of Apache bookkeeper series: Part 4 - back pressure
In depth analysis of Apache bookkeeper series: Part 4 - back pressure
2022-06-30 22:23:00 【StreamNative】
This paper is written by StreamNative Organization translation from 《Apache BookKeeper Internals — Part 4 — Back Pressure》, author Jack Vanlightly,Apache BookKeeper Committer.
Translator information
Zhangwenfeng , Love to share , Embrace open source , Community nickname zeroGozhang, Now he is the big data architect of xinghuan information technology finance .
This series of blogs is based on Apache Pulsar Configured Apache BookKeeper 4.14 To write .
In this article , We will introduce BookKeeper All back pressure mechanisms used by the server nodes , To protect yourself from read and write overloads . Back pressure mechanism is necessary in any data system , It can not only prevent resource exhaustion , At the same time, it can make the system handle overload more gracefully and smoothly . When Bookie Overload , Ideally , We hope it will continue to provide high throughput for the content it can handle , And reject other requests .
Some components restrict the data structures in their memory , To prevent Bookie Run out of memory . for example , in the light of Journal The line will be right entry Limit the number of , Write cache has a limit on the number of bytes written . in fact , The write cache is pre allocated , So no matter Bookie What's the load of , Its memory usage is fixed .
By default , Other components are unlimited , For example, suspended Netty Mission . Besides , Even after considering all the different limitations of the internal buffer , When they are combined, they may exceed Bookie Memory limit of .
Let's take a look at various back pressure and memory limitation mechanisms .

chart 1: Location of various back pressure mechanisms
1 - Total number of writes in progress
We can do it through configuration maxAddsInProgressLimit Parameter controls the total number of writes in progress . When the total number of write requests in progress reaches this limit , The system will block those processing new write requests Netty Threads , Until the number of writes in progress falls below this limit again . When Netty Stop reading data from network buffer , Data will be overstocked in TCP Buffer zone , triggering TCP Built in back pressure mechanism , Notify the upstream sender and suspend sending , take TCP Back pressure is applied to the client .
This can effectively avoid the thread pool task queue 、Journal Queue, etc. caused by backlog of too many requests OutOfMemory error . There are no restrictions by default .
2 - Total number of reads in progress
We can also configure maxReadsInProgressLimit Parameters , Limit the total number of reads in progress . This triggers the same Netty Thread blocking behavior .
3 - Number of pending write requests per write thread pool thread
We can also limit the size of the write thread pool task queue ( To configure maxPendingAddRequestsPerThread, The default value is 10000), To reduce the number of pending write requests . Once the task queue is full , The client will receive TOO_MANY_REQUESTS Response , Causes the client to choose another Bookie To write .
4 - The number of pending read requests per read thread pool thread
The size of the read thread pool task queue can be limited in the same way as the write thread pool ( To configure maxPendingReadRequestsPerThread). Once the task queue is full , Read requests begin to be rejected in the same way as write requests , The affected client will choose another Bookie To read .
5 - Journal queue
Journal Get task from blocking queue . When Journal When the queue size reaches its maximum due to the gradual failure to keep up with the filling speed of the queue , The writing thread will be blocked , No more work can be performed until there is space on the queue .
Next , The write thread task queue will be filled , Write requests will begin to be rejected .
6 - DbLedgerStorage Write denied
If the active write cache is full , The swapped write cache is not yet available ( Because it's still brushing the plate ), be Bookie Unable to process more writes . Only when an empty write cache becomes available , It can accept more writes . therefore , When no write cache is available after waiting for a period of time ( By default 10 second , from dbStorage_maxThrottleTimeMs Definition ), Write requests will be rejected .
stay BookKeeper 4.14 In the version , This will result in a generic error code being returned to the client , instead of TOO_MANY_REQUESTS Code . This problem will be fixed in a future release .
7 - Netty Non writable channel
In order to prevent the passage of Netty The channel is out of memory when sending a response to the client , Can pass waitTimeoutOnResponseBackpressureMs Parameter configuration fallback mechanism . If the channel buffer is full , bring Netty The channel becomes non writable , The write response may be delayed to the corresponding waiting time . If the channel is still not writable , The system will not send a response , And it will send an indicator of channel error . If this fallback mechanism is not configured , Although its status is not writable , The response will still be sent to the channel ; If too many bytes are sent along the channel , May cause out of memory errors .
Besides ,Netty The number of queued tasks can also be determined by using Java Attribute to limit :io.netty.eventLoop.maxPendingTasks. This parameter also prevents Netty Thread accepts too many tasks .
summary
The back pressure applied by the receiving end will propagate upward along the link , Until we reach the source . about BookKeeper Come on , Back pressure usually starts from Journal and DbLedgerStorage Component start , Then it goes up the link to the thread pool ( Their task queues )、Netty, Finally arrive at the client .
But for the Apache Pulsar For clusters , More than that .Pulsar Broker It also has its own internal back pressure mechanism , It will eventually trigger a return to Pulsar producers and consumers .
This is the last article in this series . Next , We are going to launch a series of new blogs , The content is about BookKeeper Some indicators produced , And how to use the thinking patterns we tried to build in this series to explain them .
Recommended reading
1. In depth analysis of Apache BookKeeper series : Chapter one — Framework principle
2. In depth analysis of BookKeeper Multi copy agreement ( One )
3. In depth analysis of Apache BookKeeper series : Second articles — Write operation principle
4. Apache BookKeeper Insight ( One ) — External consensus and dynamic members
5. In depth analysis of Apache BookKeeper series : Third articles —— Reading principle
▼ Focus on 「Apache Pulsar」, Get dry and dynamic ▼
reply BookKeeper, Join in Pulsar Storage team

Click on 「 Read the original 」, receive Pulsar vs Kafka The latest evaluation report PDF!
This article is from WeChat official account. - ApachePulsar(ApachePulsar).
If there is any infringement , Please contact the [email protected] Delete .
Participation of this paper “OSC Source creation plan ”, You are welcome to join us , share .
边栏推荐
- vncserver: Failed command ‘/etc/X11/Xvnc-session‘: 256!
- Is the stock account opened in qiniu safe? How to apply for a low commission stock account?
- Zhoushaojian, rare
- "Team training competition" Shandong multi university training 3
- 机器学习适合女生学吗?
- Nansen double disk encryption giant self rescue: how to prevent the collapse of billions of dominoes
- 软件确认测试的内容和流程有哪些?确认测试报告需要多少钱?
- 【Android,Kotlin,TFLite】移动设备集成深度学习轻模型TFlite(图像分类篇)
- 总结的一些内存问题
- When unittest automatically tests multiple use cases, the logging module prints repeatedly to solve the problem
猜你喜欢

Why does the computer speed slow down after vscode is used for a long time?

Windbg调试工具介绍

Ten of the most heart piercing tests / programmer jokes, read the vast crowd, how to find?
![[introduction to MySQL] the first conversation · first time in the](/img/73/cc85eb469384c3df94479318293c6f.png)
[introduction to MySQL] the first conversation · first time in the "database" Mainland

Starting from pg15 xid64 ticket skipping again

Where can I find the computer device manager

基于kubernetes平台微服务的部署

腾讯3年,功能测试进阶自动化测试,送给在手工测试中迷茫的你

【BSP视频教程】BSP视频教程第19期:单片机BootLoader的AES加密实战,含上位机和下位机代码全开源(2022-06-26)

部门新来了个阿里25K出来的,让我见识到了什么是天花板
随机推荐
多线程经典案例
阿婆做的臭豆腐
Turn: win others' follow with practical actions
Study summary of dynamic routing between capsules
B_ QuRT_ User_ Guide(31)
机器学习工作要求研究生吗?
latex中 & 号什么含义?
Apache server OpenSSL upgrade
严格次小生成树
Femas:云原生多运行时微服务框架
AtCoder Beginner Contest 257
【MySQL入门】第一话 · 初入“数据库”大陆
AtCoder Beginner Contest 255
What is the experience of pairing with AI? Pilot vs alphacode, Codex, gpt-3
「团队训练赛」ShanDong Multi-University Training #3
Label Contrastive Coding based Graph Neural Network for Graph Classification
总结的一些内存问题
【BSP视频教程】BSP视频教程第19期:单片机BootLoader的AES加密实战,含上位机和下位机代码全开源(2022-06-26)
B_ QuRT_ User_ Guide(33)
Coredns modifying upstream