Heuristic:A616567126 GPT WEB JAVA Load Balancer Rule Selection
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Distributed_Systems |
| Last Updated | 2026-10-13 18:00 GMT |
Overview
Choose BestWaitIdleRule over RoundRobinRule for Discord account pool load balancing to minimize user wait time by routing to the least-loaded instance.
Description
When managing a pool of Discord accounts for Midjourney task submission, the load balancing strategy directly impacts user-perceived latency. The codebase provides two `IRule` implementations: `RoundRobinRule` distributes tasks in strict rotation order, while `BestWaitIdleRule` groups instances by their current wait count (running futures minus core pool size) and selects from the least-loaded group. If all instances are idle (wait = -1), it falls back to random selection within that idle group. This avoids sending tasks to accounts that already have a backlog, reducing the maximum wait time per user.
Usage
Use this heuristic when configuring the Discord account pool load balancer (`DiscordLoadBalancer`). Choose `BestWaitIdleRule` when Discord accounts have varying pool sizes or when minimizing user wait time is the priority. Use `RoundRobinRule` only for simple, uniform-capacity deployments where even distribution matters more than wait time optimization.
The Insight (Rule of Thumb)
- Action: Select `BestWaitIdleRule` as the `IRule` implementation injected into `DiscordLoadBalancer`.
- Value: N/A (strategy choice, not a numeric setting).
- Trade-off: BestWaitIdleRule has slightly higher CPU overhead (grouping + comparison) but significantly reduces per-user wait time. RoundRobinRule is simpler but can pile tasks on a slow account.
- Compatibility: Both rules implement `IRule` and are interchangeable via Spring DI. The rule bean is injected via constructor (`@RequiredArgsConstructor`).
Reasoning
Midjourney tasks are long-running (seconds to minutes) and submitted to Discord accounts with finite thread pool capacity (`coreSize`). If a RoundRobin approach sends a new task to an account that already has a full queue, the user waits longer than necessary. BestWaitIdleRule calculates `wait = runningFutures.size() - coreSize` for each instance: a wait of 0 means the instance is at capacity, a wait of -1 means it is idle. By selecting the minimum wait group, the rule ensures new tasks go to instances that can process them immediately or with the shortest queue. The random selection within the tie group prevents deterministic ordering artifacts.