vcon-server

Bound the open tenants

Close a tenant's Store when no request has used it for a while, or past a number of open tenants, so its keys leave memory: the two configuration keys, the restart, the check of locked memory, the memory-lock limit to set, and what a bound costs.

A tenant's Store holds the tenant's key and its catalog's key in locked memory, and an open catalog connection, from the first request for the tenant until the server stops. A start opens every tenant's Store to check its keys. With many tenants, that memory grows with every tenant, and every tenant's key stays in memory while the server runs. Two keys bound it:

  • key_wrap.idle_close_after closes a Store that no request has used for that many seconds;
  • key_wrap.max_open_tenants keeps at most that many Stores open, closing the least recently used one that no request holds.

A closed Store's keys are zeroed. The next request for the tenant opens its Store again; what a bound costs gives the measured cost. Neither key is set unless you set it, so a server without them keeps every Store open, as before. This how-to sets both, checks the server's locked memory, and sizes the memory-lock limit.

The keys are new in 0.4.20. CI runs every command on this page against a live server, after getting started, and checks each answer.

What a bound costs

A Store that is open answers at once. A request for a tenant whose Store is closed opens it first, and, at the cap, closes the least recently used one. With the cap at or above the tenants that take requests, few requests open a Store; with a cap far below them, most do. Measured on a 14-core Jetson AGX Thor with the scale harness (2,000 stores then 2,000 reads, 8 clients, the SQLite catalog), all on 2026-11-30, at 1-minute loads of 12 to 27; the runs of 1,000 tenants used one prepared data directory:

TenantsTaking requestsmax_open_tenantsStores a secondRead p99Start, to serving
1,0001,000none1,058 (median of 3)4.8 ms (median of 3)1 to 2 s
1,00064none1,3787.2 ms1 s
1,000646430117.6 ms2 s
1,0001,0006420646.0 ms2 s
1,0001,0001196102.3 ms1 s
100100none96011.8 msunder 1 s
1001006426016.3 msunder 1 s

Each run lasted 5 to 25 seconds, so the passes of the background jobs at start, below, fall inside it: under a cap those passes open most of the other tenants' Stores while the run stores. On the same machine a different day gave different figures for the same runs, so compare rows of one table only.

A start opens every tenant's Store once to check its keys, closing the least recently used past the cap as it goes. Three background jobs also go through every tenant on each pass: the purge sweep (at start and each purge_interval), the rotation warning (at start and once a day) and, with Parquet storage, the pack run. Under a cap far below the number of tenants, each pass opens most Stores again.

How much memory the server locks

The server locks every page it maps, so LimitMEMLOCK must cover all of its memory, not only its keys: the program, each thread's stack (2 MiB), the C library's memory arenas (up to 64 MiB each, counted in full whether used or not), and each open tenant's Store. LimitMEMLOCK=infinity, as getting started sets it, needs no sizing and is what this page recommends. For a number, in KiB:

40,960 + 1,092 + 2,048 x threads + 65,536 x arenas + 300 x open tenants
  • 40,960: the program, its libraries and its first allocations, for a release build; a debug build of the same code maps about 22 MiB more.
  • 1,092: the catalogs' page cache, which the server gives SQLite at start: 256 pages of 4,368 bytes each. SQLite takes pages from it before it asks for more memory.
  • threads: the server's threads (Threads: in /proc/<pid>/status): at most limits.workers, plus limits.blocking_threads for disk and catalog work, plus 2, plus 10 with S3 storage and 10 with a PostgreSQL catalog (each client's own 2 workers and at most 8 blocking threads). See locked memory for both keys and the limit they set.
  • arenas: the C library's arenas past the main one. The server limits malloc to two arenas unless its environment sets MALLOC_ARENA_MAX, or glibc.malloc.arena_max in GLIBC_TUNABLES, so count 1; with a larger setting, count that number less one.
  • open tenants: max_open_tenants, or every tenant without it.

Measured on the machine above on 2026-11-27, VmLck at the end of a run, with a build from before the server limited its arenas, so the rows with MALLOC_ARENA_MAX not set show the C library's own limit:

Tenantsmax_open_tenantsMALLOC_ARENA_MAXThreadsVmLck
1none230164,412 KiB
1,000none229402,428 KiB
1,00064228159,708 KiB
1nonenot set322,132,940 KiB (31 arenas)
1,0001not set281,862,348 KiB (27 arenas)

Each open tenant added about 280 KiB: the difference between the first two rows, with the threads' stacks and the one arena only the first row had taken out. The run at a cap of 64 locked 159,708 KiB, under the formula's 184,132 for its 28 threads and one arena; how much of that the closed Stores left behind was not measured, so keep the formula's arena term even where a run showed none.

Before you start

  • A running server, set up as getting started leaves it: its configuration in /etc/vcon-server/vcon-server.toml.
  • A shell on the server's host, with sudo. The configuration changes and the server restarts, so every request waits or fails for the seconds the restart takes.
  • How many tenants are active: the tenants that take requests within the idle bound. A cap below that number makes most requests open a Store.
  • Changes on other systems: none. Under systemd, the unit's LimitMEMLOCK is the only setting that may change, and only if you give it a number in place of infinity.
  • One shell for the steps: later steps use variables that earlier steps set.

Steps

  1. Set the variable the steps use, and read how many tenants there are and what the server locks now: the locked memory in KiB and its threads.

    CONFIG=/etc/vcon-server/vcon-server.toml
    sudo -u vcon vcon-server tenant list --config $CONFIG | jq -s length
    awk '/^(VmLck|Threads):/ {print $1, $2}' /proc/$(pidof vcon-server)/status
    
    <tenants>
    VmLck: <kib>
    Threads: <threads>
    
  2. Add the two keys in a [key_wrap] table at the end of the configuration. This page closes a Store after 15 minutes unused and keeps at most 64 open; choose the cap from the active tenants (see what a bound costs):

    printf '\n[key_wrap]\nidle_close_after = 900\nmax_open_tenants = 64\n' | sudo tee -a $CONFIG >/dev/null
    tail -n 3 $CONFIG
    
    [key_wrap]
    idle_close_after = 900
    max_open_tenants = 64
    
  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
    …
    

Check it

The server started with the keys: it refuses a value out of range by name (see when a step fails). Compare its locked memory with the formula, for its threads, the one arena past the main one that the server allows itself and the cap of 64, plus the 25% that locked memory adds for other hosts and loads:

awk '/^VmLck:/ {l = $2} /^Threads:/ {t = $2}
  END {limit = int((40960 + 1092 + 2048 * t + 65536 + 300 * 64) * 5 / 4)
       print (l <= limit ? "within the bound" : "over the bound: " l " KiB, more than " limit)}' \
  /proc/$(pidof vcon-server)/status
within the bound

A Store closes once no request has used it for idle_close_after seconds; the server checks at least once a minute, so a Store closes at most a minute late. Nothing is logged at a close.

Go back to no bounds

Take the table out and restart the server as in step 3. Every Store then stays open from its first request until the server stops, as without the keys:

sudo sed -i '/^\[key_wrap\]$/,/^max_open_tenants = /d' $CONFIG
grep -c key_wrap $CONFIG || true
0
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
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
…

When a step fails

  • vcon-server: configuration: key_wrap.max_open_tenants = 0: 1 to 1000000 tenants' Stores may be open at once: the cap is out of range. Give a number from 1 to 1000000.
  • vcon-server: configuration: key_wrap.idle_close_after = 0: a tenant's Store closes after 1 to 31536000 seconds unused: the idle bound is out of range. Give a number of seconds from 1 to 31536000 (a year).
  • unknown field idle_close_after`` (or max_open_tenants): release 0.4.19 has the [key_wrap] table without these two keys. Take them out, or upgrade.
  • unknown field key_wrap``: release 0.4.18 and earlier have no [key_wrap] table. Take the table out, or upgrade.
  • duplicate key, pointing at [key_wrap]: the configuration already has a [key_wrap] table. Put the two keys in that table in place of a second one.
  • vcon-server: memory cannot be locked: …: the memory-lock limit is below what the server locks. Raise it as in how much memory the server locks, or set LimitMEMLOCK=infinity.
  • Requests slow down after the change: the cap is below the number of active tenants, so most requests open a Store, and each open closes another. Raise max_open_tenants above the active tenants, or remove it and keep idle_close_after alone.
  • The check prints over the bound: more threads or tenants are open than the formula's numbers allow for, or the environment allows more arenas. Compare Threads with limits.workers and limits.blocking_threads, check MALLOC_ARENA_MAX in the server's environment, and read the formula's terms again.

Source of this page: website/content/docs/bound-open-tenants.md