optuna.storages.run_grpc_proxy_server

optuna.storages.run_grpc_proxy_server(storage, *, host='localhost', port=13000, thread_pool=None)[source]

为给定的存储 URL、主机和端口运行 gRPC 服务器。

示例

以下列方式运行此服务器

from optuna.storages import run_grpc_proxy_server
from optuna.storages import get_storage

storage = get_storage("mysql+pymysql://<user>:<pass>@<host>/<dbname>[?<options>]")
run_grpc_proxy_server(storage, host="localhost", port=13000)

请参考客户端类 GrpcStorageProxy 了解客户端用法。请使用 get_storage() 而不是 RDBStorage,因为 RDBStorage 本身在进程中不使用缓存,这可能导致显著的性能下降。

参数:
  • storage (BaseStorage) – 一个要代理的存储对象。

  • host (str) – 监听的主机名。

  • port (int) – 监听的端口。

  • thread_pool (ThreadPoolExecutor | None) – 用于服务器的线程池。如果为 None,将使用默认的包含 10 个工作线程的线程池。

返回类型:

None

注意

在 v4.2.0 中作为实验性功能添加。接口可能在更新版本中更改,恕不另行通知。参见 https://github.com/optuna/optuna/releases/tag/v4.2.0