본문으로 건너뛰기

[sglang] HiRadixCache에서 TTL 기반 hard pin 기능 제거

PR 링크: sgl-project/sglang#21884 상태: Merged | 변경: +1 / -223

들어가며

HiRadixCache에 도입된 TTL 기반 hard pin 기능은 특정 prefix를 일정 시간 동안 eviction에서 보호하는 메커니즘이었다. 그러나 이 기능은 캐시 관리 로직을 크게 복잡하게 만들었고, pin budget 관리, TTL 만료 처리, host_ref_counter 조작 등 여러 부수 효과를 도입했다. 이 PR은 해당 기능 전체를 revert한다.

핵심 코드 분석

1. HTTP API 엔드포인트 제거

Before:

@app.api_route("/hicache/pin_prefix", methods=["POST"])
@auth_level(AuthLevel.ADMIN_OPTIONAL)
async def pin_prefix(obj: PinPrefixReqInput):
    """Pin a prefix by token_ids to resist eviction."""
    ret = await _global_state.tokenizer_manager.pin_prefix(
        obj.token_ids, obj.ttl_seconds
    )
    return ORJSONResponse(content={
        "status": "ok" if ret.success else "error",
        "nodes_pinned": ret.nodes_pinned,
    })

After:

# 엔드포인트 완전 삭제

/hicache/pin_prefix REST API 엔드포인트가 제거되었다.

2. Pin budget 및 TTL 관리 로직 제거

Before:

# HiRadixCache.__init__
pin_ratio = envs.SGLANG_HICACHE_MAX_PINNED_RATIO.get()
self._max_pinned_tokens = int(self.token_to_kv_pool_host.size * pin_ratio)
self.pinned_size_ = 0

def _is_pinned(self, node: TreeNode) -> bool:
    return node.pin_expiry > 0 and time.monotonic() <= node.pin_expiry

def pin_prefix(self, token_ids, ttl_seconds=300):
    # 70줄에 달하는 pin 로직
    # budget 확인, host_ref_counter 조작, TTL 설정 등

After:

# 모든 pin 관련 코드 삭제
# SGLANG_HICACHE_MAX_PINNED_RATIO 환경변수도 제거

pin_prefix, _is_pinned, _clear_pin 메서드와 환경변수, IO struct, communicator, scheduler 핸들러까지 6개 파일에 걸쳐 약 223줄이 삭제되었다.

왜 이게 좋은가

  • 복잡도 대폭 감소: 캐시 노드의 pin 상태 추적, TTL 만료 처리, budget 관리 등 부수 로직 제거
  • 버그 가능성 제거: host_ref_counter를 수동으로 조작하던 코드가 사라져 ref counting 불일치 위험 해소
  • 의존성 정리: SGLANG_HICACHE_MAX_PINNED_RATIO 환경변수 제거로 설정 항목 단순화
  • 6개 파일 정리: http_server, environ, io_struct, scheduler, tokenizer_communicator, hiradix_cache

정리

TTL 기반 hard pin은 유용한 아이디어였지만, 현 시점에서는 복잡도 대비 실용적 가치가 낮다고 판단된 것으로 보인다. revert를 통해 HiRadixCache의 핵심 eviction 로직이 다시 단순해졌다. 향후 필요 시 더 단순한 형태로 재도입될 수 있다.

참고 자료

⚠️ 알림: 이 분석은 AI가 실제 코드 diff를 기반으로 작성했습니다.

댓글

관련 포스트

PR Analysis 의 다른글