Add SSL context support in benchmark function for improved connection handling

Signed-off-by: tzhouam <tzhouam@connect.ust.hk>
This commit is contained in:
tzhouam committed 2026-02-12 08:52:27 +00:00
1 parent 8c1df5c704
commit 86e20769fd
1 file changed
+4 -1
+4 -1
View File
@@ -5,6 +5,7 @@ import io
import json
import os
import random
import ssl
import sys
import time
import traceback
@@ -238,6 +239,7 @@ async def benchmark(
ramp_up_start_rps: int | None = None,
ramp_up_end_rps: int | None = None,
ready_check_timeout_sec: int = 600,
ssl_context: ssl.SSLContext | bool | None = None,
):
try:
request_func = ASYNC_REQUEST_FUNCS[endpoint_type]
@@ -245,6 +247,7 @@ async def benchmark(
raise ValueError(f"Unknown backend: {endpoint_type}") from None
# Reuses connections across requests to reduce TLS handshake overhead.
ssl_setting = ssl_context if ssl_context is not None else ("https://" in api_url)
connector = aiohttp.TCPConnector(
limit=max_concurrency or 0,
limit_per_host=max_concurrency or 0,
@@ -253,7 +256,7 @@ async def benchmark(
keepalive_timeout=60,
enable_cleanup_closed=True,
force_close=False,
ssl=("https://" in api_url),
ssl=ssl_setting,
)
session = aiohttp.ClientSession(