Skip to content

About

Multithreaded, self-clustering in-memory cache for Linux - its own Noise-encrypted binary protocol plus a Redis (RESP2) door, WAL + snapshot persistence, read-through from Redis, alerts by mail, and libperfd, the MIT C client library (shared or static)

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

perfcached - found fast, kept safe

A multithreaded cache for Linux, with its own authenticated protocol and a Redis-compatible door. One node to start; a cluster when you need it.

perfcached is an in-memory key-value cache for small, hot state - sessions, routing, counters, call state. One daemon serves requests on every core, keeps data in memory with an optional write-ahead log and snapshots, and is watched through its dashboard and Prometheus metrics. When one machine is not enough, run the same binary on several: they find each other, elect a master and share the keyspace.

libperfd - the compass

Clients speak perfcached's own protocol - binary frames opened with a Noise handshake that proves the client secret - through libperfd, the C client library (MIT), or perfcli, the command-line client. Redis clients such as redis-cli and hiredis work unmodified through the Redis door (RESP2).

$ perfcli -a client-secret-example set sessions user:17 'hello world' 300
{"stored":true}
$ perfcli -a client-secret-example get sessions user:17
{"found":true,"value":"hello world","ttl":300}
$ redis-cli -p 6380 -a resp-password-example --no-auth-warning GET user:42
alice

Current release: 0.7.5.1 (2026-11-26), with libperfd 0.7.6.1 and php-perfcached 0.2.0. GUIDE.md shows how to install it, build a cluster, take over from Redis, upgrade, back up and watch it, with real output.

Why perfcached

  • More work from every core. Every core serves requests: a pool of worker threads, not one event loop. Given the same 20 hardware threads, one perfcached process answered 1.9x the SETs and 1.8x the GETs of a 20-instance Valkey Cluster, and 3.6x Dragonfly's (How it compares).
  • A cluster that builds itself. Run the same binary on several machines: they find each other, elect a master and rejoin after a crash. No slots or node ids to assign, no operator tooling. Five placement modes, from every key on every node to one owner per key.
  • Move off Redis without a migration day. Put perfcached in front of the Redis you run now: a missing key is read from Redis on first use, or every write goes through to it, until perfcached holds the keyspace.
  • Redis clients work unchanged. redis-cli, hiredis and most Redis client libraries talk to its Redis door. Its own protocol authenticates every client at connect (a Noise handshake) and routes each key to the node that owns it.
  • Durable when you want it. An optional write-ahead log and snapshots, with a storage probe that recommends an fsync policy for your disks.
  • Easy to run. A dashboard, Prometheus metrics with a Grafana dashboard, alerts by mail, and collections created, resized and dropped while it serves.
  • A client library for any licence. The daemon is GPL; libperfd, the C client, is MIT.

When not to use it: if you need lists, sets, sorted sets, streams, transactions or Lua scripts (beyond the Symfony lock scripts), values over 256 KB, or a platform other than Linux. See Known limits.

How it compares

Each server got the same hardware: one NUMA node (10 cores, 20 hardware threads) of a bare-metal 2x Xeon E5-2690 v2 server on 10 Gbit/s, and 20 threads to fill it. Every server installed from its package, persistence off, measured one at a time through the Redis protocol with redis-benchmark 8.0.2 from three client hosts (pipeline 32, 1,000,000 keys). The rate is the server's own count over 15 seconds.

20 threads each SET/s, 32 B GET/s, 32 B p99 SET / GET SET/s, 200 B GET/s, 200 B
perfcached 0.7.5, one process, 20 workers 11.05M 13.86M 1.8 / 1.3 ms 5.00M 5.92M
Valkey 8.1.1 Cluster, 20 instances 5.78M 7.56M 2.3 / 1.8 ms 4.94M 5.91M
Dragonfly 2.1, 20 threads 3.10M 3.79M 6.0 / 5.1 ms 2.93M 3.19M

At 32 bytes every server had all 20 threads busy, so the CPU decided. At 200 bytes the 10 Gbit/s link capped perfcached and Valkey at the same rate; Dragonfly ran out of CPU first.

A three-node perfcached fleet in shard mode, through its own protocol and a client that sends each key to its owner, answered 23.9M SET/s and 31.4M GET/s at 32 bytes; the network link and the clients set that ceiling, not the servers.

Valkey is Debian 13's package (8.1.1); Valkey 9 was not measured. Valkey's I/O threads made one process slower on this machine (0.46M SET/s with 12 I/O threads, 0.57M with none), so it runs here in its best layout, one instance per hardware thread. The method, every run and how to repeat it: doc/benchmarks.md.

What it does

  • Its own protocol, authenticated at connect. Typed verbs, binary-safe values and pipelining; requests in the clear after the handshake by default (half the CPU), or encrypted with [listen] encrypt = yes.
  • Uses every core. A pool of worker threads, not one event loop: on one 16-vCPU host over a real network, four workers answer 2.2x Redis 8's SET rate and 1.4x its GET rate at pipeline depth 64 (Performance).
  • Durable when you want it. A write-ahead log plus snapshots, with a storage probe that recommends an fsync policy. A node that loses log records heals itself from memory instead of going down.
  • Redis clients work too. Strings with TTLs, counters, SET ... NX locks, RedisJSON documents, hashes, pub/sub, keyspace notifications, SCAN, INFO, SLOWLOG, behind an address allow-list, AUTH and optional TLS (REDIS-COMMANDS.md).
  • Takes over from Redis without a big-bang copy: a collection reads a missing key from Redis on first use, or writes through to it (GUIDE.md).
  • Easy to watch. A dashboard (perfcached-dashboard, its own process), /metrics for Prometheus (a Grafana dashboard is in contrib/grafana) and /stats as JSON. A node raises its own alerts and, in a build with mail, sends them over SMTP; in a fleet [mail] on one node mails for all (doc/alerts.md).
  • Changes while it runs. Collections are created, resized, renamed and dropped live; memory grows under load and is given back when idle.
  • Clusters without a coordinator. Nodes find each other by multicast on one segment, or through seed names where there is none (clouds, Kubernetes - doc/cluster.md), elect a master and rejoin by themselves. No node ids or peer lists to configure. Five ways to place data (Cluster modes).
  • Clients that follow the fleet. libperfd keeps standby connections, fails over in one send() and can send each key to its owner; cluster-aware Redis clients read CLUSTER SLOTS.
  • A standalone edition leaves every line of cluster code out, for a cache that will only ever be one node.

Known limits

  • WARNING - size limits. A record (key, value and a 28-byte header) is at most 262,080 bytes, so a value is at most just under 256 KB; larger is refused (value too large). A JSON document is at most 64 KB, a hash (one value) under 58,000 bytes, a key 4,096 bytes. In a cluster a write this node forwards to the key's owner carries at most 58,000 bytes of value. perfcached holds small, hot state - it is not a store for large objects or a web page cache.
  • No lists, sets, sorted sets, streams, bitmaps, HyperLogLog or geo. Keys hold strings, counters, JSON documents or hashes.
  • No transactions (MULTI/EXEC/WATCH) and no general scripting: EVAL/EVALSHA run only the approved Symfony Lock scripts.
  • Linux only (x86_64, arm64, arm32, i386), on glibc or musl.
  • The write-ahead log's ceiling is the storage's: about 1,000,000 small SETs a second under fsync = everysec on a fast disk, but with 1 KB records the log's writer tops out near 180,000 a second, and a disk that absorbs about 35 MB/s falls behind at about 35,000. Past that, writers wait for the log (doc/durability.md).
  • A cluster is one L2 segment by default; across routed links only with multicast_ttl and multicast routing, not measured over WAN links. discovery = unicast is tested in network namespaces that drop IP fragments and block UDP, not yet in a real cloud deployment, and suits a fleet of a few dozen nodes. spread mode has not carried production traffic.
  • Read-through and write-through carry strings, hashes and RedisJSON documents (a list, set, sorted set or stream answers WRONGTYPE); KEYS and SCAN see only what perfcached holds; proxy collections refuse an upstream; tracking Redis's changes needs every connection on one Redis server and an upstream user allowed INFO. Write-through does not bridge pub/sub, costs each write a round trip to the master, and two clients writing one key through two nodes at the same moment can leave Redis and the fleet with different winners.
  • The RESP and HTTP doors are plaintext unless their listener says tls (a build with OpenSSL). Under upstream_writes = through the RESP door can write to Redis: keep it on a trusted segment, behind resp_allow and [secrets] resp, or on TLS.
  • Upgrading from 0.7.4.x is a whole-fleet stop: 0.7.5 and later speak cluster wire epoch 4 alone and refuse an older node. Stop every node (perfcli -E <enable> fleetstop), install 0.7.5.1, start them all; the state is kept (GUIDE.md). Use libperfd 0.7.6 or later with it: an older libperfd does not route by key against 0.7.5 and later (every request takes a forward hop) and is refused a value over 58,000 bytes.

0.7.5.1 fixes 0.7.5's known issues: a write-through value too large for one record is refused before Redis takes it, a node rejoining during a reconcile pass no longer reports ready before its copy has finished, a collection change from the fleet no longer stalls the cluster thread on slow storage, and tombstone_acks = yes works in a mixed fleet - once every node runs 0.7.5.1, a fleet on no switches to yes one node at a time. It also carries the fixes from a full code review of 0.7.5. From 0.7.5 it rolls node by node (the same wire epoch); create, drop or rename no collection while the fleet is mixed. From 0.7.4.x it is still the whole-fleet stop above. Read the top of the ChangeLog before upgrading: perfcli load now needs -E, a read whose owner does not answer in time is refused as retryable instead of answered absent, and an IPv4 allow-list entry must be a full dotted quad (10/8 is refused).

Report anything odd as an issue, with perfcached -V, the config (secrets removed) and the log around the event. A security problem goes privately, as SECURITY.md says.

Install

Debian and Ubuntu: .deb packages for Debian 13 and 12 and Ubuntu 24.04 and 20.04 (amd64) are on the releases page: perfcached (the clustered daemon) or perfcached-standalone (one node only) - they install the same files and replace each other - and perfcached-dashboard (Debian 13 and 12, Ubuntu 24.04). On Alpine all three come as signed .apk files; a release tarball installs under /opt/perfcached-0.7.5.1.

sudo apt install ./perfcached_0.7.5.1-1+deb13_amd64.deb

libperfd 0.7.6.1: libperfd0 (the shared library) and libperfd-dev (header, static archive, pkg-config file) as .deb, libperfd / libperfd-dev as .apk. A program built against libperfd-dev links the shared library, so a libperfd update with the same SONAME is an install and a restart, no rebuild (lib/README.md).

From source: a C compiler, make and libsodium (OpenSSL for TLS): make && sudo make install && sudo systemd-sysusers. The editions, the allocator, debug and sanitizer builds, mail and TLS: doc/building.md.

Quick start

/etc/perfcached/perfcached.conf, owned by root, group perfcached, mode 640:

[daemon]
workers = 4                      # the number of cores

[memory]
arena_mb = 512                   # memory for keys and values

[secrets]
client = client-secret-example   # what applications present
cluster = cluster-secret-example # only the daemons hold it
enable = enable-secret-example   # privileged commands (perfcli -E)
resp = resp-password-example     # the Redis door's AUTH

[listen]
tcp = 0.0.0.0:6479               # native protocol
resp = 127.0.0.1:6380            # Redis protocol (optional)
resp_collections = 0:sessions    # Redis database 0 is the collection "sessions"

[collection sessions]
buckets_log2 = 16
perfcached -f /etc/perfcached/perfcached.conf -C    # check it
sudo systemctl enable --now perfcached
perfcli -a client-secret-example ping

All secrets differ. To serve Redis clients across a network, give the door a LAN address, resp_allow and TLS (resp = <addr:port> tls). For a cluster, add the same [cluster] section to every node and start them in any order:

[daemon]
state_dir = /var/lib/perfcached

[cluster]
multicast = 239.68.68.1:6480     # same group on every node
mode = eager                     # every node holds every key
collections = sessions

Open UDP and TCP 6480 and 6481 between the nodes (and TCP 6482 with discovery = unicast). perfcli fleet-status lists the members. Step by step, with the output to expect: GUIDE.md. Complete configurations for single nodes and every mode: contrib/CONFIGURATIONS.md; every option: contrib/perfcached.conf.example.

Cluster modes

One cluster runs one mode. The modes differ in how many nodes hold a key, and which.

mode copies of a key memory per node when a node dies
eager every node the whole keyspace nothing is lost, while replication keeps up (below)
spread K nodes (you pick K) K/P of the keyspace survives K-1 failures
shard one owner, by hash 1/P its share is unavailable
proxy one holder, by free memory 1/P its share is unavailable
store nodes that read it what each node reads keys read only there are lost

Under a saturated network an eager fleet can drop replication traffic, and a node then holds fewer keys than its peers until the background sweep has copied the rest: after a three-node fleet was driven past its 10 Gbit/s link with 1,000,000 keys, the nodes held 793,602, 964,513 and 1,000,000 keys at once, and all three held 1,000,000 within four minutes (doc/benchmarks.md).

Use eager for three nodes that must not lose anything, spread for four or more where you want a fixed redundancy, and shard for throughput with a client that routes by key. Durability is separate from copies: only the node that took a write logs it, so turn on the WAL and snapshots if the whole fleet may stop at once. doc/modes.md has the trade-offs in full.

Clients

  • libperfd, the C client (MIT): authenticates, pipelines and follows the fleet (lib/README.md).
  • perfcli, the redis-cli of the native protocol (PERFCLI-COMMANDS.md); perfdump and perfload for parallel backup and restore between fleets of any size or mode; perfcached-dashboard, the status page.
  • PHP: an extension over libperfd for PHP 8.1 or later (lang/php/README.md), with a Symfony cache adapter.
  • Any Redis client through the Redis door.
  • Asterisk: dialplan functions in contrib/asterisk.

Performance

Turn NIC multiqueue on - one queue per CPU, on the nodes and the clients - and keep the default io_uring backend (PRODUCTION.md, section 7). With one receive queue, one CPU handles everything a host receives and caps it.

redis-benchmark, unmodified, against one perfcached 0.4.0 node (4 workers) and against redis-server 8.10.1, each on the same 16-vCPU host, with the client on a second host across a real network. 20k keys of 200 bytes, 50 clients, median of 3:

SET/s GET/s SET p99 GET p99
redis-server, no pipelining 41,824 46,468 1.54 ms 1.47 ms
perfcached, no pipelining 37,425 44,703 1.08 ms 1.00 ms
redis-server, pipeline 64 760,746 948,317 5.39 ms 4.98 ms
perfcached, pipeline 64 1,643,385 1,314,060 1.73 ms 1.74 ms

With no pipelining both servers wait on the network round trip; with pipelining perfcached's workers pull ahead, at a third of Redis's tail. The lead comes from the workers, not from a cheaper command: per core, a SET and its write-ahead log record cost perfcached more than a SET costs a Redis that persists nothing, so a node with two workers can trail one Redis thread on SET. A three-node fleet through a routing client reached 31 million GET/s on bare metal (How it compares). A KEYS that walks 74,000 keys 50 times a second costs Redis's other clients a quarter of their GET rate; perfcached's keep theirs - the KEYS caller waits longer instead. Every table, its method and how to reproduce it: doc/benchmarks.md and bench/RESULTS.md.

Upgrading

  • 0.7.4.x to 0.7.5.1: a whole-fleet stop (above).
  • 0.7.5 to 0.7.5.1: a rolling restart, as below; no collection create, drop or rename while the fleet is mixed.
  • Within the support window - from 0.7.5 to a later 0.7.5.x patch or to the next minor's releases - a rolling restart: members first, the master last, one node at a time, each only once its stats.cluster.restart.safe says so and the fleet reads healthy (every node ready, peers up, record counts not fallen). From an older minor, step through the last patch of each minor in between. Mixed versions are for the roll, not for running; a release note names any exception.
  • Packages do not restart the daemon - install, then restart node by node (PRODUCTION.md, section 8). A tarball install upgrades through the staged build and the helper (doc/operations.md, "The upgrade helper").
  • The client library of the same or the previous minor talks to both sides of a roll; against 0.7.5 use libperfd 0.7.6 or later.

What may change between releases: doc/compatibility.md.

Documentation

License

  • The daemon and its tools: GPL-2.0-or-later (COPYING).
  • libperfd, the client library: MIT (lib/LICENSE), so applications of any license can link it.
  • The PHP extension and its Symfony adapter: MIT (lang/php/LICENSE).

LICENSING.md says which files are on which side. Every file libperfd is built from carries an MIT SPDX line, a file with no SPDX line is GPL-2.0-or-later, and the test suite checks that the MIT side never includes GPL code. libsodium is ISC (see lib/NOTICE). Contributions need a DCO sign-off; see CONTRIBUTING.md.

About

Multithreaded, self-clustering in-memory cache for Linux - its own Noise-encrypted binary protocol plus a Redis (RESP2) door, WAL + snapshot persistence, read-through from Redis, alerts by mail, and libperfd, the MIT C client library (shared or static)

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages