MCPcopy
hub / github.com/InternLM/lmdeploy / start_proxy_server

Function start_proxy_server

autotest/utils/run_restful_chat.py:1215–1278  ·  view source on GitHub ↗

Start the proxy server for testing with enhanced error handling and logging.

(log_path, port, case_name: str = 'default')

Source from the content-addressed store, hash-verified

1213
1214
1215def start_proxy_server(log_path, port, case_name: str = 'default'):
1216 """Start the proxy server for testing with enhanced error handling and
1217 logging."""
1218 if log_path is None:
1219 log_path = '/nvme/qa_test_models/evaluation_report'
1220
1221 timestamp = time.strftime('%Y%m%d_%H%M%S')
1222 proxy_log = os.path.join(log_path, f'proxy_server_{case_name}_{str(port)}_{timestamp}.log')
1223
1224 proxy_url = f'http://{DEFAULT_SERVER}:{port}' # noqa: E231, E261
1225 try:
1226 response = requests.get(f'{proxy_url}/nodes/status', timeout=5)
1227 if response.status_code == 200:
1228 print(f'Terminating existing nodes on proxy {proxy_url}')
1229 requests.get(f'{proxy_url}/nodes/terminate_all', timeout=10)
1230 time.sleep(5)
1231 except requests.exceptions.RequestException:
1232 pass
1233
1234 cmd = (f'lmdeploy serve proxy --server-name {DEFAULT_SERVER} --server-port {port} '
1235 f'--routing-strategy min_expected_latency --serving-strategy Hybrid')
1236
1237 print(f'Starting proxy server with command: {cmd}')
1238 print(f'Proxy log will be saved to: {proxy_log}')
1239
1240 proxy_file = open(proxy_log, 'w')
1241 proxy_process = subprocess.Popen([cmd],
1242 stdout=proxy_file,
1243 stderr=proxy_file,
1244 shell=True,
1245 text=True,
1246 encoding='utf-8')
1247 pid = proxy_process.pid
1248
1249 start_time = int(time.time())
1250 timeout = 300
1251
1252 time.sleep(5)
1253 for i in range(timeout):
1254 time.sleep(1)
1255 if proxy_health_check(f'http://{DEFAULT_SERVER}:{port}'): # noqa: E231, E261
1256 break
1257
1258 try:
1259 # Check if process is still running
1260 return_code = proxy_process.wait(timeout=1) # Small timeout to check status
1261 if return_code != 0:
1262 with open(proxy_log) as f:
1263 content = f.read()
1264 print(content)
1265 return 0, proxy_process
1266 except subprocess.TimeoutExpired:
1267 continue
1268
1269 end_time = int(time.time())
1270 total_time = end_time - start_time
1271 if total_time >= timeout:
1272 break

Callers 2

run_eval_testFunction · 0.90
run_eval_testFunction · 0.90

Calls 6

proxy_health_checkFunction · 0.85
joinMethod · 0.80
getMethod · 0.45
sleepMethod · 0.45
waitMethod · 0.45
closeMethod · 0.45

Tested by 2

run_eval_testFunction · 0.72
run_eval_testFunction · 0.72