Skip to content

Commit 59285cd

Browse files
committed
使用orjson 增加json解析速度
1 parent 93c23d3 commit 59285cd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

gpt_server/serving/openai_api_server.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import asyncio
1111
import argparse
1212
import json
13+
import orjson
1314
import os
1415
import time
1516
import traceback
@@ -629,7 +630,9 @@ async def generate_completion_stream_generator(
629630

630631

631632
async def generate_completion_stream(payload: Dict[str, Any], worker_addr: str):
632-
async with httpx.AsyncClient() as client:
633+
async with httpx.AsyncClient(
634+
limits=httpx.Limits(max_connections=1000, max_keepalive_connections=100)
635+
) as client:
633636
delimiter = b"\0"
634637
async with client.stream(
635638
"POST",
@@ -646,7 +649,7 @@ async def generate_completion_stream(payload: Dict[str, Any], worker_addr: str):
646649
chunk, buffer = buffer[:chunk_end], buffer[chunk_end + 1 :]
647650
if not chunk:
648651
continue
649-
yield json.loads(chunk.decode())
652+
yield orjson.loads(chunk.decode())
650653

651654

652655
async def generate_completion(payload: Dict[str, Any], worker_addr: str):

0 commit comments

Comments
 (0)