Skip to content

Commit a27dfc8

Browse files
feat: replace gunicorn with hypercorn for http2 (h2c) support (#1211)
Co-authored-by: Siyu Wu <wu.siyu@hotmail.com>
1 parent e15b056 commit a27dfc8

4 files changed

Lines changed: 11 additions & 23 deletions

File tree

lightllm/server/api_start.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .embed_cache.manager import start_cache_manager
1111
from lightllm.utils.log_utils import init_logger
1212
from lightllm.utils.envs_utils import set_env_start_args, set_unique_server_name, get_unique_server_name
13-
from lightllm.utils.envs_utils import get_lightllm_gunicorn_time_out_seconds, get_lightllm_gunicorn_keep_alive
13+
from lightllm.utils.envs_utils import get_lightllm_gunicorn_keep_alive
1414
from .detokenization.manager import start_detokenization_process
1515
from .router.manager import start_router_process
1616
from lightllm.utils.process_check import is_process_active
@@ -333,13 +333,11 @@ def normal_or_p_d_start(args):
333333
],
334334
)
335335

336-
# 启动 gunicorn
336+
# 启动 Hypercorn
337337
command = [
338-
"gunicorn",
338+
"hypercorn",
339339
"--workers",
340340
f"{args.httpserver_workers}",
341-
"--worker-class",
342-
"uvicorn.workers.UvicornWorker",
343341
"--bind",
344342
f"{args.host}:{args.port}",
345343
"--log-level",
@@ -349,8 +347,6 @@ def normal_or_p_d_start(args):
349347
"--error-logfile",
350348
"-",
351349
"lightllm.server.api_http:app",
352-
"--timeout",
353-
f"{get_lightllm_gunicorn_time_out_seconds()}",
354350
"--keep-alive",
355351
f"{get_lightllm_gunicorn_keep_alive()}",
356352
]
@@ -403,11 +399,9 @@ def pd_master_start(args):
403399
)
404400

405401
command = [
406-
"gunicorn",
402+
"hypercorn",
407403
"--workers",
408404
"1",
409-
"--worker-class",
410-
"uvicorn.workers.UvicornWorker",
411405
"--bind",
412406
f"{args.host}:{args.port}",
413407
"--log-level",
@@ -418,8 +412,6 @@ def pd_master_start(args):
418412
"-",
419413
"--preload",
420414
"lightllm.server.api_http:app",
421-
"--timeout",
422-
f"{get_lightllm_gunicorn_time_out_seconds()}",
423415
"--keep-alive",
424416
f"{get_lightllm_gunicorn_keep_alive()}",
425417
]
@@ -445,11 +437,9 @@ def config_server_start(args):
445437
set_env_start_args(args)
446438

447439
command = [
448-
"gunicorn",
440+
"hypercorn",
449441
"--workers",
450442
"1",
451-
"--worker-class",
452-
"uvicorn.workers.UvicornWorker",
453443
"--bind",
454444
f"{args.config_server_host}:{args.config_server_port}",
455445
"--log-level",
@@ -460,8 +450,6 @@ def config_server_start(args):
460450
"-",
461451
"--preload",
462452
"lightllm.server.config_server.api_http:app",
463-
"--timeout",
464-
f"{get_lightllm_gunicorn_time_out_seconds()}",
465453
"--keep-alive",
466454
f"{get_lightllm_gunicorn_keep_alive()}",
467455
]

lightllm/server/req_id_generator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,14 @@ def _find_sibling_processes():
125125

126126
# 查找兄弟进程
127127
sibling_processes = []
128-
for proc in psutil.process_iter(["pid", "name"]):
128+
for proc in psutil.process_iter(["pid", "name", "cmdline"]):
129129
try:
130130
# 检查是否是兄弟进程(同一父进程且不是当前进程)
131131
if proc.pid != current_pid and proc.ppid() == parent_process.pid:
132+
# 过滤掉 multiprocessing.resource_tracker 进程
133+
cmdline = proc.cmdline()
134+
if cmdline and "multiprocessing.resource_tracker" in " ".join(cmdline):
135+
continue
132136
sibling_processes.append(proc)
133137
except (psutil.NoSuchProcess, psutil.AccessDenied):
134138
continue

lightllm/utils/envs_utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ def get_deepep_num_max_dispatch_tokens_per_rank():
7171
return int(os.getenv("NUM_MAX_DISPATCH_TOKENS_PER_RANK", 256))
7272

7373

74-
def get_lightllm_gunicorn_time_out_seconds():
75-
return int(os.getenv("LIGHTLMM_GUNICORN_TIME_OUT", 180))
76-
77-
7874
def get_lightllm_gunicorn_keep_alive():
7975
return int(os.getenv("LIGHTLMM_GUNICORN_KEEP_ALIVE", 10))
8076

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ujson==5.10.0
7979
frozendict==2.4.6
8080
atomics==1.0.3
8181
easydict==1.13
82-
gunicorn==23.0.0
82+
hypercorn==0.18.0
8383
flashinfer-python==0.2.4
8484
sgl-kernel==0.3.7.post1
8585
httpx==0.28.1

0 commit comments

Comments
 (0)