Add --http2-max-concurrent-streams server arg (#34796)

Co-authored-by: Yilong Zhao <74357408+happierpig@users.noreply.github.com>
This commit is contained in:
cctry
2026-08-15 10:34:49 -07:00
committed by GitHub
co-authored by Yilong Zhao
parent cef8a32b9d
commit e5b3a48751
5 changed files with 81 additions and 2 deletions
@@ -2392,6 +2392,7 @@ def _run_granian_server(
host,
port,
log_level,
http2_max_concurrent_streams,
tokenizer_worker_num=1,
ssl_certfile=None,
ssl_keyfile=None,
@@ -2415,6 +2416,7 @@ def _run_granian_server(
from granian import Granian
from granian.constants import HTTPModes, Interfaces, Loops
from granian.http import HTTP2Settings
from granian.server.embed import Server as GranianEmbeddedServer
Server = GranianEmbeddedServer if tokenizer_worker_num == 1 else Granian
@@ -2427,6 +2429,9 @@ def _run_granian_server(
port=port,
interface=Interfaces.ASGI,
http=HTTPModes.auto,
http2_settings=HTTP2Settings(
max_concurrent_streams=http2_max_concurrent_streams
),
log_level=log_level,
ssl_cert=ssl_certfile,
ssl_key=ssl_keyfile,
@@ -2556,6 +2561,9 @@ def _setup_and_run_http_server(
host=server_args.host,
port=server_args.port,
log_level=server_args.log_level_http or server_args.log_level,
http2_max_concurrent_streams=(
server_args.http2_max_concurrent_streams
),
ssl_certfile=server_args.ssl_certfile,
ssl_keyfile=server_args.ssl_keyfile,
ssl_ca_certs=server_args.ssl_ca_certs,
@@ -2640,6 +2648,9 @@ def _setup_and_run_http_server(
host=server_args.host,
port=server_args.port,
log_level=server_args.log_level_http or server_args.log_level,
http2_max_concurrent_streams=(
server_args.http2_max_concurrent_streams
),
tokenizer_worker_num=server_args.tokenizer_worker_num,
ssl_certfile=server_args.ssl_certfile,
ssl_keyfile=server_args.ssl_keyfile,
+12
View File
@@ -1306,6 +1306,12 @@ class ServerArgs:
"Use Granian instead of Uvicorn as the ASGI server, enabling HTTP/1.1 and HTTP/2 auto-negotiation. Clients may use h2c (cleartext HTTP/2) or plain HTTP/1.1. Requires 'pip install sglang[http2]'.",
NS("serving"),
] = False
http2_max_concurrent_streams: A[
int,
"Maximum number of concurrent streams advertised on each HTTP/2 "
"connection (1 to 2^32 - 1). Only applies with --enable-http2.",
NS("serving"),
] = 200
# -------------------------------------------------------------------------
# SSL/TLS
@@ -4029,6 +4035,12 @@ class ServerArgs:
)
if self.enable_http2:
if not 0 < self.http2_max_concurrent_streams < 2**32:
raise ValueError(
"--http2-max-concurrent-streams must be between 1 and "
"4294967295."
)
try:
import granian # noqa: F401
except ImportError: