xiangfu0 opened a new pull request, #16409:
URL: https://github.com/apache/pinot/pull/16409
## Summary
This PR enhances the `ThrottleOnCriticalHeapUsageExecutor` by implementing
queue-based throttling functionality instead of immediate task rejection during
critical heap usage conditions.
## Background
Previously, the `ThrottleOnCriticalHeapUsageExecutor` would immediately
reject tasks when heap usage was critical. This new implementation provides a
more graceful degradation by queuing tasks and processing them when heap usage
returns to normal levels.
## Changes
### Core Implementation (`ThrottleOnCriticalHeapUsageExecutor.java`)
- **Queue-based throttling**: Tasks are queued when heap usage is critical
instead of being rejected
- **Configurable parameters**: Queue size, timeout duration, and monitoring
interval
- **Background processing**: Scheduled monitoring of heap usage to process
queued tasks
- **Timeout handling**: Tasks that exceed the queue timeout are properly
handled with appropriate exceptions
- **Graceful shutdown**: Proper cleanup of queued tasks during shutdown
- **Support for both Runnable and Callable tasks**: Full executor service
compatibility
### Key Features
- ✅ **Immediate execution** when heap usage is normal
- ✅ **Task queuing** during critical heap usage periods
- ✅ **Automatic processing** when heap usage recovers
- ✅ **Configurable timeouts** to prevent indefinite waiting
- ✅ **Queue overflow protection** with proper exception handling
- ✅ **Comprehensive metrics** (queued, processed, timed-out task counts)
- ✅ **Thread-safe implementation** with proper synchronization
### Test Coverage (`ThrottleOnCriticalHeapUsageExecutorTest.java`)
- Complete test suite with 6 test cases covering all scenarios:
- Immediate execution under normal heap conditions
- Task queuing and timeout behavior under critical heap
- Queue overflow handling
- Task processing during heap recovery
- Callable task support with return values
- Graceful shutdown behavior
## Configuration
```java
// Default values
int DEFAULT_QUEUE_SIZE = 1000;
long DEFAULT_QUEUE_TIMEOUT_MS = 30000; // 30 seconds
long DEFAULT_MONITOR_INTERVAL_MS = 1000; // 1 second
// Custom configuration
ThrottleOnCriticalHeapUsageExecutor executor = new
ThrottleOnCriticalHeapUsageExecutor(
executorService, accountant, queueSize, timeoutMs, monitorIntervalMs);
```
## Exception Handling
Tasks now throw standardized `QueryException` with
`SERVER_RESOURCE_LIMIT_EXCEEDED` error code for:
- Queue overflow conditions
- Task timeouts in queue
- Resource limit violations
## Testing
- ✅ All tests pass (6/6)
- ✅ Comprehensive coverage of success and error scenarios
- ✅ Thread safety validation
- ✅ Timeout and recovery behavior verification
## Backward Compatibility
This change is fully backward compatible. The existing constructor and API
remain unchanged, with new functionality being opt-in through additional
constructors.
## Performance Impact
- Minimal overhead during normal operation (immediate execution path
unchanged)
- Background monitoring thread has configurable interval to balance
responsiveness vs. resource usage
- Queue operations are O(1) for typical use cases
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]