lmcache quota#

lmcache quota 命令管理运行中的 LMCache 服务器上的每个 salt 的缓存配额。配额是软限制:超过配额会在下一个周期(约 1 秒)触发逐出,而不是拒绝写入。

lmcache quota <sub-command> [options]
$ lmcache quota -h
usage: lmcache quota [-h] {set,get,list,delete} ...

Manage per-salt cache quotas on the LMCache server.

subcommands:
  set            Create or update a quota for a cache_salt
  get            Show the quota and current usage for a cache_salt
  list           List all registered quotas and their usage
  delete         Remove a quota for a cache_salt

options:
  -h, --help     show this help message and exit

设置#

为给定的 cache_salt 创建或更新配额。

lmcache quota set <salt> --limit-gb <GB> [--url <URL>]

示例:

$ lmcache quota set tenant1 --limit-gb 10.5

================ Quota Set =================
Cache salt:                          tenant1
Limit (GB):                             10.5
Status:                                   ok
=============================================

选项:

标志

必需的

描述

<salt>

cache_salt 标识符。对于匿名(未加盐)流量,请使用 _default

--limit-gb

以千兆字节为单位的配额限制(非负浮点数)。

--url

LMCache HTTP 服务器 URL(默认:http://localhost:8080)。

--format

输出格式:terminal(默认)或json

--output

将输出保存到文件中(使用 --format 选择的格式)。

-q / --quiet

抑制标准输出。仅返回退出代码。

获取#

显示特定 cache_salt 的当前配额限制和实时使用情况。

lmcache quota get <salt> [--url <URL>]

示例:

$ lmcache quota get tenant1

================ Quota Info ================
Cache salt:                          tenant1
Limit (GB):                             10.5
Current usage (GB):                     3.27
Exists:                                 True
=============================================

选项:

标志

必需的

描述

<salt>

cache_salt 标识符。

--url

LMCache HTTP 服务器 URL(默认:http://localhost:8080)。

--format

输出格式:terminal(默认)或json

--output

将输出保存到文件。

-q / --quiet

抑制标准输出。

列出#

列出所有注册的配额及其当前使用情况。

lmcache quota list [--url <URL>]

示例:

$ lmcache quota list

=================== Quota List ====================
--- Salt: tenant1 ---
Cache salt:                               tenant1
Limit (GB):                                  10.5
Current usage (GB):                          3.27
--- Salt: _default ---
Cache salt:                              _default
Limit (GB):                                   5.0
Current usage (GB):                          1.82
===================================================

JSON 输出:

$ lmcache quota list --format json
{
  "title": "Quota List",
  "sections": {
    "quota_0": {
      "label": "Salt: tenant1",
      "metrics": {
        "cache_salt": "tenant1",
        "limit_gb": 10.5,
        "current_usage_gb": 3.27
      }
    },
    "quota_1": {
      "label": "Salt: _default",
      "metrics": {
        "cache_salt": "_default",
        "limit_gb": 5.0,
        "current_usage_gb": 1.82
      }
    }
  }
}

选项:

标志

必需的

描述

--url

LMCache HTTP 服务器 URL(默认:http://localhost:8080)。

--format

输出格式:terminal(默认)或json

--output

将输出保存到文件。

-q / --quiet

抑制标准输出。

删除#

删除给定 cache_salt 的配额条目。此盐下仍然缓存的任何字节将在下一个逐出周期中超出预算,并将被逐出(有效限制降至 0)。

lmcache quota delete <salt> [--url <URL>]

示例:

$ lmcache quota delete tenant1

============== Quota Delete ===============
Cache salt:                        tenant1
Status:                            removed
===========================================

选项:

标志

必需的

描述

<salt>

cache_salt 标识符。

--url

LMCache HTTP 服务器 URL(默认:http://localhost:8080)。

--format

输出格式:terminal(默认)或json

--output

将输出保存到文件。

-q / --quiet

抑制标准输出。

退出代码#

代码

含义

0

成功。

1

错误(连接失败、服务器错误、参数错误)。

_default#

LMCache 服务器使用空字符串 ("") 作为匿名 / 未加盐流量的 cache_salt。由于空字符串不能出现在 URL 路径参数中,HTTP API(以及此 CLI)使用哨兵 _default 代替。

# Set a 5 GB quota for anonymous traffic
lmcache quota set _default --limit-gb 5.0

# Check usage
lmcache quota get _default

常见模式#

为多个租户配置配额:

for tenant in tenant_a tenant_b tenant_c; do
    lmcache quota set "$tenant" --limit-gb 8.0
done

在脚本中监控使用情况:

USAGE=$(lmcache quota get tenant1 --format json | jq '.metrics.current_usage_gb')
LIMIT=$(lmcache quota get tenant1 --format json | jq '.metrics.limit_gb')
echo "tenant1: ${USAGE} / ${LIMIT} GB"

撤销访问(逐出所有缓存数据以便于一个盐):

# Deleting the quota causes all data under this salt to be evicted
lmcache quota delete tenant1