Update uvicorn server configuration and add pool config (#2052)
The Makefile has been updated to add support for specifying the number of workers for the uvicorn server. The pyproject.toml file has also been updated to upgrade the uvicorn dependency to version 0.30.0. Additionally, the DatabaseService class in service.py has been refactored to use the pool_size and max_overflow settings from the SettingsService. This change allows for better control over the number of connections in the connection pool and the number of connections that can be opened beyond the pool size. The create_engine function has also been modified to pass the pool_size and max_overflow parameters.
This commit is contained in:
commit
d2f144829d
8 changed files with 41 additions and 24 deletions
5
Makefile
5
Makefile
|
|
@ -7,6 +7,7 @@ port ?= 7860
|
|||
env ?= .env
|
||||
open_browser ?= true
|
||||
path = src/backend/base/langflow/frontend
|
||||
workers ?= 1
|
||||
|
||||
codespell:
|
||||
@poetry install --with spelling
|
||||
|
|
@ -144,10 +145,10 @@ backend:
|
|||
@-kill -9 $(lsof -t -i:7860)
|
||||
ifdef login
|
||||
@echo "Running backend autologin is $(login)";
|
||||
LANGFLOW_AUTO_LOGIN=$(login) poetry run uvicorn --factory langflow.main:create_app --host 0.0.0.0 --port 7860 --reload --env-file .env --loop asyncio
|
||||
LANGFLOW_AUTO_LOGIN=$(login) poetry run uvicorn --factory langflow.main:create_app --host 0.0.0.0 --port 7860 --reload --env-file .env --loop asyncio --workers $(workers)
|
||||
else
|
||||
@echo "Running backend respecting the .env file";
|
||||
poetry run uvicorn --factory langflow.main:create_app --host 0.0.0.0 --port 7860 --reload --env-file .env --loop asyncio
|
||||
poetry run uvicorn --factory langflow.main:create_app --host 0.0.0.0 --port 7860 --reload --env-file .env --loop asyncio --workers $(workers)
|
||||
endif
|
||||
|
||||
build_and_run:
|
||||
|
|
|
|||
16
poetry.lock
generated
16
poetry.lock
generated
|
|
@ -4365,7 +4365,7 @@ rich = "^13.7.0"
|
|||
sqlmodel = "^0.0.18"
|
||||
typer = "^0.12.0"
|
||||
uncurl = "^0.0.11"
|
||||
uvicorn = "^0.29.0"
|
||||
uvicorn = "^0.30.0"
|
||||
websockets = "*"
|
||||
|
||||
[package.extras]
|
||||
|
|
@ -6834,17 +6834,17 @@ typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0"
|
|||
|
||||
[[package]]
|
||||
name = "pydantic-settings"
|
||||
version = "2.2.1"
|
||||
version = "2.3.0"
|
||||
description = "Settings management using Pydantic"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "pydantic_settings-2.2.1-py3-none-any.whl", hash = "sha256:0235391d26db4d2190cb9b31051c4b46882d28a51533f97440867f012d4da091"},
|
||||
{file = "pydantic_settings-2.2.1.tar.gz", hash = "sha256:00b9f6a5e95553590434c0fa01ead0b216c3e10bc54ae02e37f359948643c5ed"},
|
||||
{file = "pydantic_settings-2.3.0-py3-none-any.whl", hash = "sha256:26eeed27370a9c5e3f64e4a7d6602573cbedf05ed940f1d5b11c3f178427af7a"},
|
||||
{file = "pydantic_settings-2.3.0.tar.gz", hash = "sha256:78db28855a71503cfe47f39500a1dece523c640afd5280edb5c5c9c9cfa534c9"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
pydantic = ">=2.3.0"
|
||||
pydantic = ">=2.7.0"
|
||||
python-dotenv = ">=0.21.0"
|
||||
|
||||
[package.extras]
|
||||
|
|
@ -9230,13 +9230,13 @@ files = [
|
|||
|
||||
[[package]]
|
||||
name = "uvicorn"
|
||||
version = "0.29.0"
|
||||
version = "0.30.1"
|
||||
description = "The lightning-fast ASGI server."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "uvicorn-0.29.0-py3-none-any.whl", hash = "sha256:2c2aac7ff4f4365c206fd773a39bf4ebd1047c238f8b8268ad996829323473de"},
|
||||
{file = "uvicorn-0.29.0.tar.gz", hash = "sha256:6a69214c0b6a087462412670b3ef21224fa48cae0e452b5883e8e8bdfdd11dd0"},
|
||||
{file = "uvicorn-0.30.1-py3-none-any.whl", hash = "sha256:cd17daa7f3b9d7a24de3617820e634d0933b69eed8e33a516071174427238c81"},
|
||||
{file = "uvicorn-0.30.1.tar.gz", hash = "sha256:d46cd8e0fd80240baffbcd9ec1012a712938754afcf81bce56c024c1656aece8"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class OpenAIModelComponent(LCModelComponent):
|
|||
self,
|
||||
input_value: Text,
|
||||
openai_api_key: str,
|
||||
temperature: Optional[float] = 0.1,
|
||||
temperature: float = 0.1,
|
||||
model_name: str = "gpt-4o",
|
||||
max_tokens: Optional[int] = 256,
|
||||
model_kwargs: NestedDict = {},
|
||||
|
|
|
|||
|
|
@ -15,4 +15,4 @@ class DatabaseServiceFactory(ServiceFactory):
|
|||
# Here you would have logic to create and configure a DatabaseService
|
||||
if not settings_service.settings.database_url:
|
||||
raise ValueError("No database URL provided")
|
||||
return DatabaseService(settings_service.settings.database_url)
|
||||
return DatabaseService(settings_service)
|
||||
|
|
|
|||
|
|
@ -21,12 +21,17 @@ from langflow.services.utils import teardown_superuser
|
|||
if TYPE_CHECKING:
|
||||
from sqlalchemy.engine import Engine
|
||||
|
||||
from langflow.services.settings.service import SettingsService
|
||||
|
||||
|
||||
class DatabaseService(Service):
|
||||
name = "database_service"
|
||||
|
||||
def __init__(self, database_url: str):
|
||||
self.database_url = database_url
|
||||
def __init__(self, settings_service: "SettingsService"):
|
||||
self.settings_service = settings_service
|
||||
if settings_service.settings.database_url is None:
|
||||
raise ValueError("No database URL provided")
|
||||
self.database_url: str = settings_service.settings.database_url
|
||||
# This file is in langflow.services.database.manager.py
|
||||
# the ini is in langflow
|
||||
langflow_dir = Path(__file__).parent.parent.parent
|
||||
|
|
@ -41,7 +46,12 @@ class DatabaseService(Service):
|
|||
connect_args = {"check_same_thread": False}
|
||||
else:
|
||||
connect_args = {}
|
||||
return create_engine(self.database_url, connect_args=connect_args)
|
||||
return create_engine(
|
||||
self.database_url,
|
||||
connect_args=connect_args,
|
||||
pool_size=self.settings_service.settings.pool_size,
|
||||
max_overflow=self.settings_service.settings.max_overflow,
|
||||
)
|
||||
|
||||
def __enter__(self):
|
||||
self._session = Session(self.engine)
|
||||
|
|
@ -267,3 +277,4 @@ class DatabaseService(Service):
|
|||
logger.error(f"Error tearing down database: {exc}")
|
||||
|
||||
self.engine.dispose()
|
||||
self.engine.dispose()
|
||||
|
|
|
|||
|
|
@ -67,6 +67,11 @@ class Settings(BaseSettings):
|
|||
|
||||
dev: bool = False
|
||||
database_url: Optional[str] = None
|
||||
"""Database URL for Langflow. If not provided, Langflow will use a SQLite database."""
|
||||
pool_size: int = 10
|
||||
"""The number of connections to keep open in the connection pool. If not provided, the default is 10."""
|
||||
max_overflow: int = 10
|
||||
"""The number of connections to allow that can be opened beyond the pool size. If not provided, the default is 10."""
|
||||
cache_type: str = "async"
|
||||
remove_api_keys: bool = False
|
||||
components_path: List[str] = []
|
||||
|
|
|
|||
16
src/backend/base/poetry.lock
generated
16
src/backend/base/poetry.lock
generated
|
|
@ -2214,17 +2214,17 @@ typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0"
|
|||
|
||||
[[package]]
|
||||
name = "pydantic-settings"
|
||||
version = "2.2.1"
|
||||
version = "2.3.0"
|
||||
description = "Settings management using Pydantic"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "pydantic_settings-2.2.1-py3-none-any.whl", hash = "sha256:0235391d26db4d2190cb9b31051c4b46882d28a51533f97440867f012d4da091"},
|
||||
{file = "pydantic_settings-2.2.1.tar.gz", hash = "sha256:00b9f6a5e95553590434c0fa01ead0b216c3e10bc54ae02e37f359948643c5ed"},
|
||||
{file = "pydantic_settings-2.3.0-py3-none-any.whl", hash = "sha256:26eeed27370a9c5e3f64e4a7d6602573cbedf05ed940f1d5b11c3f178427af7a"},
|
||||
{file = "pydantic_settings-2.3.0.tar.gz", hash = "sha256:78db28855a71503cfe47f39500a1dece523c640afd5280edb5c5c9c9cfa534c9"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
pydantic = ">=2.3.0"
|
||||
pydantic = ">=2.7.0"
|
||||
python-dotenv = ">=0.21.0"
|
||||
|
||||
[package.extras]
|
||||
|
|
@ -2890,13 +2890,13 @@ zstd = ["zstandard (>=0.18.0)"]
|
|||
|
||||
[[package]]
|
||||
name = "uvicorn"
|
||||
version = "0.29.0"
|
||||
version = "0.30.1"
|
||||
description = "The lightning-fast ASGI server."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "uvicorn-0.29.0-py3-none-any.whl", hash = "sha256:2c2aac7ff4f4365c206fd773a39bf4ebd1047c238f8b8268ad996829323473de"},
|
||||
{file = "uvicorn-0.29.0.tar.gz", hash = "sha256:6a69214c0b6a087462412670b3ef21224fa48cae0e452b5883e8e8bdfdd11dd0"},
|
||||
{file = "uvicorn-0.30.1-py3-none-any.whl", hash = "sha256:cd17daa7f3b9d7a24de3617820e634d0933b69eed8e33a516071174427238c81"},
|
||||
{file = "uvicorn-0.30.1.tar.gz", hash = "sha256:d46cd8e0fd80240baffbcd9ec1012a712938754afcf81bce56c024c1656aece8"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
|
|
@ -3265,4 +3265,4 @@ local = []
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = ">=3.10,<3.13"
|
||||
content-hash = "1dc0dd442df5d174ea85c859208f5cfea9d4785c7b7a93f2c6bf8c92e93d8cad"
|
||||
content-hash = "48a7355a7096e763b75315d0704bed8f4d8134a33553e62bc305a686b9e72803"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ langflow-base = "langflow.__main__:main"
|
|||
python = ">=3.10,<3.13"
|
||||
fastapi = "^0.111.0"
|
||||
httpx = "*"
|
||||
uvicorn = "^0.29.0"
|
||||
uvicorn = "^0.30.0"
|
||||
gunicorn = "^22.0.0"
|
||||
langchain = "~0.2.0"
|
||||
langchainhub = "~0.1.15"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue