Skip to content

[serve] Add gRPC support to haproxy - #63735

Merged
abrarsheikh merged 41 commits into
ray-project:masterfrom
akyang-anyscale:hap-ga-1
Jun 25, 2026
Merged

abrarsheikh merged 41 commits into
ray-project:masterfrom
akyang-anyscale:hap-ga-1

Conversation

@akyang-anyscale

@akyang-anyscale akyang-anyscale commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

This PR implements gRPC service support for HAProxy.

Basic functionality

  • creates a grpc frontend that binds to host and port from grpc options and uses proto h2
  • controller already broadcasts grpc target groups to HAProxyManager, we now just add them to the haproxy config in their own grpc backends
  • routing is done to each backend based on the application header in the request. if there's only one app, then just always map to that backend
  • since haproxy doesn't natively support grpc health checks, in order to figure out which server is up or down we construct a grpc health check and send it over tcp. the implementation is a bit complex but necessary so that replica draining correctly conveys that the server's down

Health Checks

  • this is the /Healthz endpoint
  • returns True if at least one backend has a server up

List Applications

  • since haproxy can't return the grpc response itself, we rely on the fallback serve proxy to answer list application requests. this requires the fallback proxy to be up. list application requests get sent to a grpc fallback backend, which only contains the fallback proxy

HAProxy serving check

  • we make this constraint tighter. we must have 1) received at least one broadcast from the controller, 2) the grpc fallback backend needs to be ready if grpc is enabled, 3) the list of backends reported by haproxy all need to have an up server that appears in the broadcasted target groups or only match the fallback proxy

Tuning flags

  • provided some tuning flags which affect performance for different workloads

support for haproxy grpc

known limitations:
* streaming (to be implemented)
* metrics (to be implemented)
* healthz response is changed such that the response object is None. The
message is in the grpc call details instead of the response now (because
of haproxy limitations). The status code is unchanged (still `OK` on
healthy and `UNAVAILABLE` otherwise).
* ListApplications request is forwarded to the serve proxy, so it does
not work if serve proxy is down.

---------

Signed-off-by: akyang-anyscale <[email protected]>
Make haproxy http2 tuning parameters adjustable via env var

---------

Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces gRPC support for HAProxy in Ray Serve, adding HTTP/2 tuning flags, a gRPC frontend, and health check configurations. Feedback on the changes highlights three key improvements: adding the missing check parameter to gRPC backend servers to enable active health checking, handling empty backend scenarios in the gRPC healthz template to avoid confusing NOT_FOUND errors, and initializing self._grpc_fallback_target in __init__ to prevent potential AttributeErrors.

Comment thread python/ray/serve/_private/haproxy.py Resolved
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
@akyang-anyscale akyang-anyscale added the go add ONLY when ready to merge, run all tests label Jun 2, 2026
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
@akyang-anyscale
akyang-anyscale marked this pull request as ready for review June 23, 2026 08:21
@akyang-anyscale
akyang-anyscale requested a review from a team as a code owner June 23, 2026 08:21
@akyang-anyscale akyang-anyscale changed the title [serve] haproxy grpc [serve] Add gRPC support to haproxy Jun 23, 2026
@ray-gardener ray-gardener Bot added the serve Ray Serve Related Issue label Jun 23, 2026

@abrarsheikh abrarsheikh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nits: lg2m

Comment thread python/ray/serve/tests/test_cli_4.py Resolved
Comment thread python/ray/serve/_private/haproxy.py Resolved
Signed-off-by: akyang-anyscale <[email protected]>
Comment thread python/ray/serve/_private/haproxy.py Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6f53f98. Configure here.

Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
@abrarsheikh
abrarsheikh merged commit b43ff15 into ray-project:master Jun 25, 2026
3 checks passed
limarkdcunha pushed a commit to limarkdcunha/ray that referenced this pull request Jun 30, 2026
eicherseiji added a commit that referenced this pull request Jul 29, 2026
## Why

HAProxy proxies gRPC end to end over HTTP/2. The gRPC frontend `bind`
and the backend `server` lines both carry `proto h2`, so HAProxy decodes
and forwards HTTP/2 streams, including client-streaming and
bidirectional streaming, without any extra handling. gRPC-over-HAProxy
support landed in #63735, and the streaming cases were skipped at that
time as a scope cut rather than because of a real limitation.

## What changed

1. Remove the `skipif(RAY_SERVE_ENABLE_HA_PROXY, reason="HAProxy does
not support streaming.")` markers from the 13 gRPC streaming tests in
`test_grpc.py`.
2. Run the `Streaming` method assertion unconditionally in
`test_serving_grpc_requests` (`test_grpc.py`) and
`test_serving_request_through_grpc_proxy` (`test_cli_4.py`). Each
previously gated that assertion behind an inline conditional (`if not
RAY_SERVE_ENABLE_HA_PROXY` and `if not
RAY_SERVE_ENABLE_DIRECT_INGRESS`). HAProxy forces
`RAY_SERVE_ENABLE_DIRECT_INGRESS` on (`constants.py`), so both
conditions were false under HAProxy and the assertion never ran there.
Also drops the now-unused `RAY_SERVE_ENABLE_HA_PROXY` import in
`test_grpc.py`.

The `serve: HAProxy tests` CI step runs the full serve suite under
`RAY_SERVE_ENABLE_HA_PROXY=1`, so these all execute there now instead of
being skipped.

## Testing

Ran under the bundled HAProxy 2.8.25 with `RAY_SERVE_ENABLE_HA_PROXY=1
RAY_SERVE_ENABLE_DIRECT_INGRESS=0`:

```
python -m pytest python/ray/serve/tests/test_grpc.py -k streaming
# 20 passed, 23 deselected

python -m pytest \
  python/ray/serve/tests/test_grpc.py::test_serving_grpc_requests \
  python/ray/serve/tests/test_cli_4.py::test_serving_request_through_grpc_proxy
# 2 passed
```

Streaming coverage now exercised under HAProxy: client and bidirectional
streaming, the grpc-context variants, timeout, cancellation,
backpressure, mid-stream client errors, and the server-streaming
`Streaming` method in the gRPC and CLI end-to-end tests.

## Not a duplicate

No open PR or issue targets gRPC streaming under HAProxy (checked `gh pr
list` and `gh issue list` on ray-project/ray).

---------

Signed-off-by: Seiji Eicher <[email protected]>
Artimislyy pushed a commit to Artimislyy/ray that referenced this pull request Aug 11, 2026
## Why

HAProxy proxies gRPC end to end over HTTP/2. The gRPC frontend `bind`
and the backend `server` lines both carry `proto h2`, so HAProxy decodes
and forwards HTTP/2 streams, including client-streaming and
bidirectional streaming, without any extra handling. gRPC-over-HAProxy
support landed in ray-project#63735, and the streaming cases were skipped at that
time as a scope cut rather than because of a real limitation.

## What changed

1. Remove the `skipif(RAY_SERVE_ENABLE_HA_PROXY, reason="HAProxy does
not support streaming.")` markers from the 13 gRPC streaming tests in
`test_grpc.py`.
2. Run the `Streaming` method assertion unconditionally in
`test_serving_grpc_requests` (`test_grpc.py`) and
`test_serving_request_through_grpc_proxy` (`test_cli_4.py`). Each
previously gated that assertion behind an inline conditional (`if not
RAY_SERVE_ENABLE_HA_PROXY` and `if not
RAY_SERVE_ENABLE_DIRECT_INGRESS`). HAProxy forces
`RAY_SERVE_ENABLE_DIRECT_INGRESS` on (`constants.py`), so both
conditions were false under HAProxy and the assertion never ran there.
Also drops the now-unused `RAY_SERVE_ENABLE_HA_PROXY` import in
`test_grpc.py`.

The `serve: HAProxy tests` CI step runs the full serve suite under
`RAY_SERVE_ENABLE_HA_PROXY=1`, so these all execute there now instead of
being skipped.

## Testing

Ran under the bundled HAProxy 2.8.25 with `RAY_SERVE_ENABLE_HA_PROXY=1
RAY_SERVE_ENABLE_DIRECT_INGRESS=0`:

```
python -m pytest python/ray/serve/tests/test_grpc.py -k streaming
# 20 passed, 23 deselected

python -m pytest \
  python/ray/serve/tests/test_grpc.py::test_serving_grpc_requests \
  python/ray/serve/tests/test_cli_4.py::test_serving_request_through_grpc_proxy
# 2 passed
```

Streaming coverage now exercised under HAProxy: client and bidirectional
streaming, the grpc-context variants, timeout, cancellation,
backpressure, mid-stream client errors, and the server-streaming
`Streaming` method in the gRPC and CLI end-to-end tests.

## Not a duplicate

No open PR or issue targets gRPC streaming under HAProxy (checked `gh pr
list` and `gh issue list` on ray-project/ray).

---------

Signed-off-by: Seiji Eicher <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
## Why

HAProxy proxies gRPC end to end over HTTP/2. The gRPC frontend `bind`
and the backend `server` lines both carry `proto h2`, so HAProxy decodes
and forwards HTTP/2 streams, including client-streaming and
bidirectional streaming, without any extra handling. gRPC-over-HAProxy
support landed in ray-project#63735, and the streaming cases were skipped at that
time as a scope cut rather than because of a real limitation.

## What changed

1. Remove the `skipif(RAY_SERVE_ENABLE_HA_PROXY, reason="HAProxy does
not support streaming.")` markers from the 13 gRPC streaming tests in
`test_grpc.py`.
2. Run the `Streaming` method assertion unconditionally in
`test_serving_grpc_requests` (`test_grpc.py`) and
`test_serving_request_through_grpc_proxy` (`test_cli_4.py`). Each
previously gated that assertion behind an inline conditional (`if not
RAY_SERVE_ENABLE_HA_PROXY` and `if not
RAY_SERVE_ENABLE_DIRECT_INGRESS`). HAProxy forces
`RAY_SERVE_ENABLE_DIRECT_INGRESS` on (`constants.py`), so both
conditions were false under HAProxy and the assertion never ran there.
Also drops the now-unused `RAY_SERVE_ENABLE_HA_PROXY` import in
`test_grpc.py`.

The `serve: HAProxy tests` CI step runs the full serve suite under
`RAY_SERVE_ENABLE_HA_PROXY=1`, so these all execute there now instead of
being skipped.

## Testing

Ran under the bundled HAProxy 2.8.25 with `RAY_SERVE_ENABLE_HA_PROXY=1
RAY_SERVE_ENABLE_DIRECT_INGRESS=0`:

```
python -m pytest python/ray/serve/tests/test_grpc.py -k streaming
# 20 passed, 23 deselected

python -m pytest \
  python/ray/serve/tests/test_grpc.py::test_serving_grpc_requests \
  python/ray/serve/tests/test_cli_4.py::test_serving_request_through_grpc_proxy
# 2 passed
```

Streaming coverage now exercised under HAProxy: client and bidirectional
streaming, the grpc-context variants, timeout, cancellation,
backpressure, mid-stream client errors, and the server-streaming
`Streaming` method in the gRPC and CLI end-to-end tests.

## Not a duplicate

No open PR or issue targets gRPC streaming under HAProxy (checked `gh pr
list` and `gh issue list` on ray-project/ray).

---------

Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: 400Ping <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
## Why

HAProxy proxies gRPC end to end over HTTP/2. The gRPC frontend `bind`
and the backend `server` lines both carry `proto h2`, so HAProxy decodes
and forwards HTTP/2 streams, including client-streaming and
bidirectional streaming, without any extra handling. gRPC-over-HAProxy
support landed in ray-project#63735, and the streaming cases were skipped at that
time as a scope cut rather than because of a real limitation.

## What changed

1. Remove the `skipif(RAY_SERVE_ENABLE_HA_PROXY, reason="HAProxy does
not support streaming.")` markers from the 13 gRPC streaming tests in
`test_grpc.py`.
2. Run the `Streaming` method assertion unconditionally in
`test_serving_grpc_requests` (`test_grpc.py`) and
`test_serving_request_through_grpc_proxy` (`test_cli_4.py`). Each
previously gated that assertion behind an inline conditional (`if not
RAY_SERVE_ENABLE_HA_PROXY` and `if not
RAY_SERVE_ENABLE_DIRECT_INGRESS`). HAProxy forces
`RAY_SERVE_ENABLE_DIRECT_INGRESS` on (`constants.py`), so both
conditions were false under HAProxy and the assertion never ran there.
Also drops the now-unused `RAY_SERVE_ENABLE_HA_PROXY` import in
`test_grpc.py`.

The `serve: HAProxy tests` CI step runs the full serve suite under
`RAY_SERVE_ENABLE_HA_PROXY=1`, so these all execute there now instead of
being skipped.

## Testing

Ran under the bundled HAProxy 2.8.25 with `RAY_SERVE_ENABLE_HA_PROXY=1
RAY_SERVE_ENABLE_DIRECT_INGRESS=0`:

```
python -m pytest python/ray/serve/tests/test_grpc.py -k streaming
# 20 passed, 23 deselected

python -m pytest \
  python/ray/serve/tests/test_grpc.py::test_serving_grpc_requests \
  python/ray/serve/tests/test_cli_4.py::test_serving_request_through_grpc_proxy
# 2 passed
```

Streaming coverage now exercised under HAProxy: client and bidirectional
streaming, the grpc-context variants, timeout, cancellation,
backpressure, mid-stream client errors, and the server-streaming
`Streaming` method in the gRPC and CLI end-to-end tests.

## Not a duplicate

No open PR or issue targets gRPC streaming under HAProxy (checked `gh pr
list` and `gh issue list` on ray-project/ray).

---------

Signed-off-by: Seiji Eicher <[email protected]>
akyang-anyscale added a commit to akyang-anyscale/ray that referenced this pull request Oct 6, 2026
…ptimized variant

HAProxy now proxies gRPC (ray-project#63735), so the aws.haproxy variant of
pytest_serve_throughput_optimized_microbenchmarks no longer needs to
skip --run-grpc. Drop its script override so it inherits --run-all.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: akyang-anyscale <[email protected]>
akyang-anyscale added a commit that referenced this pull request Oct 6, 2026
…ptimized variant (#66771)

## Description

The `aws.haproxy` variant of
`pytest_serve_throughput_optimized_microbenchmarks` overrode the script
to skip `--run-grpc`, because HAProxy did not proxy gRPC when the
variant was added (#63386). HAProxy has proxied gRPC since #63735, so
this PR removes the override. The variant now inherits the base
`--run-all` script and runs the gRPC latency and throughput benchmarks
the same way the non-HAProxy variant does.


**Latency**

| Scenario | p50 | p90 | p95 | p99 |
|---|---:|---:|---:|---:|
| http | 0.808204 | 0.861002 | 0.884248 | 0.965185 |
| http_1mb | 0.916350 | 0.960832 | 0.979879 | 1.035858 |
| http_10mb | 2.923250 | 3.028106 | 3.064171 | 3.147383 |
| http_streaming | 10606.518767 | 10727.092702 | 10782.166075 |
10793.441756 |
| http_intermediate_streaming | 11520.631168 | 11709.328922 |
11783.598146 | 11794.278803 |
| grpc | 0.329592 | 0.359457 | 0.374129 | 0.419050 |
| grpc_1mb | 2.914066 | 3.262638 | 3.301536 | 3.536366 |
| grpc_10mb | 28.468160 | 29.396314 | 29.621062 | 33.389895 |
| handle | 0.496363 | 0.535661 | 0.563960 | 0.684138 |
| handle_1mb | 1.240247 | 1.785575 | 2.186740 | 2.772050 |
| handle_10mb | 20.357473 | 24.710342 | 26.734965 | 34.078222 |
| handle_choose_dispatch | 1.365623 | 1.479252 | 1.537067 | 1.765258 |
| handle_streaming | 11385.084532 | 11440.792105 | 11521.717464 |
11530.988577 |

**Throughput**

| Scenario | Average | Standard deviation | Rate |
|---|---:|---:|---|
| http | 3170.64 | 71.61 | RPS |
| http_model_comp | 1532.82 | 10.25 | RPS |
| http_100_max_ongoing_requests | 3179.71 | 73.90 | RPS |
| http_model_comp_100_max_ongoing_requests | 1849.08 | 23.66 | RPS |
| http_800_max_ongoing_requests | 2445.74 | 54.76 | RPS |
| http_model_comp_800_max_ongoing_requests | 1567.39 | 22.87 | RPS |
| http_streaming | 46990.46 | 436.22 | TPS |
| http_intermediate_streaming | 12994.40 | 152.01 | TPS |
| grpc | 4476.50 | 40.00 | RPS |
| grpc_model_comp | 1791.69 | 11.26 | RPS |
| grpc_100_max_ongoing_requests | 4498.49 | 41.80 | RPS |
| grpc_model_comp_100_max_ongoing_requests | 1840.62 | 11.83 | RPS |
| grpc_800_max_ongoing_requests | 4622.03 | 58.40 | RPS |
| grpc_model_comp_800_max_ongoing_requests | 1841.71 | 18.64 | RPS |
| handle | 3504.46 | 46.10 | RPS |
| handle_model_comp | 1020.17 | 25.20 | RPS |
| handle_100_max_ongoing_requests | 3539.55 | 41.45 | RPS |
| handle_model_comp_100_max_ongoing_requests | 1691.89 | 9.40 | RPS |
| handle_800_max_ongoing_requests | 3470.64 | 44.36 | RPS |
| handle_model_comp_800_max_ongoing_requests | 1633.69 | 10.54 | RPS |
| handle_streaming | 13147.51 | 57.50 | TPS |

Signed-off-by: akyang-anyscale <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants