Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
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
15 changes: 13 additions & 2 deletions lightly_studio/src/lightly_studio/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,19 @@ def __init__(self, host: str, port: int) -> None:

def start(self) -> None:
"""Start the API server using Uvicorn."""
# start the app
uvicorn.run(app, host=self.host, port=self.port, http="h11")
# start the app with connection limits and timeouts
uvicorn.run(
app,
host=self.host,
port=self.port,
http="h11",
# https://uvicorn.dev/settings/#resource-limits
limit_concurrency=100, # Max concurrent connections
limit_max_requests=10000, # Max requests before worker restart
# https://uvicorn.dev/settings/#timeouts
timeout_keep_alive=5, # Keep-alive timeout in seconds
timeout_graceful_shutdown=30, # Graceful shutdown timeout
)


def _get_available_port(host: str, preferred_port: int, max_tries: int = 50) -> int:
Expand Down
18 changes: 17 additions & 1 deletion lightly_studio/src/lightly_studio/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import logging
import os
from contextlib import contextmanager
from pathlib import Path
from typing import Generator
Expand Down Expand Up @@ -41,7 +42,22 @@ def __init__(
self._engine_url = engine_url if engine_url else "duckdb:///lightly_studio.db"
if cleanup_existing:
_cleanup_database_file(engine_url=self._engine_url)
self._engine = create_engine(url=self._engine_url, poolclass=poolclass)

# Configuration for testing
self._engine = create_engine(
url=self._engine_url,
poolclass=poolclass,
)

# Total available connections = pool_size + max_overflow = 10 + 40 = 50
# (default is (pool_size=5, max_overflow=10))
if "PYTEST_CURRENT_TEST" not in os.environ:
self._engine = create_engine(
url=self._engine_url,
pool_size=10,
max_overflow=40,
)

SQLModel.metadata.create_all(self._engine)

@contextmanager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
});
</script>

<div bind:this={triggerRef}></div>
<div bind:this={triggerRef} style="height: 1px; width: 1px;"></div>
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const buildRequestBody = (params: ImagesInfiniteParams, pageParam: number): Read
const baseBody: ReadImagesRequest = {
pagination: {
offset: pageParam,
limit: 100
limit: 20
},
text_embedding: params.text_embedding,
filters: {
Expand Down
Loading