Skip to content

Optimization: single coordinator worker dispatching per-position rebalance workers #264

@holyfuchs

Description

@holyfuchs

Problem

Currently, each position has its own AutoRebalancer scheduled independently. With $N$ positions, there are $N$ independent scheduled transactions running on their own intervals.

Key Issues:

  • $O(N)$ Overhead: Scheduling overhead grows linearly with the number of positions.
  • No Cross-Position Coordination: The Supervisor only performs fixReschedule() recovery; it lacks the logic to decide if a position actually requires action.
  • Efficiency: Every rebalancer fires unconditionally, consuming resources regardless of need.
graph TD
    SUP[Supervisor<br/>cron every z min]
    AB1[Rebalancer 1<br/>every x min]
    AB2[Rebalancer 2<br/>every y min]
    ABn[Rebalancer N<br/>...]
    P1[Position 1]
    P2[Position 2]
    Pn[Position N]

    SUP -->|fixReschedule| AB1
    SUP -->|fixReschedule| AB2
    SUP -->|fixReschedule| ABn

    AB1 -->|rebalance| P1
    AB2 -->|rebalance| P2
    ABn -->|rebalance| Pn

Loading

Proposed Solution

Replace $N$ independent rebalancers with a single Coordinator. This central entity inspects all positions and only dispatches a worker for positions that meet the rebalancing criteria.

graph TD
    COORD[Coordinator<br/>cron every x min]
    P1[Position 1]
    P2[Position 2]
    Pn[Position N]
    W1[Worker 1]
    Wn[Worker N]

    COORD -->|inspects| P1
    COORD -->|inspects| P2
    COORD -->|inspects| Pn

    COORD -.->|dispatch if needed| W1
    COORD -.->|dispatch if needed| Wn

    W1 -->|rebalance| P1
    Wn -->|rebalance| Pn

Loading

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions