Skip to content

Commit

Permalink
fix: use api_server.workers from config correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
judahrand committed Sep 29, 2022
1 parent 926b613 commit 99faf91
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions bentoml/_internal/configuration/containers.py
Expand Up @@ -4,7 +4,7 @@
import uuid
import typing as t
import logging
import multiprocessing
import math
from copy import deepcopy
from typing import TYPE_CHECKING
from dataclasses import dataclass
Expand Down Expand Up @@ -449,7 +449,7 @@ def access_control_options(
return filtered_kwargs

api_server_workers = providers.Factory[int](
lambda workers: workers or (multiprocessing.cpu_count() // 2) + 1,
lambda workers: workers or math.ceil(system_resources()["cpu"]),
api_server_config.workers,
)

Expand Down
2 changes: 1 addition & 1 deletion bentoml/_internal/configuration/default_configuration.yaml
@@ -1,5 +1,5 @@
api_server:
workers: 1
workers: null # When this is set to null the number of available CPU cores is used.
timeout: 60
backlog: 2048
metrics:
Expand Down
8 changes: 4 additions & 4 deletions bentoml/serve.py
Expand Up @@ -289,7 +289,7 @@ def serve_http_production(
port: int = Provide[BentoMLContainer.http.port],
host: str = Provide[BentoMLContainer.http.host],
backlog: int = Provide[BentoMLContainer.api_server_config.backlog],
api_workers: int | None = None,
api_workers: int = Provide[BentoMLContainer.api_server_workers],
ssl_certfile: str | None = Provide[BentoMLContainer.api_server_config.ssl.certfile],
ssl_keyfile: str | None = Provide[BentoMLContainer.api_server_config.ssl.keyfile],
ssl_keyfile_password: str
Expand Down Expand Up @@ -442,7 +442,7 @@ def serve_http_production(
),
],
working_dir=working_dir,
numprocesses=api_workers or math.ceil(CpuResource.from_system()),
numprocesses=api_workers,
)
)

Expand Down Expand Up @@ -650,7 +650,7 @@ def serve_grpc_production(
port: int = Provide[BentoMLContainer.grpc.port],
host: str = Provide[BentoMLContainer.grpc.host],
backlog: int = Provide[BentoMLContainer.api_server_config.backlog],
api_workers: int | None = None,
api_workers: int = Provide[BentoMLContainer.api_server_workers],
reflection: bool = Provide[BentoMLContainer.grpc.reflection.enabled],
max_concurrent_streams: int
| None = Provide[BentoMLContainer.grpc.max_concurrent_streams],
Expand Down Expand Up @@ -808,7 +808,7 @@ def serve_grpc_production(
args=args,
use_sockets=False,
working_dir=working_dir,
numprocesses=api_workers or math.ceil(CpuResource.from_system()),
numprocesses=api_workers,
)
)

Expand Down
4 changes: 2 additions & 2 deletions bentoml_cli/serve.py
Expand Up @@ -45,7 +45,7 @@ def add_serve_command(cli: click.Group) -> None:
@click.option(
"--api-workers",
type=click.INT,
default=None,
default=BentoMLContainer.api_server_workers.get(),
help="Specify the number of API server workers to start. Default to number of available CPU cores in production mode",
envvar="BENTOML_API_WORKERS",
show_default=True,
Expand Down Expand Up @@ -249,7 +249,7 @@ def serve( # type: ignore (unused warning)
@click.option(
"--api-workers",
type=click.INT,
default=None,
default=BentoMLContainer.api_server_workers.get(),
help="Specify the number of API server workers to start. Default to number of available CPU cores in production mode",
envvar="BENTOML_API_WORKERS",
show_default=True,
Expand Down
4 changes: 2 additions & 2 deletions bentoml_cli/start.py
Expand Up @@ -63,7 +63,7 @@ def add_start_command(cli: click.Group) -> None:
@click.option(
"--api-workers",
type=click.INT,
default=None,
default=BentoMLContainer.api_server_workers.get(),
help="Specify the number of API server workers to start. Default to number of available CPU cores in production mode",
envvar="BENTOML_API_WORKERS",
)
Expand Down Expand Up @@ -295,7 +295,7 @@ def start_runner_server( # type: ignore (unused warning)
@click.option(
"--api-workers",
type=click.INT,
default=None,
default=BentoMLContainer.api_server_workers.get(),
help="Specify the number of API server workers to start. Default to number of available CPU cores in production mode",
envvar="BENTOML_API_WORKERS",
)
Expand Down

0 comments on commit 99faf91

Please sign in to comment.