前端仪表板#

**LMCache 前端仪表板**是一个轻量级的网页用户界面,允许您从一个浏览器标签页监控和管理一组 LMCache 多进程 (MP) 服务器。它作为 lmcache 包的一部分提供,不需要额外的基础设施,只需一个小型发现服务。

架构概述#

架构图
+-----------------------------+
|  LMCache MP HTTP Server     |
|  (lmcache server)           |
|                             |
|  MPRuntimePluginLauncher    |                +---------------------------+
|    |                        |                |  simple_discover_service  |
|    +-> lmcache_mp_frontend  |   heartbeat    |  (lmcache.tools)          |
|        _plugin (subprocess) | -------------> |                           |
|        -> app.main()        |   (HTTP GET)   |  /lmcache_heartbeat       |
|           - HeartbeatService|                |  /lmcache_infos           |
|           - (--no-http)     |                +---------------------------+
+-----------------------------+                         |
                                                        | node supplier
                                                        v
                                          +---------------------------+
                                          |  Frontend Dashboard       |
                                          |  python -m lmcache.       |
                                          |  lmcache_frontend.app     |
                                          |  --node-supplier-url ...  |
                                          +---------------------------+

每个 LMCache MP 服务器运行一个 前端插件子进程,定期向发现服务发送心跳。仪表板查询发现服务以发现所有活动节点,并通过内置反向代理代理它们的 HTTP API。

组件#

组件

描述

lmcache.lmcache_frontend.app

FastAPI 应用程序提供 Web UI 和每个注册的 LMCache 节点的反向代理。使用 python -m lmcache.lmcache_frontend.app 启动。

lmcache_mp_frontend_plugin

MPRuntimePluginLauncher 启动的运行时插件子进程。运行 HeartbeatService``(--no-http`` 模式)以将服务器注册到发现服务。

lmcache.tools.simple_discover_service

参考 Flask 发现服务。接受 /lmcache_heartbeat 的心跳并在 /lmcache_infos 处公开节点列表。使用 python -m lmcache.tools.simple_discover_service 启动。

先决条件#

安装前端和发现服务所需的额外依赖项:

pip install flask httpx fastapi uvicorn

这些并不是通过基础的 lmcache 安装引入的,以保持其精简。

快速开始#

步骤 1 — 启动发现服务

python3 -m lmcache.tools.simple_discover_service

该服务监听 0.0.0.0:5000 并暴露:

  • GET /lmcache_heartbeat — 记录来自 MP 服务器的心跳。

  • GET /lmcache_infos — 以 JSON 格式返回所有注册的节点。

步骤 2 — 启动带有前端插件的 LMCache MP 服务器

lmcache server \
    --l1-size-gb 2 \
    --eviction-policy LRU \
    --http-host 0.0.0.0 --http-port 8085 \
    --runtime-plugin-locations \
        lmcache/lmcache_frontend/lmcache_mp_plugin/lmcache_mp_frontend_plugin.py \
    --runtime-plugin-config \
        '{"plugin.frontend.heartbeat-url": "http://localhost:5000/lmcache_heartbeat"}'

插件子进程将每 30 秒向发现服务发送一次心跳(可通过 plugin.frontend.heartbeat-interval 配置)。

或者,使用提供的示例脚本:

bash lmcache/lmcache_frontend/run_mp_server_with_frontend.sh

步骤 3 — 启动仪表板

python3 -m lmcache.lmcache_frontend.app \
    --port 8000 \
    --host 0.0.0.0 \
    --node-supplier-url http://localhost:5000/lmcache_infos

在浏览器中打开 http://localhost:8000

备注

仪表板在加载主页时,最多每 30 秒自动从供应商 URL 刷新一次节点列表。

仪表板功能#

  • 节点树视图 — 显示所有代理及其子节点,以可折叠的树形结构呈现。

  • 指标聚合GET /metrics 在仪表板上聚合来自每个叶节点的 Prometheus 指标。

  • 反向代理/proxy2/{node_name}/{path} 将请求转发到指定节点,使浏览器能够直接访问 API。

  • 健康端点GET /health 返回 {"status": "healthy"}.

CLI 参考#

python -m lmcache.lmcache_frontend.app#

标志

默认

描述

--host

0.0.0.0

仪表板 HTTP 服务器的绑定地址。

--port

8000

仪表板 HTTP 服务器的端口。

--node-supplier-url

(无)

发现服务的节点列表端点的 URL,例如 http://localhost:5000/lmcache_infos

--config

(内置)

代理节点的 JSON 配置文件路径。当未设置 --node-supplier-url 时使用。

--nodes

(无)

节点字典的内联 JSON 数组,例如 '[{\"name\":\"n1\",\"host\":\"127.0.0.1\",\"port\":\"8085\"}]'

--heartbeat-url

(无)

如果设置,仪表板本身也会向此 URL 发送心跳。

--log-level

warning

Uvicorn 日志级别 (debug, info, warning, …)。

--no-http

false

禁用 HTTP 服务器;仅运行心跳循环。由 MP 插件内部使用。

插件配置键#

在启动 MP 服务器时,将这些放在 --runtime-plugin-config 中:

描述

plugin.frontend.heartbeat-url

(必需) 发现服务的心跳端点。

plugin.frontend.heartbeat-interval

心跳间隔(单位:秒,默认值:30)。

plugin.frontend.heartbeat-initial-delay

在第一次心跳之前等待的秒数(默认值:0)。

使用自定义发现服务#

simple_discover_service 是一个参考实现。任何接受以下 GET 请求的 HTTP 服务都可以使用:

GET <heartbeat_url>?api_address=<url>&pid=<int>&version=<str>&other_info=<json>

并暴露一个节点列表端点,该端点返回形状为 JSON 的数据:

{
  "processInfos": {
    "http://host:port": {
      "lmCacheInfoEntities": [
        {"apiAddress": "http://host:port", "version": "1.0.0"}
      ]
    }
  }
}