Mostra HN: Keybench – Strumento di misurazione delle prestazioni personalizzabile ed estensibile per i database key-value
Sintesi redazionale: Lavoro con i motori di archiviazione da un bel po' di tempo e, in realtà, non esisteva uno strumento simile a sysbench o HammerDB per i motori di archiviazione chiave-valore. Per questo motivo vi presento un POC chiamato keybench.. Fonte originale: https://github.com/guycipher/keybench
<p>keybench<br>========<br>A scriptable, extensible performance tool for sorted key value stores.<br>You write the workload in Lua. keybench drives it across one or more storage<br>engines, times every operation, and reports throughput and latency. The same<br>script runs unchanged against every engine, so a comparison measures the<br>engines and not the harness.<br>POSIX only currently.<br>What it measures<br>================<br>keybench reports two rates and a latency distribution.<br>wu/s workload units per second. One unit is one call to your run()<br>function. This is the rate of whole operations as your script<br>defines them, a "view cart" or a "checkout", regardless of how many<br>key touches each one costs.<br>ops/s primitive operations per second. One primitive op is a single put,<br>get, del, range, or scan call, or one key handled inside an mget,<br>mput, or mdel. A range or a scan counts once no matter how many rows<br>it returns. This is the rate of raw key touches.<br>When every unit is one primitive op the two rates are equal and the report<br>prints one throughput line. When a unit does several primitive ops, such as a<br>batch of B keys or a cart checkout that scans then deletes, the report prints<br>wu/sec and ops/sec on separate lines. For a batched verb ops/sec is exactly B<br>times wu/sec, because each unit performs B key touches, so batching shows as<br>ops/sec rising with B while wu/sec falls, the difference being the fixed per<br>call cost spread over more keys.<br>Latency is recorded per operation kind as a distribution, not an average. Each<br>of put, get, del, range, mget, mput, and mdel has its own histogram, and a scan<br>is timed into the range histogram. The report gives p50, p99, p99.9, and the<br>max for each.<br>How it works<br>============<br>Five parts, each replaceable.<br>The engine owns concurrency. keybench spawns the worker threads, splits the op<br>budget across them, and joins them. A worker runs your script in its own Lua<br>state with its own random seed. The harness never holds a lock around an<br>engine call, so a serialized engine reports as serialized and a parallel one<br>reports as parallel. The Lua script stays single threaded and never reasons<br>about locks.<br>The workload is a Lua table. A file returns a table with a name, an optional<br>load function, and a run function. load seeds the store before timing, and the<br>harness runs it on every worker thread at once, each filling its own shard, so a<br>large dataset loads in parallel. run is the measured unit and the harness calls<br>it until the op budget or the time budget is spent. Both receive a ctx table<br>carrying users, items, ops, seed, thread, threads, the current iter, and, when<br>the workload sweeps a parameter of its own, that parameter under its own name.<br>The store is one verb set over every engine. Your script calls a global kv<br>table. The same eight verbs reach whichever engine is selected. keybench times<br>the call, files the sample in the right histogram, and counts the primitive<br>ops.<br>The backend is a self registering plugin. Each engine lives under backends/<br>with its own build fragment and registers itself before main runs. Selecting<br>one by name, or several for a comparison, is a command flag. Adding one is a<br>new directory and a vtable, no edit to the core.<br>The reporter is a sink. A run broadcasts its metadata, its probes, its<br>aggregated points, and its live samples to every reporter you asked for. A<br>console reporter prints a human report. A tsv reporter writes machine rows. A<br>timeline reporter writes one row per live sample. You can run several at once.<br>Building<br>========<br>keybench vendors its own Lua, so the default build needs only a C compiler and<br>pthreads.<br>make<br>That produces ./keybench with the in memory skiplist engine compiled in. The<br>skiplist needs no external library and is the reference engine.<br>To compile in the persistent engines, name them.<br>make ROCKSDB=1 add the RocksDB engine<br>make TIDESDB=1 add the TidesDB engine<br>make BACKENDS="skiplist rocksdb tidesdb"<br>No special allocator is linked by default, keybench uses the system one. If a<br>distro rocksdb or tidesdb was itself built against jemalloc or other, link the same<br>allocator first with ALLOC=jemalloc so the whole malloc family agrees, which<br>avoids a crash when a database is reopened across sweep points. ALLOC=tcmalloc<br>works too, and ALLOC_LIBS="..." links any other allocator or a custom path. The<br>engine library and header locations are also overridable, so a custom install<br>works.<br>make ROCKSDB=1 ROCKSDB_CFLAGS=-I/opt/rocksdb/include ROCKSDB_LIBS="-L/opt/rocksdb/lib -lrocksd</p><p>_(testo troncato)_</p>
