A Redis-compatible, in-memory key-value server written in Go using TCP sockets,
RESP, and Linux epoll.
Tool: redis-benchmark (from redis-tools), run in WSL2 (Ubuntu) against
FlokiDB built and running in the same WSL instance, port 7379.
| Command | Result | Notes |
|---|---|---|
redis-benchmark -p 7379 -t set,get -n 100000 -c 50 -q |
GET: ~152,439 req/s, p50 = 0.167 ms | 100k requests, 50 clients, no pipelining. SET (run separately): ~156,495 req/s, p50 = 0.159 ms. |
redis-benchmark -p 7379 -t set,get -n 200000 -c 50 -P 16 -q |
Failed: Connection reset by peer |
Pipelining. The server closes the connection when a read ends mid-command. See "Deferred: Stream-safe command pipelining" below. |
Baseline: real Redis 8.0.5 (redis-server --port 6380 --save "", no persistence),
same machine and same benchmark command (-t set,get -n 100000 -c 50 -q):
| Server | SET (req/s) | GET (req/s) | p50 |
|---|---|---|---|
| Redis 8.0.5 | 165,289 | 160,256 | 0.151 ms |
| FlokiDB | 156,495 | 152,439 | 0.159 ms (SET), 0.167 ms (GET) |
FlokiDB reaches about 95% of Redis throughput on SET and GET in this test. Note that Redis ran with persistence off, while FlokiDB writes an AOF.
redis-benchmark -p 7379 -t set,get -n 200000 -c <clients> -q, with
ulimit -n 65536 for both server and client, same WSL2 instance (loopback).
| Clients | SET (req/s) | GET (req/s) | p50 SET / GET | Server survived |
|---|---|---|---|---|
| 50 | 152,555 | 150,602 | 0.167 / 0.167 ms | yes |
| 500 | 135,593 | 134,862 | 1.807 / 1.783 ms | yes |
| 1,000 | 122,474 | 110,988 | 4.087 / 4.351 ms | yes |
| 2,000 | 97,943 | 91,575 | 9.671 / 10.479 ms | yes |
| 5,000 | 75,131 | 71,149 | 32.831 / 34.463 ms | yes |
| 10,000 | 92,039 | 102,881 | 53.791 / 47.167 ms | yes |
| 15,000 | 102,669 | 110,497 | 48.767 / 46.527 ms | yes |
FlokiDB served 15,000 concurrent connections without errors or crashes, sustaining ~100K req/s. Latency rises with client count, as expected for a single-threaded event loop. Runs beyond 15,000 clients were not completed. The benchmark client shares the same machine, so it competes for CPU at high client counts.
WARNING: Could not fetch server CONFIG appears because CONFIG GET is not
implemented. It is harmless.
The current pipelining implementation can decode and execute multiple complete RESP commands when they arrive together in one socket read. TCP does not preserve application-message boundaries, however, so a command may be split across reads, and a non-blocking write may send only part of a response batch.
The next pipelining milestone is to maintain state for every connected client:
type ConnState struct {
Input []byte // received bytes not yet decoded into a complete command
Output []byte // response bytes not yet written to the socket
}For the asynchronous server, store this state by client file descriptor:
clients := map[int]*ConnState{}- On
EPOLLIN, read available bytes and append them toConnState.Input. - Decode complete RESP commands while tracking the number of bytes consumed.
- Execute complete commands in order and append their responses to
ConnState.Output. - If decoding returns
core.ErrIncompleteRESP, retain the incomplete trailing bytes instead of closing the connection. - Remove only successfully consumed bytes from the input buffer.
- Enforce a maximum input-buffer size so one client cannot consume unlimited memory.
A useful decoder contract is:
func DecodeCommands(data []byte) (cmds RedisCmds, consumed int, err error)- Attempt to write
ConnState.Outputafter evaluating commands. - Remove only the bytes successfully written.
- Retain the remainder when
writereturns a partial count,EAGAIN, orEWOULDBLOCK. - Enable
EPOLLOUTwhile output remains queued. - Continue flushing when epoll reports
EPOLLOUT. - Disable
EPOLLOUTafter the output buffer becomes empty. - Enforce a maximum output-buffer size for backpressure.
The intended connection flow is:
EPOLLIN -> input buffer -> RESP decoder -> command evaluation
|
v
EPOLLOUT <- socket write <- output buffer <- ordered responses
This work should be completed before describing FlokiDB's pipelining as fully TCP-stream-safe.