Server
Run fennecdb as a server: one process over one file, reached over HTTP from any language.
Start and query
-
Start the server on a file.
fennec-server --file data.fennec --http 127.0.0.1:8080 -
Send it a query.
curl -s -X POST localhost:8080/query \ -d '{"query": "get articles select title near embed $1 limit 5", "params": [[0.1, 0.2]]}'
Everything the server does goes over that one listener: queries and the REST routes, subscriptions, replication, change data capture, metrics and the admin routes of a tenant node. The requests are on HTTP endpoint, every route on HTTP reference, and each language's way of sending them on Your language.
One writer process, and a thread a connection
One process writes one file. Two processes over the same file corrupt it,
which is why everything a server does — HTTP, replication, the graph keeper,
the sweeper of rows past their time (@ttl),
the --follow mirror — runs inside this one process rather than
as programs of its own.
One thread per connection. Read-only statements run at the same time under a shared lock — a call of a named statement whose body only reads among them; writes take the exclusive one. HNSW search buffers are thread-local, so the same index can be searched in parallel — eight concurrent full scans on eight cores measured 4.3×.
A /batch is one block: its writes land in the file as one
record, or none of them do, and a replica applies it whole. There are no
interactive transactions held open across requests — the database has one
writer, and a transaction a client held open would hold every other write
with it. An Idempotency-Key makes a write, or a
/batch, safe to retry (HTTP endpoint).
With --replica-of the process follows another
fennec-server as a read replica: it serves every read and refuses
every write with 403. The flags, promotion and what a failover loses are on Replication. With --dir <path>
instead of --file it serves a directory of tenant files, one per
tenant under /t/<tenant>/; that mode, its
--admin-token and --idle-close are on Sharding
reference, and the router in front of it on Tenants and sharding.
Flags
| Flag | What it does |
|---|---|
-f, --file <path> | The database file. In memory without it. The server holds <path>.lock while it runs, so a second process over the file — another server, fennec mcp --file, an app through the native library, the fennec shell — is refused rather than let corrupt it, and told which process holds it. To look inside the file while the server runs, fennec --read-only <path> reads it as it stands, writing nothing. A file reached through a symbolic link is the file the link leads to, for its lock and for the checkpoints and compacts that write it anew, the link left a link; but a hard link is a name of its own, and a record lock does not cross a file system that does not pass it on: a Docker Desktop bind mount, a network file system keeping no locks. Open a file from one side of those only. |
--dir <path> | One file per tenant in this directory (Sharding reference). Each open tenant holds <tenant>.fennec.lock, as --file holds its file's, so a shell or an app over a tenant's file is refused while the node has it open, and the node is refused it while they do. A deleted tenant's lock file stays, for the name made again. |
--http <address> | Where to listen. Default 127.0.0.1:8080. |
--http-token <value> | Requires Authorization: Bearer <value>. Also read from FENNEC_HTTP_TOKEN, since argv shows up in ps. Past loopback 32 bytes at least, as every token is (Security). |
--tls-cert <pem>, --tls-key <pem> | Serves HTTPS alone, with this certificate chain (the server's certificate first, then its intermediates) and its private key; both or neither. --metrics speaks it too. Read at the start: a renewed certificate takes a restart (HTTPS). |
--tls-ca <pem> | The CAs every https:// this server dials is held to, in place of Mozilla's roots, which it trusts without the flag: a replica's --replica-of primary, --otlp-endpoint, a tenant's primary. A PEM file of one or more CAs, for a private CA (Dialing HTTPS). |
--jwt-secret, --jwt-secret-file, --jwt-keys, --jwt-require-exp, --jwt-max-age, --jwt-tenant-claim, --jwt-unbound-tenants, --policy | Tokens held to rules: which collections, which rows (Security). |
--jwt-issuer <iss>, --jwt-audience <aud> | Takes only a token whose iss is one of the issuers given, and whose aud (a text or a list) holds one of the audiences given; each repeatable, the two lists independent rather than paired. A token refused is 401 naming the check. Without them any token the keys sign is taken, as before, and with --jwt-keys the server says so as it starts. Required for Firebase, whose keys sign every project's tokens; not enough where the caller names its own audience (Google identity tokens, GitHub Actions, Kubernetes), where the rules pin sub too (Whom a token is for). |
--jwt-client <id> | Takes only a token whose azp, or client_id where it names no azp, is one of the clients given; repeatable. For a Cognito pool, --jwt-client takes its access tokens and --jwt-audience its ID tokens. |
--jwt-role-claim <name> | The claim a rule's for <role> reads, a text or a list holding the role, such as cognito:groups. Default role. Every --jwt-* flag but the keys' is refused without --jwt-secret or --jwt-keys, and one given empty is refused. |
--sync off|always|<ms> | When writes reach the disk. Default 250 (Durability). |
--no-checkpoint | Writes no checkpoint on shutdown. |
--exit-on-stdin-close | Shuts down as SIGTERM does once stdin ends. For an app that starts the server with a pipe on its stdin: however the app ends, kill -9 too, the pipe closes and the server syncs, lets go of the file and exits 0. Stdin of /dev/null ends at once, and so does the server; a terminal is refused (Durability). |
--no-mmap | Reads the file into memory instead of mapping it: for a network file system, or to have --max-memory count the documents too. On Windows a file on FAT32, exFAT or a network share is read so without it, as the server says at its start. |
--warm all|off|<list> | Builds the hash, text, ordered and sparse indexes after the open, beside the first requests, rather than on the first read of each. Default all for a file, off for a node's tenants (Warm-up). |
--auto-compact <ratio>|off | Compacts a file on its own once this share of it is dead, beside the queries. Default 0.5 (Compaction). |
--max-connections, --idle-timeout, --header-timeout, --write-timeout, --max-memory | Limits. |
--http-cors, --http-read-only, --http-max-streams, --http-keepalive, --http-gzip, --http-gzip-local, --changes, --idempotency-ttl | The HTTP endpoint's options, each where it is described: --http-cors and --http-read-only under Security, --http-max-streams under Subscriptions, --http-gzip and --http-gzip-local under Compressed answers, --changes under Dropped connections and the horizon, --idempotency-ttl under Retrying a write; --http-keepalive is in fennec-server --help. |
--replication-token, --replica-of, --promote, --replication-buffer, --cdc | Replication and change data capture. |
--admin-token, --idle-close, --lease | A tenant node's (Sharding: reference). The admin token is also read from FENNEC_ADMIN_TOKEN. |
--follow <postgres://...>, --follow-* | Mirrors a PostgreSQL table into the file and serves it (Import). |
--metrics, --slow-ms, --audit, --auth-delay | Monitoring and the audit log. |
--otlp-endpoint, --otlp-header, --trace-sample | OpenTelemetry traces to a collector; off unless an endpoint is given (Tracing). |
--studio, --studio-connect | fennec studio, the admin pages, at /_studio/; off unless given (Studio). |
--mcp, --mcp-write, --mcp-memory, --mcp-max-rows, --mcp-max-bytes, --mcp-calls-per-sec | MCP for agents at POST /_mcp, each tool held to the request's token; off unless given (Agents and MCP). |
--hooks <path> | The hooks file: a line a hook another service sends its events to, its scheme and the files holding its secrets, read once at the start and refused there, naming the line, when anything in it is wrong. Its events are taken at POST /_hooks/<hook> by the statements defined on hook <hook>; a file's server alone (Webhooks from Stripe and GitHub). |
--call-max-rows <n> | The most rows one call of a named statement examines; past it the call is put back and refused (400), never answered from the rows it reached. Default 100000. |
--call-rate <n> | Calls a second from one scoped token's subject and issuer in each tenant, and runs of the statements bound to its writes (Waking a bound statement), 429 with Retry-After past it; 0 for no bound. The server's token is not held. Default 100 (Calling a named statement). |
--request-rate <n> | Requests a second from one scoped token's subject and issuer to each database or tenant, every route counted, 429 with Retry-After and retry_after_ms past it, before anything of the request runs; 0 for no bound. The server's token is not held. A call is a request too, held to both. Default 1000 (Requests a second). |
--user <uid>:<gid> | Started as root, runs as this user and group, in numbers: the directory the server writes in (--file's, or --dir) is handed to them first, where it is a volume of its own holding nothing but the database, then root is dropped for good, before any file is opened. Also read from FENNEC_USER, which the Docker image sets to 65534:65534; started as any other user, the server passes the variable over and refuses a --user it is not. Unix only (Who owns the volume). |
--insecure | Allows a non-loopback address without a token, and, with no data token, answering a router that listens on one (A node with no token behind a router). |
--ping | Asks the server whether it is up and exits, over TLS too where the server speaks it (health checks). |
-V, --version | Prints fennec-server <version> on stdout and exits 0, before the file is opened or a port bound. Releases up to 0.1.12 have no such flag: the first line of --help, on stderr, names theirs. |
fennec-server --help prints every flag with its default.
Its exit code says how it ended:
| Code | When |
|---|---|
0 | It stopped as asked: a signal, or the end of stdin under --exit-on-stdin-close, after the final sync. A signal that comes before the server has opened its file ends it by the system's default action instead, with no code of its own. --ping: a server answers. --version and --help: printed. |
1 | A server over a file or in memory could not start: its file could not be opened (another process holds it, or it cannot be read), --follow's guard could not be put on it, a replica's file was started without --replica-of or --promote, its history could not be settled (a promotion's fork, or its sync, failed), or its HTTP port could not be had. Or --follow's mirror stopped, before the server served or after, or once serving its listener failed, or its scheduler stopped (a failure outside any scheduled run, a file's or a node's) — after the final sync and with no checkpoint. --ping: none answers. |
2 | A flag or its value was refused, before anything was opened: an open address with no token among them, --tls-cert without --tls-key or the reverse, a certificate or key that cannot be read or parsed, a key that is not the certificate's. Also a server started as root that could not become its --user (a container without the SETUID and SETGID capabilities), a node's directory that could not be used, a node's HTTP port or --metrics' that could not be had, and a thread the start could not make (after the final sync, with no checkpoint). |
A start that fails rewrites nothing. The ports are taken straight after the
open, before anything writes the file or runs beside it, so a failed start
has written only <file>.lock and what an open writes — the
file, or a node's directory, made empty where there was none, a torn tail cut,
the side files a process writing it left as it ended removed and logged with
their sizes (which, and when
one is kept),
and on Linux the writes a crashed server had made durable written back from
its sync log — and, started as root, the owner of a volume it handed to
--user before it read the rest of its flags; a supervisor restarting
it again and again changes nothing more. A server that stops on a failure
writes no checkpoint either: the next open links what the graphs kept in the
file left. Between the ports being taken and the server answering — the open
of a node's tenants, a moment for a single file — a connection waits in the
system's queue rather than being refused.
Security
Give the server a token, or give each user a JSON Web Token that names what they may read and write.
fennec-server --file data.fennec --http 0.0.0.0:8080 --http-token "$TOKEN"A server with no token -- the Quickstart's, or a node given
--admin-token alone -- answers only under this machine's name:
localhost (or a name under it) and an IP address. A request naming
another host, a container's service name or a LAN name among them, is refused
(403): a web page whose DNS name was pointed at 127.0.0.1 would otherwise read
every row. It answers a page in a browser only from its own origin (the studio)
or the one --http-cors names; another site's page is refused before
anything it sent runs. curl, the SDKs and other servers send no
Origin and are unaffected. To reach the server by another name, give
it a token; /_health answers under any name.
Behind a reverse proxy, the same holds for the name the proxy was reached by:
- A proxy that keeps the
Host(Caddy's and Traefik's default) passes on the browser's name, and names it inX-Forwarded-Hosttoo, which the server asks as it asks its ownHost. An open server behind it answers 403 to every request: give it--http-tokenor JSON Web Tokens. - A proxy that rewrites the
Hostto the server's address (nginx's defaultproxy_pass) gets through. But a page served on the proxy's origin, the studio among them, is not on the server's own origin, so its POSTs are refused until--http-corsnames that origin (--http-cors https://db.example.com). Such a proxy hides the page's name from the server, so a page whose DNS name was rebound to the proxy reaches the server through it: a server reached past this machine needs a token, behind a proxy or not. - Behind a proxy or a router, a token is 32 bytes too. A server
on 127.0.0.1 takes a token of any length (token
length), but a proxy in front, or a router on the same machine
relaying to it, reaches it for anyone who reaches them: every guess
comes through, and behind a plain proxy every refusal waits by the
proxy's address, which any client's good token clears. Give it
openssl rand -hex 32. A server holding a shorter one logs a warning, once, at the first request carryingForwarded,X-Forwarded-FororX-Forwarded-Host.
Without a certificate the server speaks plain HTTP, and a token sent over a network travels in the clear. Give it a certificate and a key and it serves HTTPS itself (HTTPS).
Tokens, JWTs and the audit log
--http-token is the server's own token: whoever sends it reads
and writes everything. The comparison is constant time. Listening on a
non-loopback address with no token is refused outright; it can be opened
deliberately with --insecure.
Past loopback a token is 32 bytes at least. Where
--http or --metrics listens beyond loopback, an
--http-token, --admin-token or
--replication-token shorter than that, given as the flag or its
variable, stops the server at the start (exit 2), naming the flag. A refused
guess waits, but only by its address, and a client may hold many:
openssl rand -hex 32 makes a token long enough. Loopback is
judged of the addresses the listener is bound on, its name looked up once,
as the server starts and before it opens anything; a name that cannot be
looked up counts as past loopback. One the resolver cannot answer yet -- a
boot before DNS is up -- fails the start whatever the token, which a
systemd unit's Restart=on-failure tries again. On loopback any
length is taken, so make server TOKEN=secret and a machine's
own tests run as they are; --insecure does not waive the
length. Behind a proxy or a router, give the token 32 bytes all the same
(Behind a proxy): the server warns once a
request comes through one while it holds a shorter one.
A webhook's secret (Webhooks) shorter than
32 bytes is taken, and warned of: at the start where --http is
past loopback, through a proxy as a short token is, and on a node as a
tenant's secret is set. Stripe's and Svix's are long enough as they come;
a GitHub secret is yours to choose, so make it with openssl rand -hex
32.
With --jwt-secret (HS256, at least 32 bytes) or
--jwt-keys (a JWKS file: oct keys for HS256,
RSA keys for an identity provider's RS256 and EC
keys on P-256 for its ES256, a token's
kid picking the key, the file read again as it changes) the
server also takes JSON Web Tokens, each held to the rules of
--policy: which collections, to read, insert, update or delete,
which rows (where owner = $jwt.sub, where room in
$jwt.rooms, the rows another collection names: where courier in
(get orders select courier where customer = $jwt.sub)), which fields of
them a read shows (read(pickup, run_at) where run_at <= now(),
Fields a read shows), and what an
update may make of a row (where
status = "ready" and new.status = "cancelled"). A token that may only read is the reporting login a
dashboard needs, one that may only insert a client appending events, and an
append-only collection takes no update or delete from any token
but the server's. The rules are ANDed into every statement
a token runs, and every document it writes is checked against them as well
(Scoped access).
--mint-token '{"sub": "ada"}' prints a token signed with the
secret, for testing, which expires in an hour (or
--jwt-max-age's, where sooner) unless the claims name an
exp. A token with no exp is refused, since it
would be good for ever (--jwt-require-exp off takes it), and
--jwt-max-age <s> refuses one whose exp lies
further ahead than that. --jwt-issuer and
--jwt-audience take only the tokens issued for this server --
an identity provider's keys sign every token it issues, for every app, and
Firebase's for every project, so there they are required -- and
--jwt-role-claim names the claim for <role>
reads. Where whoever asks for a token names its audience (Google identity
tokens, GitHub Actions, Kubernetes), the two flags are not enough: the
rules pin sub, azp or repository
(Whom a token is
for). On a --dir node a token reaches only
the tenant its tenant claim names
(Tokens). Pass the secret with --jwt-secret-file or
FENNEC_JWT_SECRET — argv shows up in ps
output.
Every token and key is read from the environment too:
FENNEC_HTTP_TOKEN, FENNEC_ADMIN_TOKEN,
FENNEC_REPLICATION_TOKEN, FENNEC_JWT_SECRET and
FENNEC_JWT_KEYS. One set and empty -- an environment file's line
left blank -- is no token. One given empty as a flag --
--http-token "$TOKEN" with TOKEN unset -- is
refused at the start, as is a secret's file holding nothing: a request that
carries no Authorization reads as the empty token, so an empty
admin token let anyone into /_admin/.
A request refused for its token waits before it is answered — 100 ms,
twice as long for each refusal from the same address within a minute, 5 s at
most (--auth-delay; 0 turns it off). An IPv6 address counts as
its /64, the least a network is given, any of whose addresses a client
there may send from; the server keeps 10 000 counts, and past them lets the
one refused longest ago go. A token the server
verifies clears its address's count; an answer that looked at no token,
whatever Authorization it carried, clears nothing. --audit
<path> appends a JSON line for each refused request, each change
of the schema and each admin request (The
audit log).
On Linux and macOS every file the server and
fennec make is readable and writable by their user alone (mode
0600), whatever the umask, and a directory they make is
0700: the database and its sync log and lock, a node's tenants and
their records, archives, backups, restores and the audit log. Another user of
the machine reads none of the rows, secrets or refused requests they hold. A
file that is there keeps the mode it has, through every compaction, checkpoint
and restore --force over it. Each of those writes a new file and
renames it over the old one, and the new file is in the group new files in
that directory get: the server's group on Linux, the directory's on macOS. It
keeps the group's bits only where that group is the old file's, and otherwise
drops them, so no other group ever gains the read. To let a backup group read
the database, give the group the directory, searchable by it and setgid, so
every file made in it is the group's, and set the database's mode once:
chgrp backup /var/lib/fennec && chmod g+xs /var/lib/fennec
chgrp backup data.fennec && chmod 640 data.fennecA sync log made beside a database takes the database's mode, and its lock
the bits of those who may write the database: a group that may only read it
gets no lock to hold against the server's start. A file that another user
owns lends its mode to nothing the server writes over it. A
directory the server writes new files into -- an archive, a node's
--dir -- gives each new file to its owner alone: a reader there
runs as the server's user, or is given read of what is there before each
read, as the deploy kit's bucket sync is (chmod -R g+rX as root,
then a copy of what the group may read). Whoever may write the directory a
database is in may remove or replace the database, so it is trusted with its
files: a restore or an unseal there opens its scratch file again by its name,
which such a user could swap for a link. Keep that directory writable by the
server's user alone. Up to 0.2.0 files took the umask's mode, usually
0644, readable by every user; a file made then keeps it until you
change it (chmod 600 data.fennec). On Windows a file takes its
folder's access list, as it always did.
HTTPS
Give the server a certificate chain and its private key and it serves HTTPS itself. No proxy goes in front.
fennec-server --file data.fennec --http 0.0.0.0:8443 --http-token "$TOKEN" \
--tls-cert fullchain.pem --tls-key privkey.pem- The files.
--tls-certis the certificate chain in PEM, the server's certificate first, then any intermediates.--tls-keyis its private key, PKCS#8, PKCS#1 or SEC1. Give both or neither. - A bad file stops the start. A file that cannot be read or parsed, or a key that is not the certificate's, is refused with exit code 2, before anything is opened.
- Keep the key to its owner. On Linux and macOS a key file that
other users can read is warned of at the start, its path and mode named:
chmod 600it, or640where root owns it and the server reads it as its group. The server still starts, since Kubernetes secret volumes (0644) and Docker secrets (0444) mount keys that way by default. On Windows the warning reads the key's ACL instead: a key that Everyone, Authenticated Users or Users may read — what a file copied intoC:\ProgramDatainherits — is named with the group, andicacls key.pem /inheritance:r /grant:r <user>:R, the user the server runs as, leaves it to that user alone. - The listener speaks HTTPS alone. TLS 1.2 and 1.3 (rustls, with
ring), ALPN
http/1.1, no client certificates. A plain HTTP request to it is answered 400, naminghttps://, and the start line readslistening on: https://<address>. - A certificate the client trusts. One from a public CA, Let's
Encrypt for one, works with every SDK as it is. For a private CA, point the
client at the CA's file:
NODE_EXTRA_CA_CERTS=ca.pemfor Node,--cacert ca.pemfor curl,SSL_CERT_FILE=ca.pemfor the Python SDK, which asks through the standard library'surllib. - Metrics are encrypted too.
--metricsspeaks TLS with the same certificate: no port of a server told to speak HTTPS is plain, so a scrape's token never travels in the clear. A Prometheus job setsscheme: https, andtls_configwith the CA's file for a private CA (Monitoring). - Renewal takes a restart. The certificate and key are read at the
start. With certbot,
--deploy-hook "systemctl restart fennec-server"does it. Reading a renewed certificate without a restart is planned.
Handshakes, refused connections, health checks and a proxy in front
Each handshake runs on its connection's own thread and is bounded at 10 s,
so a client that stalls in it holds up no other. A handshake that fails is
counted by reason in fennec_tls_handshakes_failed_total
(Monitoring) and said in the log a minute apart
at most, so a scan or a client with the wrong CA cannot fill the log.
Every connection the server ends on purpose ends with TLS's
close_notify: an answer with Connection: close, a
kept-alive connection's end, a stream of changes or a replica's stream, and
each open connection at a shutdown, one still in its handshake too, which
the shutdown waits for as it waits for the others, half a second at most. A
connection that has sent nothing yet is not waited for, and one whose
handshake would begin after the shutdown began is closed before it. A
client reading a stream to its end can tell that end from one cut short. A
connection whose write failed gets none, and neither does a stream the
router relays from a node that broke off. A request the server had not yet
read when the shutdown came is still served on Linux if it had reached the
server by then (one still on the way gets no answer); on macOS it is
dropped, the connection ending with close_notify and no
answer, and on Windows the connection is reset. Dropped or reset, it never
ran. On Windows a shutdown also cuts an answer still being written to a
slow client, which a Unix server lets finish for half a second.
A connection refused at --max-connections, or for which no
thread can be made, is told a TLS internal_error alert, where plain
HTTP gets a 503 with Retry-After. Its request was never sent, so a
client may retry any request.
fennec-server --ping, the image's health check, works as it did.
The 400 a plain request gets tells it the port speaks HTTPS, and it asks again
over TLS. It does not check the certificate: it is a probe of the server on its
own machine, and it carries no token.
A TLS terminator in front is still fine where you want one, for HTTP/2 or for a certificate setup shared with other services; the server then speaks plain HTTP to it, on a private network.
Dialing HTTPS
What the server dials itself takes https:// too. The URL's
scheme says so; http:// works as it did.
- Where. A replica's
--replica-of https://host:port(and a tenant's follow, which the router sets),--otlp-endpoint https://...(alsoOTEL_EXPORTER_OTLP_TRACES_ENDPOINT; a port left out is 443),fennec backupandfennec archivefrom anhttps://primary or node, the router's links to its nodes and a region's routers (Sharding reference), andfennec mcp --url https://.../_mcp(MCP). - What is checked. The server's certificate: its chain and the URL's host name, which is also sent as the server name. Mozilla's roots are compiled in and are the default.
- A private CA.
--tls-ca <pem>names a PEM file of CAs and replaces Mozilla's roots, never adds to them. It is a flag offennec-server,fennec-shard,fennec backup,fennec archiveandfennec mcp. A file that cannot be read, or holds no certificate, is refused at the start, naming it. - A refusal sends nothing. A certificate from an unknown issuer, or
one that does not hold the URL's host name, is refused in the handshake,
before any byte of the request is sent, the token included. Under
Mozilla's roots the message says that
--tls-canames a private CA. The handshake is bounded inside the dial, so a replica's 5 s connect bound covers it. - No client certificates. These dials present none; the token is what identifies them.
Upgrade before you record an https:// address. A node
from before this release refuses to follow an https:// primary,
and a router from before cannot dial an https:// node
(Sharding reference).
Upgrade every router and node first.
Durability
Choose how often writes reach the disk with --sync.
--sync | What it means |
|---|---|
250 (default) | Flushed every 250 ms. A crash loses at most the writes answered in the last 250 ms plus the sync's own time. Measured over ten power cuts of a Linux guest (ext4), in two runs: each cut lost 54 to 794 acknowledged writes, none answered more than 316 ms before it, and what was kept was always a prefix of the writes. A --dir node syncs each tenant on a thread of its own, so a tenant's window is a file's whatever its other tenants' syncs take: with four tenants, five cuts lost 7 to 141 writes a tenant, none answered more than 162 ms before its cut. |
always | Each write is answered once it is on disk; a write refused by what another left (a 409 for an id taken, a 412 for a require) once that is on disk. Held over power cuts of Linux guests on ext4, in each of its data modes (ordered, writeback, journal), and on XFS: every acknowledged write was there after every cut, the disk's lost cache included. |
off | Flushed only on shutdown. |
What each --sync policy costs, and how the server shuts down
Writes accumulate in a 1 MB buffer. Under always every write
waits for an fsync, about 3.7 ms on macOS for a write alone, and
writes arriving together share one; 250 costs next to nothing;
off nothing. A /batch lands with one
fsync however many writes it holds.
Under always the fsync runs after the write has
let go of the exclusive lock, and the bytes reach the file there too. Readers
therefore do not wait on the disk, and writes that arrive while one
fsync runs are made durable together by the next. One client
still gets one write per fsync. The sync of 250
takes the same path, for a single database and for each tenant of a
--dir node: held through the fsync, a tenant's lock
had its reads and writes wait up to 27 ms once an interval.
A write another write landed is read from the moment it lands, before its
fsync has run. Under always a write refused by it —
an insert of the id it took (409), a @unique value, a
collection or statement it made, a require its del
left unmet (412), a /_changes consumer it made — is answered once
that write is on disk too, as its success would be: answered at once, a power
loss could take back the row the client was told was there. So is a
/_schema/apply that finds nothing to apply, a quota's 507 as a
block lands, and a /batch stopped after some of its statements were
made, which answers once those are on disk. An fsync that covered
it already costs the refusal nothing; one that failed is its answer (500). A
refusal of the request alone — a body that is not JSON, a path no route
takes — waits for nothing.
SIGINT, SIGTERM and SIGHUP are caught
and a final sync runs before exit. The exclusive lock is held until
exit, so no write can be accepted between the sync and the exit and no write is
left that looked successful to the client but never reached the disk. On
Linux the file is then synced and its sync log (<file>.sync,
File format) removed, each open tenant's on
a node too, so a stopped server leaves its file and
<file>.lock and no log. Under kill -9 you get
exactly what the chosen policy promised, and no more; the log stays beside
the file, and the next open puts back what it holds.
Windows sends no signals. There Ctrl+C and Ctrl+Break, closing the
server's console window, logging off from the session it runs in and the
system shutting down start the same shutdown. Ctrl+C stops it even when it
was started in a process group of its own or with start /b,
which turn Ctrl+C off for the programs they start. On a close, a logoff or
a shutdown Windows ends the process five seconds after, so the server
syncs first: every write it acknowledged before the event is on disk
within a fraction of a second. Only then does it answer held requests,
end its TLS connections and flush its traces, sync what came meanwhile and
write the checkpoint, if the five seconds last that long; a checkpoint cut
short leaves the file whole, and the next start links the vectors it would
have held. A program that stops a server it started sends Ctrl+Break, or
Ctrl+C, to the server's process group, what SIGTERM is
elsewhere: start it with CREATE_NEW_PROCESS_GROUP, then call
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid) from the same
console. Run as a Windows service, the server goes under a wrapper that
stops it with Ctrl+C or Ctrl+Break and waits for it before it kills, as
WinSW and NSSM do; give it the time a final sync takes. A user logging off
from another session does not stop a server in the services' session,
which Windows keeps a service's own process running through; whether it
does the same for a wrapper's child is not verified yet. Killed
(taskkill /f, End process in Task Manager's details),
it gets what kill -9 gets.
With --exit-on-stdin-close the end of stdin starts the same
shutdown. A process that is killed sends its children no signal, but the
system closes every descriptor it held, so a server started with a pipe on its
stdin sees the pipe end however its parent ended, and stops rather than run on
holding <file>.lock with nobody to answer. What the parent
writes into the pipe is read and dropped. A terminal is refused: a server
reading one from the background would be stopped whole by the system, its file
held; there Ctrl-C does the same. So is a secret, policy or keys file that is
stdin, which would be read to its end.
import { spawn } from 'node:child_process';
// stdin is a pipe this process holds for as long as the server runs.
const server = spawn('fennec-server', ['--file', path, '--http', '127.0.0.1:0', '--exit-on-stdin-close'], {
stdio: ['pipe', 'ignore', 'pipe'],
env: { ...process.env, FENNEC_HTTP_TOKEN: token },
});
// Read stderr for as long as the server runs: a pipe nobody reads fills,
// and the server's next log line waits for room. `onListening` is yours,
// called once with the address the server took.
let head = '';
let url = null;
server.stderr.setEncoding('utf8').on('data', (text) => {
if (url) return;
head += text;
const at = /listening on: (http:\/\/\S+)\s/.exec(head);
if (at) onListening((url = at[1]));
});The pipe's write end must stay in this process alone. A child it starts later that inherits it — a descriptor not marked close-on-exec — holds the server's stdin open after this process has gone, and the server runs on.
When the disk refuses a write or a sync, the request fails with 500 —
under always, before the client is told it succeeded — and every
later write is refused until the process restarts; reads go on answering. The
sync is not retried: after a failed fsync the kernel may already
have dropped the pages, so a retry that succeeds would prove nothing.
The shutdown checkpoint. After the sync, if a vector index exists,
a checkpoint is written: the HNSW graph lands in the file and the next open
does not rebuild it — 9 ms instead of 3.4 s at 100 000 × 128. Vectors still
waiting to be linked after a crash are written as waiting, and linked after
the next open. The cost is that shutdown takes longer on a large database:
the image is written into the new file as it is produced, so it is a copy on
disk rather than one in memory. --no-checkpoint turns it off.
The order is deliberate. The sync comes first, so even if the process is
killed while the checkpoint is being written, the data is already on disk and
only the graph is lost. The rewrite goes to a side file and is renamed, so a
half-written checkpoint cannot corrupt anything.
Warm-up
An open builds no hash, text, ordered or sparse index: the first query
that reads one builds it, and pays for it. fennec-server builds
them after the open instead, beside the first requests, one at a time: the
port opens as soon as before, and the first search finds its index built.
--warm products,orders.status names the collections and fields
to warm, --warm off none.
How warm-up builds indexes beside reads, measured
Each index is built under the read lock on its own, so reads go on beside
it, a read that needs the index being built waits for that build rather than
starting its own, and a write waits out one index at most (a
@text index of 100 000 products: 141 ms). The thread starts once
the HTTP endpoint is up, whose start takes the write lock. Over 100 000
products with a text, two hash and an ordered index, on an M1: the first
answer 16 ms after the start either way, the indexes built 208 ms after it,
and the first match 1.4 ms warm against 166 ms cold; the process
held 99 MB against 88 for a cold one that had only searched, and 25 before
any read.
It is on for a file because an index is declared to be read, and a
first query that builds one is the slowest a server answers: a shop's
first search page took 2.68 s to its largest paint against 1.40 s warm. The
memory is what the reads would have taken anyway; only an index nothing
ever reads is held for nothing, and --warm names the rest. A
node's tenants open on their first request and close when idle, and
warming each would build every index of every tenant a request touches, so
there it is off unless asked. The native library has the same call,
fennec_warm, and the Rust API Database::warm and
warm_index.
Compaction
A file only grows until it is compacted. An update writes the whole record
again at the end of the file, and a delete writes a tombstone; the version
left behind is dead until a compact writes the live records into
a new file, and that is what stops the file from growing. The server runs
one on its own: every 5 s it looks at each file it serves, the
database, each open tenant and a replica alike, and compacts one once half
of it is dead and the dead part is at least 64 MB -- or sooner, once a
third of what the compact writes is dead, where the file has reached three
quarters of the memory the system has for its pages or the server is
waiting for the disk, so that its reads stay in memory. The compact runs
beside the queries: it reads the documents, rebuilds a vector index that
holds deleted entries and writes the new file with no lock held, and takes
the write lock only for the writes of its last moments and to put the new
file in place. A vector index whose writes outrun its rebuild -- more
written during its last round of catching up than about 0.1 s of linking
at any m and ef_construction, 128 vectors at
768 dimensions, 33 at 3 072 at the defaults, fewer as a wider
m or ef_construction makes each link cost more
-- is kept as it stands until
the next compact, rather than every write held while the compact links
them, and the log line says so. A sustained ingest of vectors can keep it
at every compact, its deleted entries growing until a quieter one.
The file a compact replaced is given back to the disk a step at a time
on Linux's ext4, XFS, Btrfs and F2FS: emptied 32 MB every 50 ms by a
thread of its own once no read still uses it -- a long read, a stream's
first answer or a backup going out keeps it whole until it ends -- and
nothing else has it open, a gigabyte in about two seconds. Freed at once,
on a file system mounted with discard its blocks' discards
held the server's reads and fsyncs behind them for about a quarter of a
second a gigabyte (trim on a timer rather
than mount with discard). A deleted tenant's file goes the
same way, and so does one a fennec restore --force replaces.
Such files go at once where the volume has less room left than they hold
together, and on other file systems -- a container's own overlay layer,
NFS, a FUSE mount -- whose leases cannot tell whether another program
still reads the file; on macOS and Windows, whose file systems discard
nothing as a file goes, too.
A vector index is rebuilt on its own too, without a compact. Every
document whose vector is written over or deleted leaves a deleted entry in
the index, its vector and its links kept in memory and in the index's
record in the file; once they outnumber the index's live entries, and
number 10 000 at least, the server builds the index again beside the
queries in the same way -- its writes caught up with in rounds, the write
lock taken for the last of them -- looking every 5 s at each file it
serves, a replica's too, right after it looks for a compact, and writes
the rebuilt index into the file. A rebuild takes as long as building the
index: half a second at 20 000 × 16, about 50 s at 100 000 × 768, one
file after another as the compacts are. While it runs the server's
memory holds the index as it was, the vectors of its live documents
copied out of the file and the index being built, all at once: up to
about two and a third times the index at its peak -- an index of 142 MB
at 20 000 × 768 took 189 MB more while it was rebuilt -- which a
container's memory limit has to hold. An index whose writes outrun its
rebuild, or holding a document it cannot read, is kept as it stands, and
tried again once as many documents have been written as it holds deleted
entries; another index is rebuilt meanwhile as it wears. A tenant
deleted, moved or made to follow, or the server stopping, stops a rebuild
under way rather than wait for it, and the server's own compact while it
rebuilds the indexes, before it writes the file: it then writes nothing,
and one already writing the file finishes first. A compact
rebuilds such an index too, whichever collection it names. The line names the file or the
tenant:
/data/db.fennec: 1 graph rebuilt, 20903 tombstones dropped in 421.0ms, the lock held 1.7ms at most (the build's copy 7.2µs, rounds 12.4µs, put in place 1.7ms)Each compact and create index run beside the queries is
logged in one line: what was done, how long it took, the longest it held
the lock -- what every write waited out at most, and every read behind a
waiting write -- and each hold by name: the build's copy, its rounds of
catching up and putting it in place, then a compact's file's copy, rounds
and swap. A compact the server runs on its own names the file or the
tenant:
/data/db.fennec: compacted, 2088.0 MB -> 1067.4 MB in 16.4s, the lock held 182.1ms at most (the build's copy 12.9ms, rounds 670.0µs, put in place 6.1ms; the file's copy 182.1ms, rounds 84.4ms, swap 6.7ms)A compact sent as a statement writes the same line naming
itself, and a create index what it built, each ending with the
request's id:
compact: compacted, 2088.0 MB -> 1067.4 MB in 16.4s, the lock held 182.1ms at most (...) request_id=6f1c0a2e9b7d4c13
create index: index built on `docs.v` in 3.2s, the lock held 9.8ms at most (the build's copy 1.1ms, rounds 2.0ms, put in place 9.8ms) request_id=0d93b5e1a4c26f87A compact that kept a vector index as it stood names it after the
holds, with how many vectors were written during its last round -- or
that a document of it could not be read, or that the vectors written
while it was rebuilt would take it past the
4 294 967 295 nodes an index holds
(its writes would pass 4294967295 nodes):
/data/db.fennec: compacted, 2088.0 MB -> 1067.4 MB in 18.9s, the lock held 191.4ms at most (...); graph `docs.v` kept, 412 behindThe compact's last moments copy under the write lock the writes made
during its last round of catching up and during the handover of what the
rounds copied, which follows it. Beside a steady stream of 1 000-row
POSTs that is milliseconds: 6.6 to 29 ms at 10 000 to 30 000
rows a second. As fast as three CPUs could write them, the handover took
9 to 11 s, the copy held every write and read 3.8 to 6.4 s, and the copies
waiting for the handover took 1.5 to 1.7 GB of memory -- in 512 MB the process
was killed. Nothing bounds that yet; give a compact's server the memory
for what is written during it.
A compact is refused for nothing a document holds: one it cannot
read is copied as it is, and a dropped field's values become
nulls, its place kept. A refusal that stands -- a damaged
file, a disk that will not take the new one -- is tried again at every
look, logged once and counted in
fennec_auto_compactions_refused_total.
| Flag | Default | What it does |
|---|---|---|
--auto-compact <ratio> | 0.5 | The share of the file that may be dead before a compact runs. |
--auto-compact off | Compacts only on compact. |
Why a file compacts itself, and what it costs
Left alone, a file of updated rows grows by a record a write, and its live records end up a few to a page among dead ones: under YCSB's updates, a million records of 1 KB took the file to 4.7 to 6.5 GB on an 8 GB machine, and one read in five then waited for the disk. With the default ratio the file stays under about twice what the last compact left it at, and each compact writes the live records once for as many bytes of updates.
What it costs, measured with make compact-bench: a million
1 KB records, five million updates of a field at keys drawn at random from
one thread, buffered, while another reads whole records. With
auto-compaction the file went from 1.03 GB to between 2.1 and 3.0 GB and
back to 1.1 to 1.6 GB three or four times; each compact took 8 s at the
median with no lock held and held the write lock 6.1 to 12.6 ms to put its
file in place. The reads while a compact ran had a p99 of 1.3 to 5.3 ms.
The updates ran at about 30 000 a second through a compact, against 110 000
to 170 000 while the file was smaller: on this 8 GB machine, beside its
other programs, the page cache holds about 2 GB of the file, the size at
which a compact comes due, and past it an update reads its row from the disk
whether a compact runs or not -- 28 000 to 46 000 a second with
auto-compaction off. At 250 000 records, whose file fits, the updates ran at
153 000 a second through a compact of 0.3 s, and at no less than 83 000 in
its worst tenth of a second, against 180 000 with none. Once the updates
were done the reads ran at 435 000 a second, p99 2.2 µs, from the first
second. Without it the file ended at 6.2 GB, and the reads after the updates
started at 19 000 a second and took 25 s to reach 400 000, their p99 0.11 ms
over those 30 s. Durable, an fsync a write from 16 writers, 100 000 records
updated 400 000 times at about 900 a second: the file went from 103 to
211 MB and back three times, each compact held the write lock 13.7 to
14.8 ms -- two F_FULLFSYNCs of this Mac's among it -- and ended
at 190 MB against 515 without it; that file fits the page cache either way,
and the reads ran alike, p99 2.2 µs.
Before the file outgrows the page cache. fennecdb keeps no cache of
its own: a document is read where it lies in the mapped file, so what the
reads need in memory is every page of the file that holds a live record --
and under updates at keys drawn at random that is every page until a
compact (a million 1 KB records updated until the file stood at 2.1 GB
left one on every 16 KB page and on 94% of 4 KB ones). Once the file
outgrows what the system has for it, every read and update waits for the
disk in turn. So a file is also compacted once a third of what the
compact writes is dead, where its live records fit in that memory and the
file has reached three quarters of it -- which Linux reports exactly, its
available memory and a container's limit -- or the server takes 500 major
faults a second, which is how macOS shows it: under pressure it compresses
the other programs' memory and reports more room than it gives the file.
That costs up to four bytes written for each byte updated, against two at
half the file dead. A compact whose new file would not fit beside the old
one writes it past the page cache and reads it in after the swap, so the
old file, which the reads need until then, stays in memory. Measured with
make compact-bench in a container held to 2 GB
(docker run --memory 2g): at half the file dead the file stood
over 2 GB for 69 to 74% of the run, the five million updates took 358 to 511
s, 3 500 to 4 100 a second at the median, and the process took 811 000 to
900 000 major faults; with the memory rule, 80 to 100 s and 34 000 to
39 000, the file at most 1.9 GB, the reads during a compact p99 0.44 to
0.49 ms against 4.6 to 6.5, for 3.0 to 3.2 bytes written a byte updated
against 1.9 to 2.0. On this Mac beside 1 GB of memory held by another
program, 191 to 260 s against 82 to 535: macOS gives a growing file more
of the machine as it compresses the other programs' memory, which it did
in the fastest run at half the file dead and not in the slowest, and a
file kept smaller is not given it -- steadier, never the best case. A file
that fits in memory is compacted as before.
A file past the page cache, read in turn. After updates at keys
drawn at random the records stand in the file in the order of their last
writes, so a compact copying them in id order read a file larger than the
memory the system has for it a page at a time, at random, from the disk: in
a container of 512 MB (docker run --memory 512m), a million 1 KB
records each updated once, 2.04 GB with 1.02 live, took 45 to 51 s and about
530 000 major faults, as in every release from 0.1.5 to 0.2.0. Past that
memory a compact now reads the file once, from its start to its end, deals
the records a run of ids at a time into a scratch file beside it,
<file>.sorting, and writes each run back in id order: 4.6
to 6.6 s and about 2 000 major faults, the new file the same byte for byte.
It holds 16 MB of memory at most and as much disk as the live records; it
copies by id instead where the disk has no room for twice those, for a
collection under 4 MB live or over 4 GB, where something already stands at
the scratch file's name, or once the scratch file fails, which the server
logs. The scratch file leaves its directory as soon as it is made, so a crash
leaves nothing beside the database, or an empty one the next open removes.
What a compact writes waits for the disk a little at a time. A page
a program writes stays in memory until it is on disk, and a container cannot
give it back before, so a compact writing past the page cache sends its
scratch file and its new file to the disk a sixteenth of the memory the
system has for the file at a time, between 4 and 64 MB, and one file's at a
time: at most an eighth of that memory waits for the disk, and from 1 GB of
it up, where each 64 MB is synced as soon as it is written, a sixteenth. It sent
each 64 MB at a time before, whatever the memory, and in
a container of 512 MB holding 417 MB of its own a compact left 84 MB of
written pages there at once, and the container was killed. Compacting a 2
GB file of 1 GB live in a container of 512 MB, with 300 MB of it the
server's own, the written pages waiting for the disk now peak at 15 to 23
MB against 33 to 41 before, and with the server's 11 MB alone at 34 to 37
against 80; in a container of 1.5 GB, at 64 against 88 to 90. Each step is the compact's own fdatasync, so the
server's own syncs are not left to flush the compact's writes: beside it,
writes synced every 250 ms took 1.5 to 3.3 ms at the median, against 1.1 to
17.8 before. Where memory is that tight, the compact itself takes longer
for it: in the container of 512 MB with 300 MB of it the server's own,
5.57 s at the median against 5.27 before, 5.7% longer, on the disk it was
measured on; from 1 GB of it up it takes as long as before.
The compact copies what it reads under the read lock, writes the live
records into a side file with no lock held, and copies the writes made
meanwhile in rounds -- a few thousand documents looked up under the read
lock at a time and copied once it is let go -- until a round finds fewer
than a thousand; it reads every page of the new file in before the swap,
asking for them ahead in large reads, so no reader waits for one after it --
unless the two files would not fit in memory together, when it writes the
new one past the page cache and reads it in once the old one is gone.
The write lock is then held for the last of those writes, the side file's
fsync and the rename. The server looks for a compact due every 5 s, and a
look waits for a write under way rather than pass a compact over. A replica
compacts its own file the same way: a compact changes no document, and an
image its primary sends meanwhile fails the compact rather than be written
over. /_metrics has the file's size,
what a compact would give back of it and the compacts run
(Monitoring), and each is logged with the
file before and after and how long it held the lock.
Limits and health checks
| Flag | Default | What it does |
|---|---|---|
--max-connections | 100 | Refuses connections past it. Once a subscription streams it is counted under --http-max-streams instead, except on a tenant node or at --http-max-streams 0. |
--max-memory <MiB> | off | Refuses writes that would grow the data past it; reads go on. |
--idle-timeout <s> | 60 | Closes a quiet keep-alive connection (0 = never). |
--header-timeout <s> | 10 | A request must come within it of its first byte, and a second more for each KiB that came, head and body alike: a client sending 1 KiB a second or more is never cut. Else 408, and the connection is closed (0 = only --idle-timeout, a read at a time). |
--write-timeout <s> | 30 | The longest a write of an answer waits for its client to take any of it: a client that reads nothing is let go within twice this (0 = never). |
--http-max-streams | 64 | Ceiling on a database's subscriptions, counted apart from --max-connections; on a tenant node, each tenant's, and each one of the node's connections too. |
fennec-server --ping --http 127.0.0.1:8080 # exits 0 when the server is upConnection ceilings and health checks
One thread per connection means unlimited connections would leave the stack
memory ceiling to the client. Past --max-connections a client
gets 503 with Retry-After, its request read off and the
connection ended after the answer, so a client writing its request as the
answer comes reads the 503, not a reset (over TLS it is told
an alert instead); --idle-timeout closes
a quiet connection. A client that sends slowly, or reads nothing, holds its
connection no longer than its request's time: within
--header-timeout of its first byte and a second more for each KiB
that came, head and body alike, so a client keeping 1 KiB a second -- a
mobile link at 32 kbit/s sends four -- is never cut, and a trickle is (a
head, 64 KiB at most, is whole within 74 s; a 64 MiB body within about
18 hours, a gibibyte image within 12 days); and each write of an answer
taken in part within --write-timeout, a client reading nothing let
go within twice it -- over HTTPS too, a request's time running from its
first record's first byte and a record that comes in parts held to the
same bound. Each such cut is counted
(fennec_client_timeouts_total). A
subscription holds a thread for as long as it lasts, so subscriptions are
counted apart, under --http-max-streams, a database's own: once
a subscription streams it gives its place under --max-connections
back, and a server holds that many connections and that many streams at
most -- 64 subscribers leave all 100 connections to ordinary requests. At
--http-max-streams 0 (no ceiling) a subscription keeps its place
under --max-connections, the one ceiling left on its thread. A
refused subscription (503 too many subscriptions) held only its
connection. On a tenant node --http-max-streams is each tenant's,
so a stream keeps its place too: --max-connections is what all of
them share, the one bound on every tenant's threads, and each tenant's
streams and held writes take a quarter of it at most unless its quota says
otherwise (quotas). A
replica's or an archiver's stream, a /_changes wait and a held
write (Fennec-Wait) are connections everywhere.
--max-memory puts a ceiling on the data footprint. Above it,
requests that grow the data are refused with 507, while reads,
del and compact keep working: hitting a ceiling with
no way out would be no better than a cgroup OOM. The point is to bring the
OOM forward: nobody warns you about a process felled by SIGKILL,
and both the last sync and the checkpoint are lost with it. The measurement
happens before the statement, so the overshoot is at most one
statement.
--ping asks GET /_health on the
--http address and exits 0 when it answers. The route needs no
token and takes no lock: every query takes the database lock first, so during
a long compact a probe that ran one would wait too and a healthy
server would look dead. Because the listener binds after the file is
opened, "healthy" also means "the documents are read".
What the server is doing is at /_metrics, in Prometheus's
text format: --metrics <address> opens a listener for it
alone, over TLS where the server speaks it, and --slow-ms <ms> logs every statement at least
that slow with its text, a JSON line on stderr. The metrics, a Grafana
dashboard, the log and the Datadog Agent's configuration are in
Monitoring and Datadog and
other monitoring systems.
Run it in a container
The image is 8 MB: the binary and nothing else.
export FENNEC_HTTP_TOKEN=$(openssl rand -hex 32)
docker run -d --name fennecdb -v fennecdata:/data \
-p 127.0.0.1:8080:8080 -e FENNEC_HTTP_TOKEN \
ghcr.io/fennec-db/fennec-serverThe image's command is --http 0.0.0.0:8080 --file
/data/data.fennec --sync 250.
A name without a tag pulls latest, the newest published
release: it moves once a release is published, never to a release candidate
or back to an older version. Name :0.2.0 where a deploy
must not change under you.
- Set a token of 32 bytes or more. Without one, or with a shorter
one, it refuses to listen beyond localhost, which a container's
0.0.0.0is. - Run one instance per file. Two writers corrupt it: on Kubernetes,
a
StatefulSetwith one replica. - It serves as 65534, on any volume. The image starts as root, and
the server hands a volume a platform made root's to
65534:65534before it becomes that user: Who owns the volume. - Write every flag out when you override the command, or the data file is dropped.
How the image is built, and what sets its memory and restart cost
The Dockerfile is two-stage: a static musl build copied into
scratch. TLS's crates and roots are compiled in, and the binary runs its own
health check (--ping), so the runtime image holds nothing but the
binary — no shell, no package manager, no libc. The image is 8.62 MB on
amd64, that binary's bytes as CI measures them on every change, and smaller on
arm64 — since no target is written in, both come out of the same file.
make docker builds it, and
docker compose up -d starts the compose file's.
The memory limit comes from the data. With no buffer pool of its own
there is no knob to tune: the file is mapped, the system's page cache keeps its
pages, and what the process holds is the indexes, which is what
--max-memory counts. Below that the
cgroup sends SIGKILL, the clean shutdown never runs and up to
one sync interval is lost. Set --max-memory to a third of the
container limit to bring that forward. What a compact of a file past the
page cache writes waits for the disk an eighth of the memory left to the
file at most, a sixteenth from 1 GB of it up, since the container cannot
give such a page back before it is written (Compaction).
The restart cost depends on how it stopped.
docker stop sends SIGTERM and a checkpoint is
written, so the next open takes 9 ms. After kill -9 or a
cgroup OOM the graph of the last checkpoint is restored, and the vectors
written since it go in unlinked: the server answers once the documents
are read, and links them on a thread beside its queries,
near measuring each of them until then. The only checkpoint
the server writes on its own is the one at shutdown, but it appends its
graphs to the file as they change — a graph that changed in 10 000 nodes,
once the file has grown by three times its record, logged as
1 graph written into the file, with writes held off for
the 5 ms that takes at 100 000 × 768 — so what waits is what came
after the last of them: at 100 000 × 768 at most 10 000 vectors, linked
in 2.6 s with near at 1.56 ms p50 meanwhile. With no graph
in the file every vector waits: at 100 000 × 768 never checkpointed the
first near was answered 1.23 s after the start, against
67.7 s when the open linked them first, and linking takes 19 s.
fennec_vectors_unlinked counts down to 0.
Overriding CMD drops --file, and the container
comes up with an in-memory database. There is no shell in the image, so
docker exec ... sh does not work; what is left is
docker logs and docker run --rm
ghcr.io/fennec-db/fennec-server --help.
Fly.io, Render, Railway, a VM on any cloud and Kubernetes each have a config file of their own on Cloud platforms, with a StatefulSet that holds the rules above.
On machines of your own, the repository's deploy/ has a
systemd unit for a server of every role — a tenant node, a region's router,
the global router, an archiver — with its tokens in an environment file,
the alert rules and the operator's runbook (Deploying it).
Two containers loading the same file and writing it corrupt it. On
Kubernetes that means a StatefulSet rather than a
Deployment, replicas: 1, strategy:
Recreate and a ReadWriteOnce volume — a rolling update
keeps two pods up together for a moment. There is a connection ceiling but no
queue: an excess connection does not wait, it gets 503.
More
- Mirror a PostgreSQL table.
fennec-server --follow postgres://...keeps a copy as the table commits, and serves it. See Import. - Embed it instead. The same engine runs inside a Rust program with no server at all (Embedded Rust), and in a browser tab (JavaScript).