Skip to content

Add MemcacheSocket class and response types with CI tests#13

Merged
bisho merged 1 commit into
mainfrom
03-11-socket_in_rust
Mar 24, 2026
Merged

Add MemcacheSocket class and response types with CI tests#13
bisho merged 1 commit into
mainfrom
03-11-socket_in_rust

Conversation

@bisho
Copy link
Copy Markdown
Member

@bisho bisho commented Mar 11, 2026

Motivation / Description

This pull request introduces a high-performance Rust-based MemcacheSocket class that provides low-level socket operations for memcache protocol communication. The implementation focuses on performance optimization through zero-copy operations, efficient buffer management, and GIL-free I/O operations.

This replaced the python-implementation in meta-memcahce-py extension and provides 20% faster gets and 40% faster set/deletes (less CPU) on multithreaded tests:

Latency per-request is not that measurable, as typical memcache latency will be dominated by the network, but it significantly reduces CPU usage, allocations and GIL lock time.

Before/after with 10 threads doing operations on a loop against a local memcache.

=== Starting benchmark ===
 - server: 127.0.0.1:11211
 - consistent_sharding: OFF
 - concurrency: 10 threads
 - per phase: 0.30M requests (3 runs x 10,000 ops x 10 threads)
 - key space: 200 keys

-SET total: 0.30M in 6.72s => 44,638 RPS / 22.40 us/req
-GET total: 0.30M in 6.79s => 44,214 RPS / 22.62 us/req
-DELETE total: 0.30M in 6.75s => 44,415 RPS / 22.51 us/req
+SET total: 0.30M in 4.02s => 74,598 RPS / 13.41 us/req
+GET total: 0.30M in 5.45s => 55,047 RPS / 18.17 us/req
+DELETE total: 0.30M in 3.94s => 76,060 RPS / 13.15 us/req

Changes introduced

  • Added MemcacheSocket class with methods for sending commands (sendall), receiving responses (get_response), and reading value data (get_value)
  • Implemented response type classes (Value, Success, Miss, NotStored, Conflict) to represent different memcache server responses
  • Added NOOP command handling to support pipelined operations and response synchronization
  • Introduced server version constants (SERVER_VERSION_AWS_1_6_6, SERVER_VERSION_STABLE) for compatibility with different memcache server implementations
  • Added libc dependency for direct system call access to socket operations
  • Implemented zero-copy value reading for small values that fit within the internal buffer
  • Added support for non-blocking sockets with timeout handling via poll()
  • Created comprehensive test suite covering socket operations, response parsing, buffer management, and error handling scenarios
  • Added CI jobs for both Rust tests and Python integration tests using uv and maturin
  • Bumped package version from 0.1.7 to 2.0.0 to reflect the major API additions

@bisho bisho marked this pull request as ready for review March 11, 2026 14:04
Copy link
Copy Markdown

@antoniobg antoniobg left a comment

Choose a reason for hiding this comment

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

Overall this is a really impressive change — the performance gains are substantial and the code is well-structured. I found a few issues worth addressing before merging, mostly around socket/OS-level edge cases.

Comment thread src/memcache_socket.rs
Comment thread src/memcache_socket.rs
Comment thread src/memcache_socket.rs
Comment thread src/memcache_socket.rs Outdated
Comment thread src/memcache_socket.rs
Comment thread src/memcache_socket.rs
@bisho bisho force-pushed the 03-10-publish_free-threaded_version branch from 2b057da to 682cb21 Compare March 11, 2026 17:31
@bisho bisho force-pushed the 03-11-socket_in_rust branch 2 times, most recently from 8f3a54c to bf04b6e Compare March 13, 2026 14:59
@bisho bisho force-pushed the 03-10-publish_free-threaded_version branch from 682cb21 to 5b0186d Compare March 13, 2026 14:59
@bisho bisho force-pushed the 03-10-publish_free-threaded_version branch from 5b0186d to bf6ddf8 Compare March 16, 2026 16:09
@bisho bisho force-pushed the 03-11-socket_in_rust branch 2 times, most recently from e6bb63a to 7fc665e Compare March 17, 2026 08:55
This was referenced Mar 17, 2026
Copy link
Copy Markdown
Member Author

bisho commented Mar 24, 2026

Merge activity

  • Mar 24, 4:58 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Mar 24, 5:07 PM UTC: Graphite rebased this pull request as part of a merge.
  • Mar 24, 5:07 PM UTC: @bisho merged this pull request with Graphite.

@bisho bisho changed the base branch from 03-10-publish_free-threaded_version to graphite-base/13 March 24, 2026 17:04
@bisho bisho changed the base branch from graphite-base/13 to main March 24, 2026 17:05
@bisho bisho force-pushed the 03-11-socket_in_rust branch from 7fc665e to 119e70e Compare March 24, 2026 17:06
@bisho bisho merged commit 4dcd677 into main Mar 24, 2026
16 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