Repository navigation
Add Memcached meta-command protocol support (memcache_meta) - #363
Conversation
Adds a new value 'memcache_meta' to the -P/--protocol flag, enabling
benchmarking of the Memcached meta protocol (memcached 1.6+).
Wire format
-----------
Every command is wire-terminated by 'mn\r\n' so every response is
uniformly terminated by 'MN'. This eliminates write-time/parse-time
mode-attribution races under pipelined / mixed-command workloads:
SET: ms <k> <l> T<e>\r\n<value>\r\n mn\r\n -> HD\r\n MN\r\n
GET: mg <k> v\r\n mn\r\n -> VA <n>\r\n<data>\r\n MN\r\n
(or EN MN on miss)
multi-GET: pipelined 'mg ... v\r\n' + 'mn\r\n' -> ...VA/EN..., MN
The wire cost is +4 request +4 response bytes per command; at typical
value sizes (>= 64B) this is < 1% of bandwidth.
Implementation
--------------
The new memcache_meta_protocol class inherits from memcache_text_protocol
to reuse the buffer plumbing and the seven assert(0) stubs for operations
not supported by either Memcached path (auth, select_db, cluster_slots,
wait, arbitrary_command). Only the four wire-touching methods are
overridden: write_command_set / write_command_get / write_command_multi_get
/ parse_response.
Performance touches:
- mg / multi-get write paths use raw evbuffer_add (no vsnprintf in the
per-key hot path), matching the existing memcache_text multi-get pattern.
- VA <size> parsing uses strtoul (not sscanf) on the GET hot path.
- Response state machine has a single termination rule (read until MN),
removing all conditional branches on external state in the hot loop.
Validation against memcached 1.6.41 (4 clients x 2 threads x 10K ops):
meta SETs 135K ops/sec (text: 131K)
meta GETs 130K ops/sec (text: 133K, ~3.5x less response bandwidth)
meta multi-get(4) 256K keys/sec
mixed --pipeline=4 246K ops/sec
Tests
-----
13 unit tests in tests/test_memcache_meta_protocol.py exercise the
parser via an in-process mock TCP server that speaks the meta protocol,
so the suite runs without requiring memcached or Redis. Coverage:
Happy path: single SET, single GET (hit / miss), GET against
pre-loaded data, multi-get with mn terminator,
SET -> GET roundtrip
Status codes: NS / EX / NF responses do not error
Async / partial: fragmented VA delivery (header and value across
two TCP sends -> rs_read_value 'need more data' path)
Error path: unknown server response classified as parse error
Pipelining: --pipeline=4 SET, mixed --pipeline=2 SET +
multi-get (regression for write-time/parse-time race)
Multi-get: deterministic VA + EN mix within a single pipeline
Tests are also discoverable by RLTest via top-level test_meta_*
adapters so they ride along with ./tests/run_tests.sh.
Documentation
-------------
Updated --help text, error message for invalid -P, manpage
(memtier_benchmark.1), README.md feature bullet, and bash completion.
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
Addresses two issues found in code review (PR redis#363): 1. get_protocol_name() had no case for PROTOCOL_MEMCACHE_META, causing --show-config and the JSON output file to report 'protocol = none' instead of 'memcache_meta'. Add the missing branch. 2. The --authenticate validation only rejected PROTOCOL_MEMCACHE_TEXT. Passing --authenticate with --protocol=memcache_meta hit the inherited memcache_text_protocol::authenticate() assert(0), producing a confusing crash report instead of the same clean usage error the text path emits. Extend the guard to reject memcache_meta as well. Verified manually: - '-P memcache_meta --show-config' now prints 'protocol = memcache_meta' - The JSON output reports 'protocol: memcache_meta' - '-P memcache_meta --authenticate=foo' now exits with the clean error 'authenticate can only be used with redis or memcache_binary' instead of crashing. - Existing text / binary / redis auth paths unchanged. - All 13 meta unit tests still pass.
|
cursor review |
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this, and for extending
The parser itself looks careful to me. I'd mainly want the single-key (would file this as a comment, not a formal block) |
|
Owner follow-up at 1a4d0a5:
The missing quote is fixed. Independent semantic review also found partial parser state surviving reconnect: the new reset override clears that state and byte accumulation. A deterministic regression fails before the fix and passes afterward; two socket reproductions now finish with the correct counts and RX bytes. Final local validation: 16 integration cases and 15 unit programs pass. Minimum Memcached version is now accurately documented as 1.6.10, when the implemented |
|
Follow-up at cd1f799 (runtime176fbb6):
The expanded unit additionally checks every byte split of valid replies (including incomplete value CRLF) and the signed libevent length boundary. All15unit programs and16integration cases pass. The fork CI matrix fallback is the same independently reviewed change required by #257/#258; repository overrides retain precedence. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 5460d2a. Configure here.
|
Follow-up at 47b0a08:
Final local validation:18integration cases and15unit programs pass. The defined-error fix is awaiting the independent focused maintainer recheck; other protocol, replay, lifetime, output and integration reviews are recorded. |
|
The expectation queue now makes single-key For a limited sanity check, I ran three rotated repeats of 30,000 GET hits, one thread/client, 32-byte values, against the same private Unix Memcached 1.6.24 server. Median ops/s at pipeline1: initial integrated meta76.1k, final meta77.5k, final text77.5k. At pipeline32: initial meta763.7k, final meta845.6k, final text861.3k. All runs completed exactly30,000 hits. Pipeline32 meta samples ranged716.1–920.1k on this shared host; these short runs neither isolate the added checks nor establish a speedup/parity claim. They show no obvious throughput collapse in this sanity workload. No performance claim was restored. The replay ordering was independently reviewed and exercised: five real GET/SET/MGET/mixed/verifier retries failed before the metadata hook and pass after it; LIFE also covered reset/replay ownership under sanitizers. The hook is at the existing central serialized replay path. The expectation queue remains strict, so missing metadata is rejected instead of silently assigning a reply to an unrelated request. The CI fallback is the shared #257 prerequisite: fork context otherwise fails matrix expansion before the seven distro jobs exist. Configured values retain precedence; after #257 merges it leaves this PR’s base diff. In 3f2d0b0 I also removed the unused hit-key preload from the all-miss test (focused test passes) and rewrote the parser comment around both the expectation queue and MN boundary. Runtime is unchanged from47b0a08, which now has all seven independent lens approvals. |
|
Following up on the07:21:14 revision: the single-key and verifier GET constructors both set MN framing is the deliberate first-version workload choice described in the previous reply: an explicit logical-operation boundary retained for all operations, with an extra server command disclosed and no claim of equivalence to clients that omit it. The pointer comparison tracks ownership of the first status line, not content equality; boundary/retained-value/error tests exercise this. I kept that reviewed state representation rather than introduce a second mutable boolean for the same state. The self-contained mock cases intentionally remain available through the existing RLTest adapter so normal suite execution cannot omit them. They do not claim to exercise the Redis/cluster/TLS environment that launches them. This can repeat the same mock coverage in full-suite cells; moving those cases to a single dedicated job is a CI-runtime optimization, not required for parser correctness. The focused standalone invocation also remains available. The shared CI prerequisite has now landed separately with #257 ( |

Problem
Memtier cannot benchmark Memcached's meta text protocol. Add
--protocol=memcache_metafor SET, GET and multi-GET against Memcached 1.6.10+ while retaining the existing Redis, text and binary protocols.Root cause
There is no meta protocol factory/CLI implementation. The original unmerged parser also accepts malformed value lengths and framing as completed operations, and unsupported WAIT/arbitrary-command options can reach inherited assertions.
Fix
Add meta
ms/mgrequests and a response parser. Each logical request ends withmn, and its reply ends atMN; a multi-GET groups its individualmgrequests before one terminator. An ordered expectation queue validates each reply kind and exact section count, while the terminator detects excess sections before an operation completes. Mixed pipelined replies do not depend on a mutable write-side mode. The extra terminator costs four request and four response bytes per logical operation; relative overhead depends on the workload, and no universal throughput improvement is claimed.Validate unsigned value lengths against the parser's representable range, complete status/number tokens and value CRLF. Reject a bare terminator without a reply. Retain valid empty values and response flags. Defined ERROR, CLIENT_ERROR and SERVER_ERROR replies consume one expected section and complete at MN through normal error accounting/retry policy. Keep the first error status even after earlier MGET hits; truly malformed replies remain parser failures. Reset partial value state, accumulated response bytes and pending expectations when reconnecting. Reject unsupported WAIT/arbitrary commands at startup; authentication, database selection, cluster and offset validation also cover meta mode. Report
memcache_metain structured configuration, help/man and completion. Existing protocols retain their implementations.Original author commits are preserved, with a normal merge of upstream
0bb7fc5. Test reports use separate temporary directories so parallel invocations cannot overwrite each other's JSON.Tests
Affected versions
This is a new feature with no released introducing commit. Upstream
0bb7fc5has nomemcache_metaprotocol. The parser and unsupported-option defects fixed during review were confined to this unmerged feature branch.Every logical meta operation includes one extra
mnserver command, with 4 request and 4 response bytes. The ordered expectation queue could support omitting it for single-key operations, but this implementation deliberately retains a uniform explicit boundary. Results describe that wire workload; no throughput equivalence with clients that omitmnis claimed.🤖 Generated with Claude Code
Note
Medium Risk
New protocol path touches connection I/O, parsing, and retry replay; mistakes could mis-account hits/misses or mishandle pipelined replies, though scope is limited to Memcached meta mode with added validation and tests.
Overview
Adds
--protocol=memcache_metaso memtier can benchmark Memcached 1.6.10+ meta text commands (msSET,mgGET/MGET) with every logical request terminated bymnand replies validated through an ordered expectation queue untilMN.The new
memcache_meta_protocolinprotocol.cppimplements wire encoding, strict response parsing (value lengths, CRLF, defined errors vs parse failures), andreset_stateon reconnect.prepare_request_replayonabstract_protocolrestores reply expectations when serialized requests are resent fromshard_connection. Startup rejects--wait-ratioand--commandfor this mode; docs, man page, bash completion, and README document the option.Tests: C++
memcache_meta_test(wired inMakefile.am) and a large Python suite with an in-process mock server. CI: smoke-test matrix falls back to a default image list whenvars.SMOKE_TEST_IMAGESis missing on fork PRs.Reviewed by Cursor Bugbot for commit 3f2d0b0. Bugbot is set up for automated code reviews on this repo. Configure here.