Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛🎨♻️Director-v0: improve registry caching #6799

Merged
merged 29 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8eaeeb0
add pytest-benchmark
sanderegg Nov 21, 2024
35de004
add external registry
sanderegg Nov 21, 2024
8599207
add prefetching and generators
sanderegg Nov 21, 2024
58de786
added tests with external registry
sanderegg Nov 21, 2024
2603f5c
let's have more generators
sanderegg Nov 21, 2024
8e36edc
skip test if no external registry set
sanderegg Nov 21, 2024
20f50ec
unflake test
sanderegg Nov 21, 2024
6c7234f
add httpx client session
sanderegg Nov 21, 2024
2e6fd90
migrated to httpx
sanderegg Nov 21, 2024
f99ff9a
migrated to httpx and added retrials
sanderegg Nov 21, 2024
181c80f
5 rounds
sanderegg Nov 21, 2024
b9dccf9
@pcrespov review: use fastapi.status
sanderegg Nov 21, 2024
886d683
cleanup
sanderegg Nov 21, 2024
b7e3acf
ruff
sanderegg Nov 21, 2024
5bcaea3
make sure the settings take care of the registry settings being correct
sanderegg Nov 21, 2024
93da4df
cleanup
sanderegg Nov 21, 2024
cb37f16
missing refactoring
sanderegg Nov 21, 2024
9ebba79
encoded true is needed here
sanderegg Nov 21, 2024
83148bd
replace aioresponses with httpx
sanderegg Nov 21, 2024
6aa1350
sonarcloud: use a specific name
sanderegg Nov 22, 2024
fdd0eba
remove confusion
sanderegg Nov 22, 2024
220b215
ensure registry proxy uses internal registry URL
sanderegg Nov 22, 2024
b6aa263
ensure registry proxy uses api_url
sanderegg Nov 22, 2024
0076aec
fix api_url to return protocol
sanderegg Nov 22, 2024
7c7c431
fixes path
sanderegg Nov 22, 2024
3e3d2f1
fix encoding
sanderegg Nov 22, 2024
a594613
fix required registry URL
sanderegg Nov 22, 2024
1843d94
fix prefix
sanderegg Nov 22, 2024
cb215ae
missing env
sanderegg Nov 22, 2024
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
3 changes: 2 additions & 1 deletion services/director/requirements/_base.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
aiocache
aiodocker
fastapi[all]
httpx
httpx[http2]
prometheus-client
pydantic
tenacity
10 changes: 9 additions & 1 deletion services/director/requirements/_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ h11==0.14.0
# via
# httpcore
# uvicorn
h2==4.1.0
# via httpx
hpack==4.0.0
# via h2
httpcore==1.0.6
# via httpx
httptools==0.6.4
Expand All @@ -135,6 +139,8 @@ httpx==0.27.2
# -r requirements/../../../packages/service-library/requirements/_fastapi.in
# -r requirements/_base.in
# fastapi
hyperframe==6.0.1
# via h2
idna==3.10
# via
# anyio
Expand Down Expand Up @@ -422,7 +428,9 @@ starlette==0.41.3
# -c requirements/../../../requirements/constraints.txt
# fastapi
tenacity==9.0.0
# via -r requirements/../../../packages/service-library/requirements/_base.in
# via
# -r requirements/../../../packages/service-library/requirements/_base.in
# -r requirements/_base.in
toolz==1.0.0
# via -r requirements/../../../packages/service-library/requirements/_base.in
tqdm==4.67.0
Expand Down
1 change: 1 addition & 0 deletions services/director/requirements/_test.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ faker
jsonref
pytest
pytest-asyncio
pytest-benchmark
pytest-cov
pytest-docker
pytest-instafail
Expand Down
5 changes: 5 additions & 0 deletions services/director/requirements/_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ propcache==0.2.0
# -c requirements/_base.txt
# aiohttp
# yarl
py-cpuinfo==9.0.0
# via pytest-benchmark
pytest==8.3.3
# via
# -r requirements/_test.in
# pytest-asyncio
# pytest-benchmark
# pytest-cov
# pytest-docker
# pytest-instafail
Expand All @@ -100,6 +103,8 @@ pytest-asyncio==0.23.8
# via
# -c requirements/../../../requirements/constraints.txt
# -r requirements/_test.in
pytest-benchmark==5.1.0
# via -r requirements/_test.in
pytest-cov==6.0.0
# via -r requirements/_test.in
pytest-docker==3.1.1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
from aiohttp import ClientSession, ClientTimeout
from common_library.json_serialization import json_dumps
import httpx
from fastapi import FastAPI
from servicelib.utils import (
get_http_client_request_aiohttp_connect_timeout,
get_http_client_request_aiohttp_sock_connect_timeout,
get_http_client_request_total_timeout,
)


def setup_client_session(app: FastAPI) -> None:
async def on_startup() -> None:
# SEE https://github.com/ITISFoundation/osparc-simcore/issues/4628

# ANE: it is important to have fast connection handshakes
# also requests should be as fast as possible
# some services are not that fast to reply
timeout_settings = ClientTimeout(
total=get_http_client_request_total_timeout(),
connect=get_http_client_request_aiohttp_connect_timeout(),
sock_connect=get_http_client_request_aiohttp_sock_connect_timeout(),
)
session = ClientSession(
timeout=timeout_settings,
json_serialize=json_dumps,
)
session = httpx.AsyncClient(transport=httpx.AsyncHTTPTransport(http2=True))
app.state.aiohttp_client_session = session
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registry accepts http/2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well it does not reject it so why not use it?


async def on_shutdown() -> None:
session = app.state.aiohttp_client_session
assert isinstance(session, ClientSession) # nosec
await session.close()
assert isinstance(session, httpx.AsyncClient) # nosec
await session.aclose()

app.add_event_handler("startup", on_startup)
app.add_event_handler("shutdown", on_shutdown)


def get_client_session(app: FastAPI) -> ClientSession:
def get_client_session(app: FastAPI) -> httpx.AsyncClient:
session = app.state.aiohttp_client_session
assert isinstance(session, ClientSession) # nosec
assert isinstance(session, httpx.AsyncClient) # nosec
return session
Loading
Loading