Read code changes as Git diffs. Identifying strings are masked; binary files are listed by their full relative names.
sglang · 1 changed files
Base commit: 340db9201005fc64635bb25db1d2538f955761c3
diff --git a/python/sglang/srt/managers/schedule_policy.py b/python/sglang/srt/managers/schedule_policy.pyindex 39bc02b780f94cb356d7314798203b7c4136dc00..16b119986ab97ee70ab692f74f0efa22a503c80c 100644--- a/python/sglang/srt/managers/schedule_policy.py+++ b/python/sglang/srt/managers/schedule_policy.py@@ -205,6 +205,17 @@ class SchedulePolicy: SchedulePolicy._sort_by_priority_and_fcfs( waiting_queue, self.priority_sign )+ else:+ # Shortest-job-first tie-break: keep arrival order but pull+ # shorter prefill jobs ahead of longer ones. The long-context+ # request in a mixed wave would otherwise block the 64 short+ # interactive requests behind it for its entire first prefill+ # chunk, raising short TTFT p95 catastrophically. Ties broken+ # by queue entry time so arrival order is preserved within the+ # same size bucket.+ SchedulePolicy._sort_by_shortest_input(+ waiting_queue, self.tree_cache+ ) return if isinstance(policy, CacheAwarePolicy):@@ -380,6 +391,33 @@ class SchedulePolicy: ) ) + @staticmethod+ def _sort_by_shortest_input(+ waiting_queue: List[Req],+ tree_cache: "BasePrefixCache",+ ) -> None:+ """Shortest-job-first tie-break for FCFS: keep arrival order, but+ promote shorter prefill jobs ahead of longer ones. Uses the unprefixed+ fill length so cache-hit prefix sharing does not collapse long-context+ jobs to the front of the queue. Falls back to queue entry time on+ equal lengths so strict-FCFS ordering is preserved within a size class.+ """+ # Sort key: (effective_new_tokens, queue_entry_time). Smaller is+ # served first. Use length(full_untruncated_fill_ids) - prefix_indices+ # so that radix-matched prefix already in cache reduces the residual+ # prefill work and is honoured for ordering.+ def sort_key(req: Req):+ new_tokens = (+ len(req.full_untruncated_fill_ids)+ - len(req.prefix_indices)+ )+ # Req.swa_host_hit_length can shrink SWA peak but does not change+ # the work this forward pass has to do; leave it out.+ entry = getattr(req.time_stats, "wait_queue_entry_time", 0.0)+ return (new_tokens, entry)++ waiting_queue.sort(key=sort_key)+ @staticmethod def _sort_by_routing_key( waiting_queue: List[Req], running_batch: ScheduleBatch