-
Notifications
You must be signed in to change notification settings - Fork 458
Description
Search before asking
- I searched in the issues and found nothing similar.
Fluss version
0.8.0 (latest release)
Please describe the bug 🐞
The current RequestChannel implementation uses a bounded ArrayBlockingQueue for request queuing. When the queue is full, putRequest() blocks the calling thread, which can cause Netty EventLoop threads to block. This leads to:
-
EventLoop Thread Blocking: When the request queue reaches capacity,
ArrayBlockingQueue.put()blocks the EventLoop thread, severely degrading server performance and responsiveness. -
No Backpressure Control: The bounded queue provides a hard limit but doesn't implement proper backpressure at the TCP level. When the queue is full, new requests are blocked at the application level rather than being controlled at the network layer.
-
Memory Management Issues: Without proper backpressure, the system cannot gracefully handle traffic spikes, potentially leading to memory exhaustion or degraded performance.
Solution
-
Use Unbounded Buffer Queue: Replace
ArrayBlockingQueuewith unbounded queue to ensureputRequest()never blocks, preventing EventLoop threads from being blocked. -
Implement TCP-Level Backpressure:
- When queue size exceeds
backpressureThreshold, pause all associated Netty channels by settingautoRead(false) - When queue size drops below
resumeThreshold(50% of backpressure threshold), resume channels by settingautoRead(true) - This provides hysteresis to avoid thrashing between pause/resume states
- When queue size exceeds
-
Channel Lifecycle Management:
- Register channels when they become active in
NettyServerHandler.channelActive() - Unregister channels when they become inactive in
NettyServerHandler.channelInactive() - Each
RequestChannelmanages its own set of associated channels independently
- Register channels when they become active in
-
Thread Safety and Performance:
- Use
ReentrantLockto protect backpressure state transitions atomically - Use
volatile boolean isBackpressureActivefor fast-path checks to avoid unnecessary lock contention - All channel operations are submitted to the channel's EventLoop thread for thread safety
- Use
Are you willing to submit a PR?
- I'm willing to submit a PR!