Get started

Quickstart: run KVStash on one machine

Start the daemon with a DRAM tier, store a block, read it back and check the metrics. This is the same daemon production runs, with the NVMe and S3 tiers left off.

Last updated

Before you start

  • A Linux machine, x86-64 or arm64, with 2 GB of free memory. macOS runs the daemon for development only.
  • The kvblockd and kvbctl binaries on your PATH. Both are static, so there is nothing else to install. Download the daemon from the install page: static binaries for Linux x86-64 and arm64 (macOS arm64 for development), with SHA-256 checksums, or run curl -fsSL https://kvstash.com/install.sh | sh. The container image and Helm chart are available on request.
  • curl to read the health and metrics endpoints.

Check the binaries: kvblockd --version and kvbctl version each print a version string.

Run it

  1. Write a config file. This one keeps every listener on loopback and gives the hot tier 1 GiB.
    config.yaml
    # config.yaml: DRAM-only, loopback only. Every key is optional;
    # the full list is on the configuration reference page.
    listen_addr: "127.0.0.1:9440"    # data plane (engines and kvbctl connect here)
    metrics_addr: "127.0.0.1:9442"   # /metrics and /healthz
    dram_arena_bytes: 1073741824     # 1 GiB hot tier
    dram_hugepages: false
    namespaces_path: "/etc/kvblockd/namespaces.yaml"   # use an absolute path
    nvme_paths: []                   # no NVMe tier for the first run
  2. Create a namespace. A namespace is a tenant: its own key space and its own token. A daemon with no namespaces accepts no connections, by design.
    namespaces.yaml
    # namespaces.yaml: who may connect. With no namespaces, nobody can.
    namespaces:
      - { name: demo, id: 1, token: "demo-token" }   # change before real use
  3. Start the daemon. It stays in the foreground and logs to the terminal. Stop it later with Ctrl-C, which drains in-flight requests first.
    Shell
    sudo mkdir -p /etc/kvblockd
    sudo cp config.yaml namespaces.yaml /etc/kvblockd/
    kvblockd --config /etc/kvblockd/config.yaml

    The last lines of the log name each listener, ending with kvblockd listening addr=127.0.0.1:9440. The admin listener for adding tenants at runtime is off in this config; turn it on when you need it.

  4. Check that it is ready. In a second terminal:
    Shell
    curl -s 127.0.0.1:9442/healthz
    # ok

    While the daemon is still starting, /healthz answers HTTP 503 with starting.

  5. Store a block and read it back. kvbctl turns a plain name like greeting into a 32-byte key by hashing it, which is convenient for tests. Engines derive their own keys.
    Shell
    export KVBCTL_TOKEN=demo-token        # keeps the token out of argv
    
    echo "hello" | kvbctl put -ns demo greeting -
    # stored 6 bytes
    
    kvbctl get -ns demo greeting
    # hello
    
    kvbctl exists -ns demo greeting
    # consecutive=1
    # greeting	OK
  6. Look at the counters. The bytes you wrote and read show up in Prometheus format. The ns label is the namespace id from namespaces.yaml.
    Shell
    curl -s 127.0.0.1:9442/metrics | grep -E '^kvb_(bytes_total|hits_total|blocks)'
    # kvb_blocks{tier="dram"} 1
    # kvb_bytes_total{dir="in",ns="1"} 6
    # kvb_bytes_total{dir="out",ns="1"} 6
    # kvb_hits_total{ns="1",tier="dram"} 1

What just happened

  • put opened a connection, authenticated into the demo namespace once, and wrote the block with a two-phase commit: the block is visible to readers only after the commit is acknowledged.
  • get read it back. The client checks the block's xxh3 checksum before printing a byte.
  • exists asked how many keys, from the start of the list, are present. Engines use this to find how much of a prompt prefix they can skip.
  • The block lives in DRAM only. Restart the daemon and it is gone. That loss is safe, because a KV block can always be recomputed; add an NVMe tier to keep blocks across restarts.

Next steps

Something missing or wrong on this page? Email rudray@kvstash.com and it gets fixed.