본문으로 건너뛰기

[Ray Serve] Direct Ingress 최적화: 상수 순서 정리 및 빈 프록시 조기 반환

PR 링크: ray-project/ray#61310 상태: Merged | 변경: +8 / -4

들어가며

코드의 상수 초기화 순서와 불필요한 순회 방지는 작지만 중요한 최적화입니다. Ray Serve의 direct ingress 관련 코드에서 두 가지 문제를 수정합니다.

핵심 코드 분석

빈 프록시 목록 조기 반환

Before (client.py):

def wait_for_proxies_serving(self, ...) -> None:
    proxy_handles = ray.get(self._controller.get_proxies.remote())
    serving_refs = [
        handle.serving.remote(
            wait_for_applications_running=wait_for_applications_running
        )
        for handle in proxy_handles
    ]
    # ...

After:

def wait_for_proxies_serving(self, ...) -> None:
    proxy_handles = ray.get(self._controller.get_proxies.remote())

    if not proxy_handles:
        return

    serving_refs = [
        handle.serving.remote(
            wait_for_applications_running=wait_for_applications_running
        )
        for handle in proxy_handles
    ]

상수 초기화 순서 수정

Before (constants.py):

# Direct ingress must be enabled if HAProxy is enabled
if RAY_SERVE_ENABLE_HA_PROXY:
    RAY_SERVE_ENABLE_DIRECT_INGRESS = True

# ... 여러 줄 아래 ...
RAY_SERVE_ENABLE_DIRECT_INGRESS = os.environ.get(...)

After:

RAY_SERVE_ENABLE_DIRECT_INGRESS = os.environ.get(...)

# ... 여러 줄 아래 ...
# Direct ingress must be enabled if HAProxy is enabled
if RAY_SERVE_ENABLE_HA_PROXY:
    RAY_SERVE_ENABLE_DIRECT_INGRESS = True

기존 코드에서는 HAProxy가 활성화되면 RAY_SERVE_ENABLE_DIRECT_INGRESS = True를 설정했지만, 이후 환경변수에서 다시 읽어와 덮어쓸 수 있었습니다. 순서를 바꿔 HAProxy 활성화 시 direct ingress가 확실히 켜지도록 보장합니다.

왜 이게 좋은가

  • 프록시가 없는 환경에서 불필요한 리스트 컴프리헨션과 ray.get() 호출을 방지합니다
  • 상수 초기화 순서 버그는 HAProxy를 사용하면서 환경변수로 direct ingress를 끄려는 경우에 예기치 않은 동작을 일으킬 수 있었습니다
  • 총 +8/-4줄의 매우 간결한 변경이지만, 정확성과 효율성을 동시에 개선합니다

참고 자료

댓글

관련 포스트

PR Analysis 의 다른글