Skip to content

Commit 45931ad

Browse files
poorbarcodeKannarFr
authored andcommitted
[improve][pip] PIP-434: Expose Netty channel configuration WRITE_BUFFER_WATER_MARK to pulsar conf and pause receive requests when channel is unwritable (apache#24510)
1 parent 71397b4 commit 45931ad

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

pip/pip-434.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# PIP-434: Expose Netty channel configuration WRITE_BUFFER_WATER_MARK to pulsar conf and pause receive requests when channel is unwritable
2+
3+
# Background knowledge & Motivation
4+
5+
As we discussed along the discussion: https://lists.apache.org/thread/6jfs02ovt13mnhn441txqy5m6knw6rr8
6+
7+
> Problem Statement:
8+
> We've encountered a critical issue in our Apache Pulsar clusters where brokers experience Out-Of-Memory (OOM) errors and continuous restarts under specific load patterns. This occurs when Netty channel write buffers become full, leading to a buildup of unacknowledged responses in the broker's memory.
9+
10+
> Background:
11+
> Our clusters are configured with numerous namespaces, each containing approximately 8,000 to 10,000 topics. Our consumer applications are quite large, with each consumer using a regular expression (regex) pattern to subscribe to all topics within a namespace.
12+
13+
> The problem manifests particularly during consumer application restarts. When a consumer restarts, it issues a getTopicsOfNamespace request. Due to the sheer number of topics, the response size is extremely large. This massive response overwhelms the socket output buffer, causing it to fill up rapidly. Consequently, the broker's responses get backlogged in memory, eventually leading to the broker's OOM and subsequent restart loop.
14+
15+
> Solution we got:
16+
> - Expose Netty channel configuration WRITE_BUFFER_WATER_MARK to pulsar conf
17+
> - Stops receive requests continuously once the Netty channel is unwritable, users can use the new config to control the threshold that limits the max bytes that are pending write.
18+
19+
# Goals
20+
21+
## In Scope
22+
- Expose Netty channel configuration WRITE_BUFFER_WATER_MARK to pulsar conf
23+
- Stops receive requests continuously once the Netty channel is unwritable, users can use the new config to control the threshold that limits the max bytes that are pending write.
24+
25+
## Out of Scope
26+
27+
- This proposal is not in order to add a broker level memory limitation, it only focuses on addressing the OOM caused by the accumulation of a large number of responses in memory due to the channel granularity being unwritable.
28+
29+
# Detailed Design
30+
31+
### Configuration
32+
33+
```shell
34+
# It relates to configuration "WriteBufferHighWaterMark" of Netty Channel Config. If the number of bytes queued in the write buffer exceeds this value, channel writable state will start to return "false".
35+
pulsarChannelWriteBufferHighWaterMark=64k
36+
# It relates to configuration "WriteBufferLowWaterMark" of Netty Channel Config. If the number of bytes queued in the write buffer is smaller than this value, channel writable state will start to return "true".
37+
pulsarChannelWriteBufferLowWaterMark=32k
38+
# Once the writer buffer is full, the channel stops dealing with new requests until it changes to writable
39+
pulsarChannelPauseReceivingRequestsIfUnwritable=false
40+
After the connection is recovered from an unreadable state, the channel will be rate-limited for a period of time to avoid overwhelming due to the backlog of requests. This parameter defines how many" requests should be allowed in the rate limiting period.
41+
pulsarChannelRateLimitingRateAfterResumeFromUnreadable=1000
42+
After the connection is recovered from an unreadable state, the channel will be rate-limited for a period of time to avoid overwhelming due to the backlog of requests. This parameter defines how long the rate limiting should last, in seconds. Once the bytes that are waiting to be sent out reach the pulsarChannelWriteBufferHighWaterMark\", the timer will be reset.
43+
pulsarChannelRateLimitingSecondsAfterResumeFromUnreadable=5
44+
```
45+
46+
### How it works
47+
With the settings `pulsarChannelPauseReceivingRequestsIfUnwritable=false`, the behaviour is exactly the same as the previous.
48+
49+
After setting `pulsarChannelPauseReceivingRequestsIfUnwritable` to `true`, the channel state will be changed as follows.
50+
- Netty sets `channel.writable` to `false` when there is too much data that is waiting to be sent out(the size of the data cached in `ChannelOutboundBuffer` is larger than `{pulsarChannelWriteBufferHighWaterMark}`)
51+
- Netty will trigger an event `channelWritabilityChanged`
52+
- Stops receiving requests that come into the channel, which relies on the attribute `autoRead` of the `Netty channel`.
53+
- Netty sets `channel.writable` to `true` once the size of the data that is waiting to be sent out is less than `{pulsarChannelWriteBufferLowWaterMark}`
54+
- Starts to receive requests(sets `channel.autoRead` to `true`).
55+
- Note: relies on `ServerCnxThrottleTracker`, which will track the "throttle count". When a throttling condition is present, the throttle count is increased and when it's no more present, the count is decreased. The autoread should be switched to false when the counter value goes from 0 to 1, and only when it goes back from 1 to 0 should it be set to true again. The autoread flag is no longer controlled directly from the rate limiters. Rate limiters are only responsible for their part, and it's ServerCnxThrottleTracker that decides when the autoread flag is toggled. See more details [pip-322](https://github.com/apache/pulsar/blob/master/pip/pip-322.md)
56+
- To avoid handling a huge request in the backlog instantly, Pulsar will start a timed rate-limiter, which limits the rate of handling the request backlog("pulsarChannelRateLimitingRateAfterResumeFromUnreadable" requests per second).
57+
- After "{pulsarChannelRateLimitingSecondsAfterResumeFromUnreadable}" seconds, the rate-limiter will be removed automatically. Once the bytes that are waiting to be sent out reach the pulsarChannelWriteBufferHighWaterMark\", the timer will be reset.
58+
59+
### CLI
60+
61+
### Metrics
62+
| Name | Description | Attributes | Units|
63+
|------------------------------------------------------|---------------------------------------------------------------------------------------------|--------------| --- |
64+
| `pulsar_server_channel_write_buf_memory_used_bytes` | Counter. The memory amount that is occupied by netty write buffers | cluster | - |
65+
66+
67+
# Monitoring
68+
69+
70+
# Security Considerations
71+
Nothing.
72+
73+
# Backward & Forward Compatibility
74+
75+
## Upgrade
76+
Nothing.
77+
78+
## Downgrade / Rollback
79+
Nothing.
80+
81+
## Pulsar Geo-Replication Upgrade & Downgrade/Rollback Considerations
82+
Nothing.
83+
84+
# Alternatives
85+
Nothing.
86+
87+
# General Notes
88+
89+
# Links
90+
91+
<!--
92+
Updated afterwards
93+
-->
94+
* Mailing List discussion thread: https://lists.apache.org/thread/hnbm9q3yvyf2wcbdggxmjzhr9boorqkn
95+
* Mailing List voting thread: https://lists.apache.org/thread/vpvtf4jnbbrhsy9y5fg00mpz9qhb0cp5

0 commit comments

Comments
 (0)