Skip to content

Make key encoder optional and remove default implementation#82

Merged
bisho merged 1 commit into
mainfrom
03-16-adopt_key_encoding_directly_in_socket
Mar 26, 2026
Merged

Make key encoder optional and remove default implementation#82
bisho merged 1 commit into
mainfrom
03-16-adopt_key_encoding_directly_in_socket

Conversation

@bisho
Copy link
Copy Markdown
Member

@bisho bisho commented Mar 16, 2026

Remove default key encoder and make key encoding optional

This change removes the default_key_encoder function and makes key encoding optional throughout the codebase. The key_encoder_fn parameter in CacheClient and DefaultExecutor is now Optional[Callable[[Key], bytes]] instead of having a default implementation.

When no key encoder is provided, the executor now passes the raw key string directly to the underlying socket layer, which handles key encoding internally. This simplifies the API by removing the need for a default key encoding strategy at the client level. It also makes the socket api more reliable and easy to use, as it handles large keys, binary, unicode all transparently.

We still prove the ability to use your own encoding for backwards compatibility, if you need to match existing behavior. As long as the key encoder returns small ascii keys, the socket endoder will not change the keys any further.

The change affects:

  • Removal of default_key_encoder function and related imports
  • Updated method signatures to make key_encoder_fn optional
  • Modified executor logic to conditionally apply key encoding
  • Updated tests to reflect the new behavior where key encoding happens at the socket level

Performance

Common config: server 127.0.0.1:11211, 10 threads, 1.00M requests (4 runs × 25,000 ops × 10 threads), 200 key space, GC disabled, 160/200 keys populated (95% small 80-250B, 5% large 100KB)                                                                                

  ┌───────────────┬────────┬─────────┬──────────────────────┬──────────────────────┬──────────────────────┐                                                                                                                                                                                       
  │               │        │         │    Socket in Rust    │    meta_* in Rust    │   key-enc in Rust    │
  │   Operation   │        │ BEFORE  ├──────────┬───────────┼──────────┬───────────┼──────────┬───────────┤                                                                                                                                                                                       
  │               │        │         │  Result  │  Speedup  │  Result  │  Speedup  │  Result  │  Speedup  │                                                                                                                                                                                       
  ├───────────────┼────────┼─────────┼──────────┼───────────┼──────────┼───────────┼──────────┼───────────┤                                                                                                                                                                                       
  │               │ RPS    │  46,600 │   76,652 │           │  110,287 │           │  112,054 │           │                                                                                                                                                                                       
  │  SET          ├────────┼─────────┼──────────┤   1.65x   ├──────────┤   2.37x   ├──────────┤   2.40x   │                                                                                                                                                                                       
  │               │ us/req │   21.46 │    13.05 │           │     9.07 │           │     8.92 │           │                                                                                                                                                                                       
  ├───────────────┼────────┼─────────┼──────────┼───────────┼──────────┼───────────┼──────────┼───────────┤                                                                                                                                                                                       
  │               │ RPS    │  46,135 │   81,401 │           │  116,382 │           │  118,682 │           │                                                                                                                                                                                       
  │  GET          ├────────┼─────────┼──────────┤   1.76x   ├──────────┤   2.52x   ├──────────┤   2.57x   │                                                                                                                                                                                       
  │               │ us/req │   21.68 │    12.28 │           │     8.59 │           │     8.43 │           │                                                                                                                                                                                       
  ├───────────────┼────────┼─────────┼──────────┼───────────┼──────────┼───────────┼──────────┼───────────┤                                                                                                                                                                                       
  │               │ RPS    │   2,677 │    3,626 │           │    3,560 │           │    3,567 │           │                                                                                                                                                                                       
  │  MULTI_GET(5) ├────────┼─────────┼──────────┤   1.35x   ├──────────┤   1.33x   ├──────────┤   1.33x   │                                                                                                                                                                                       
  │               │ us/req │  373.52 │   275.81 │           │   280.86 │           │   280.31 │           │                                                                                                                                                                                       
  ├───────────────┼────────┼─────────┼──────────┼───────────┼──────────┼───────────┼──────────┼───────────┤                                                                                                                                                                                       
  │               │ RPS    │  48,080 │   82,886 │           │  123,053 │           │  125,639 │           │                                                                                                                                                                                       
  │  DELETE       ├────────┼─────────┼──────────┤   1.72x   ├──────────┤   2.56x   ├──────────┤   2.61x   │                                                                                                                                                                                       
  │               │ us/req │   20.80 │    12.06 │           │     8.13 │           │     7.96 │           │                                                                                                                                                                                       
  └───────────────┴────────┴─────────┴──────────┴───────────┴──────────┴───────────┴──────────┴───────────┘

Copy link
Copy Markdown
Member Author

bisho commented Mar 16, 2026

@bisho bisho marked this pull request as ready for review March 16, 2026 16:13
@bisho bisho requested a review from a team March 24, 2026 17:00
@bisho bisho force-pushed the 03-12-adopt_meta__and_send_meta__api_from_memcachesocket branch from b947f0b to dee32d0 Compare March 25, 2026 09:18
@bisho bisho force-pushed the 03-16-adopt_key_encoding_directly_in_socket branch 2 times, most recently from 1d8d11b to 35c7d13 Compare March 25, 2026 09:21
@bisho bisho force-pushed the 03-12-adopt_meta__and_send_meta__api_from_memcachesocket branch from dee32d0 to 96943d7 Compare March 25, 2026 12:38
@bisho bisho force-pushed the 03-16-adopt_key_encoding_directly_in_socket branch from 35c7d13 to 285cfef Compare March 25, 2026 12:38
@bisho bisho force-pushed the 03-12-adopt_meta__and_send_meta__api_from_memcachesocket branch from 96943d7 to e04597e Compare March 25, 2026 13:21
@bisho bisho force-pushed the 03-16-adopt_key_encoding_directly_in_socket branch 3 times, most recently from 6e3b2d9 to 6ed12d6 Compare March 26, 2026 14:11
@bisho bisho force-pushed the 03-12-adopt_meta__and_send_meta__api_from_memcachesocket branch from e04597e to 03324e8 Compare March 26, 2026 14:11
Copy link
Copy Markdown

@xmartinez xmartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG! Just a nit re: version mismatch.

Comment thread src/meta_memcache/__init__.py Outdated
@bisho bisho force-pushed the 03-16-adopt_key_encoding_directly_in_socket branch from 6ed12d6 to 51da0e9 Compare March 26, 2026 15:13
@bisho bisho force-pushed the 03-12-adopt_meta__and_send_meta__api_from_memcachesocket branch from 03324e8 to 314d081 Compare March 26, 2026 15:13
@bisho bisho changed the base branch from 03-12-adopt_meta__and_send_meta__api_from_memcachesocket to graphite-base/82 March 26, 2026 15:21
@bisho bisho force-pushed the 03-16-adopt_key_encoding_directly_in_socket branch from 51da0e9 to 6ceea8d Compare March 26, 2026 15:27
@bisho bisho force-pushed the graphite-base/82 branch from 314d081 to 7ba0963 Compare March 26, 2026 15:27
@bisho bisho changed the base branch from graphite-base/82 to 03-12-adopt_meta__and_send_meta__api_from_memcachesocket March 26, 2026 15:27
Copy link
Copy Markdown
Member Author

bisho commented Mar 26, 2026

Merge activity

  • Mar 26, 3:31 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Mar 26, 3:38 PM UTC: Graphite rebased this pull request as part of a merge.
  • Mar 26, 3:39 PM UTC: @bisho merged this pull request with Graphite.

@bisho bisho changed the base branch from 03-12-adopt_meta__and_send_meta__api_from_memcachesocket to graphite-base/82 March 26, 2026 15:36
@bisho bisho changed the base branch from graphite-base/82 to main March 26, 2026 15:37
@bisho bisho force-pushed the 03-16-adopt_key_encoding_directly_in_socket branch from 6ceea8d to 22fea2e Compare March 26, 2026 15:38
@bisho bisho merged commit 82cafeb into main Mar 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants