cswork / OA打开练习工作台

StripeOA #1

Connection Load Balancing (5 Parts)

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)迭代器设计模拟/实现

The Stripe video platform is built on Jupyter. Requests are routed through multiple Jupyter servers; different developers are pinned to different servers based on load.

Implement route_request that accepts requests and routes them.

  • Part 1: Basic load balancing. For each incoming request, route to the server with the smallest active-request count. Tie → smaller index.
  • Part 2: Disconnection. Handle CONNECT and DISCONNECT actions; rebalance correctly when a connection drops.
  • Part 3: Sticky session by object id. Subsequent requests for the same object id route to the same server, unless that server is unhealthy.
  • Part 4: maxConnectionsPerTarget cap. When a target hits its cap, evict the least-recently-used object on that target.
  • Part 5: SHUTDOWN. When a target shuts down, re-route its evicted connections.
Working with 2 targets and high maxConnectionsPerTarget:
CONNECT, conn1, userA, obj1
CONNECT, conn2, userB, obj2
SHUTDOWN, 1
CONNECT, conn3, userC, obj3
→ conn1 userA 2, conn2 userB 2, conn1 userA 2, conn3 userC 1