Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
from fastapi import FastAPI


def setup_client_session(app: FastAPI) -> None:
def setup_client_session(app: FastAPI, *, max_keepalive_connections: int = 20) -> None:
async def on_startup() -> None:
session = httpx.AsyncClient(transport=httpx.AsyncHTTPTransport(http2=True))
session = httpx.AsyncClient(
transport=httpx.AsyncHTTPTransport(http2=True),
limits=httpx.Limits(max_keepalive_connections=max_keepalive_connections),
)
app.state.aiohttp_client_session = session

async def on_shutdown() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ def create_app(settings: ApplicationSettings) -> FastAPI:
if app.state.settings.DIRECTOR_TRACING:
initialize_tracing(app, app.state.settings.DIRECTOR_TRACING, APP_NAME)

# replace by httpx client
setup_client_session(app)
setup_client_session(
app,
max_keepalive_connections=settings.DIRECTOR_REGISTRY_CLIENT_MAX_KEEPALIVE_CONNECTIONS,
)
setup_registry(app)

setup_instrumentation(app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class ApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):
),
)

DIRECTOR_REGISTRY_CLIENT_MAX_KEEPALIVE_CONNECTIONS: PositiveInt = 0
DIRECTOR_REGISTRY_CLIENT_MAX_CONCURRENT_CALLS: PositiveInt = 20
DIRECTOR_REGISTRY_CLIENT_MAX_NUMBER_OF_RETRIEVED_OBJECTS: PositiveInt = 30

Expand Down
Loading