vcon-server

Tenant limits

Limit how many requests a second each key and each tenant may send, and how much storage each tenant may keep: the configuration, the restart, the refusals a client sees, one tenant's own limits, the usage, and how to take the limits away.

On a server shared by several tenants, one tenant can send enough requests, or store enough vCons, to slow every other tenant or fill the disk. The [limits.rate] and [limits.quota] tables bound each tenant:

LimitKeyA request past it
Requests a second of one keylimits.rate.key429 rate-limited, limit "key"
Requests a second of all the keys of one tenantlimits.rate.tenant429 rate-limited, limit "tenant"
Bytes one tenant keepslimits.quota.bytes507 quota-exceeded, limit "bytes"
vCons one tenant keepslimits.quota.vcons507 quota-exceeded, limit "vcons"

Every key is off unless set, and each applies to every tenant that has no value of its own: an operator can set any of them for one tenant, with vcon-server tenant limits or PUT /admin/tenants/{id}/limits (see one tenant's own limits). A session's requests take from its tenant's rate as its keys' do. A refused request is answered before its body is read and before its route runs. A rate's _burst key (limits.rate.key_burst, limits.rate.tenant_burst) sets how many requests may come at once above the rate; unset, it is one second of the rate. See configuration for the bounds of each key.

CI runs every command on this page against a live server, after getting started and the first vCon, and checks each answer.

Before you start

  • A running server, set up as in getting started, with the tenant acme holding at least one vCon, as the first vCon stores.
  • One shell for every step: later steps use variables that earlier steps set.
  • On other systems: a client that is refused 429 should wait the Retry-After seconds before it sends again. A load balancer in front of several servers on one PostgreSQL database spreads a tenant's requests over them, and each server counts the requests it receives: with N servers, a tenant may send up to N times limits.rate.tenant in all, so set the rate to the total divided by N. The storage quota is one figure for the whole database, whichever server takes the write.

Steps

  1. Set the variables the steps use, and make a key of acme that may read and write. key create runs beside the server:

    CONFIG=/etc/vcon-server/vcon-server.toml
    CA=/usr/local/share/vcon-server/ca.pem
    URL=https://vcon.example.com:8443
    TENANT=$(sudo -u vcon vcon-server tenant list --config $CONFIG | jq -r 'select(.name == "acme") | .id')
    KEY=$(sudo -u vcon vcon-server key create --tenant "$TENANT" --scope read --scope write --label limits --config $CONFIG | jq -r .token)
    
  2. Add the two tables to the end of the configuration: one request a second for each tenant, and one vCon for each tenant. These numbers are small so that the checks below reach them; choose your own from what each tenant needs:

    printf '\n[limits.rate]\ntenant = 1\n\n[limits.quota]\nvcons = 1\n' | sudo tee -a $CONFIG >/dev/null
    
  3. Restart the server. Under systemd:

    sudo systemctl restart vcon-server
    timeout 30 sh -c 'until curl -s -o /dev/null --cacert /usr/local/share/vcon-server/ca.pem https://vcon.example.com:8443/health; do sleep 1; done' && echo answering
    
    answering
    

    Or, without systemd, stop it and start it again:

    sudo kill -TERM "$(pidof vcon-server)"
    while pidof vcon-server >/dev/null; do sleep 0.2; done
    
    sudo -u vcon vcon-server serve --config /etc/vcon-server/vcon-server.toml
    
    <time>  INFO vcon_server::serve: serving listen=0.0.0.0:8443
    …
    

    A value out of bounds stops the start with a line that names the key, such as limits.rate.tenant must be more than 0: leave it out for no limit.

Check it

  1. Two requests at once, on one connection: the first is answered, and the second is past the tenant's one request a second. curl takes one -o for each URL, so each answer's body is set aside and only the codes are printed:

    sleep 1
    curl -sS -o /dev/null -o /dev/null -w '%{http_code}\n' --cacert $CA -H "Authorization: Bearer $KEY" "$URL/vcons" "$URL/vcons"
    
    200
    429
    
  2. The refusal says which limit refused it and when to come back:

    sleep 1
    curl -sS -o /dev/null --cacert $CA -H "Authorization: Bearer $KEY" "$URL/vcons"
    curl -sS -D - -o /dev/null --cacert $CA -H "Authorization: Bearer $KEY" "$URL/vcons" | grep -i '^retry-after'
    
    retry-after: 1
    

    The problem document carries the same wait in milliseconds, retry_after_ms, and limit: "tenant". The refusals are counted in the tenant's audit log as rate_limited, one record a minute for each key, with the number refused.

  3. acme already keeps a vCon, so a new one is past its quota of one:

    sleep 1
    OVER=$(cat /proc/sys/kernel/random/uuid)
    curl -sS --cacert $CA -X POST "$URL/vcons" -H "Authorization: Bearer $KEY" \
      -H "Content-Type: application/vcon" \
      -d "{\"uuid\": \"$OVER\", \"created_at\": \"2026-10-23T12:00:00Z\", \"parties\": []}" | jq -r '.type, .limit, .quota'
    
    https://vcon-server.com/problems/quota-exceeded
    vcons
    1
    

    Nothing was kept: reads, lists and deletes still work, and only a new store or a replace is refused.

Set one tenant's own limits

An operator can give one tenant values of its own over the server's: rate, rate_burst, key_rate, key_burst, bytes and vcons, the names of the configuration's keys. Each is a number, none for no limit for that tenant (a rate or a quota; a burst is a number), or default for the server's value. The command line's vcon-server tenant limits runs beside the server, and the operator route PUT /admin/tenants/{id}/limits takes the same names in a JSON body, with null for default; both make the same change and record tenant_limits in the admin log and limits in the tenant's. A tenant cannot change its own limits.

The server that takes the route's request puts the change in force at once. Every other server, and a running server when the change came from the command line, reads the limits again when its copy is 10 seconds old, at the next request after that, so a change reaches it within about 10 seconds; until then it answers with the limits it read before. No request waits for that read.

  1. Give acme room for one vCon more than it keeps. tenant limits with no flag prints its usage; with --vcons it sets the tenant's own quota:

    KEPT=$(sudo -u vcon vcon-server tenant limits "$TENANT" --config $CONFIG | jq .usage.vcons)
    sudo -u vcon vcon-server tenant limits "$TENANT" --vcons $((KEPT + 1)) --config $CONFIG | jq -r .limits.vcons.source
    
    tenant
    
  2. Within the 10 seconds, the server takes the new quota, and the store that was refused above is kept:

    ROOM=$(cat /proc/sys/kernel/random/uuid)
    for try in $(seq 15); do
      sleep 2
      code=$(curl -sS -o /dev/null -w '%{http_code}' --cacert $CA -X POST "$URL/vcons" \
        -H "Authorization: Bearer $KEY" -H "Content-Type: application/vcon" \
        -d "{\"uuid\": \"$ROOM\", \"created_at\": \"2026-10-23T12:00:00Z\", \"parties\": []}")
      [ "$code" = 201 ] && break
    done
    echo "$code"
    
    201
    
  3. Read the tenant's limits, each with its source, and its usage:

    sudo -u vcon vcon-server tenant limits "$TENANT" --config $CONFIG | jq -r '.limits.vcons.source, .limits.rate.source, .limits.rate.value'
    
    tenant
    server
    1
    

    Each limit is {"source", "value"}: tenant or server, and the value in force, or null for no limit.

    The same answer, with usage, is GET /admin/tenants/{id}/limits for an operator key. A key of the tenant that holds tenant_admin reads its own limits and usage at GET /tenant/usage, and no other tenant's.

  4. Return the quota to the server's:

    sudo -u vcon vcon-server tenant limits "$TENANT" --vcons default --config $CONFIG | jq -r '.limits.vcons.source, .limits.vcons.value'
    
    server
    1
    

See each tenant's usage

vcon-server check reports each tenant's storage as usage: the bytes of every version it keeps, as they were sent, the versions and the vCons. It does not run beside the server, so stop the server first. Under systemd:

sudo systemctl stop vcon-server

Or, without systemd:

sudo kill -TERM "$(pidof vcon-server)"
while pidof vcon-server >/dev/null; do sleep 0.2; done

Then:

sudo -u vcon vcon-server check --config $CONFIG | jq -c 'select(.name == "acme") | .usage | keys'
["bytes","vcons","versions"]

usage_counter is the counter the server keeps for the quota, or null for a tenant it has not counted yet. When the two differ, check names it as a problem, and vcon-server tenant recount <id> --config $CONFIG counts the tenant's rows again and keeps that count as its counter. It runs beside a running server: the count and the new counter are one transaction under the tenant's write lock, so a store at the same time is counted once.

Take the limits away

Take the two tables out, as step 2 wrote them at the end of the file, and start the server again:

sudo sed -i '/^\[limits\.rate\]$/,$d' $CONFIG

Under systemd:

sudo systemctl start vcon-server
timeout 30 sh -c 'until curl -s -o /dev/null --cacert /usr/local/share/vcon-server/ca.pem https://vcon.example.com:8443/health; do sleep 1; done' && echo answering
answering

Or, without systemd:

sudo -u vcon vcon-server serve --config /etc/vcon-server/vcon-server.toml
<time>  INFO vcon_server::serve: serving listen=0.0.0.0:8443
…

When a step fails

  • The server does not start after step 2. The line it printed names the key: a rate of 0 or over 1000000, a burst without its rate, or a quota of 0. Fix the value, or leave the key out for no limit.
  • Step 1 of the check answers 200 twice. The two requests were more than a second apart, or the configuration was not read again: check that the server was restarted after step 2, and that [limits.rate] is in the file it reads (--config).
  • A client is refused 429 that should not be. All the keys of a tenant share limits.rate.tenant: another key of the same tenant may be sending. The tenant's audit log counts the refusals by key (rate_limited).
  • A store is refused 507 with room left on the disk. The quota counts the bodies of every version a tenant keeps, deleted ones included until they are purged, and a replace adds its whole body because the old version is kept. Raise limits.quota.bytes, or let the retention period purge old versions. vcon-server tenant limits <id> prints which value is in force and whether it is the tenant's own or the server's.
  • A change made with tenant limits is not in force yet. A running server reads the limits again within about 10 seconds; step 2 above tries for 30. A change that keeps being ignored was made with a configuration that names another data directory or database: run tenant limits <id> with the server's --config.
  • tenant limits refuses a value. The line names the reason: a rate of 0 or over 1000000, a burst without its rate, a quota of 0 or over the largest, or a name that is not one of the six.

Source of this page: website/content/docs/tenant-limits.md