-
Notifications
You must be signed in to change notification settings - Fork 74
Home
PAN, Myautsai edited this page Feb 2, 2016
·
11 revisions
libmc is a fast and lightweight memcached client library for C++/Python/Golang without any other dependencies in runtime. The internal part is written in C++, and the Python wrapper and Golang wrapper are written mainly in Cython and cgo.
The python version of libmc can be considered as a drop in replacement for libmemcached and python-libmemcached.
Update: Golang version of libmc is now in beta, checkout golibmc.
- Server aliases support
- Memory efficient
- TCP I/O multiplexing
- Lazy-connecting
Internal classes:
Client
| (1:1)
ConnectionPool
| (1:N)
Connection
/ | (1:1) \
BufferReader Parser BufferWriter
| (1:N)
DataBlock
- Client: top-level API for libmc
-
ConnectionPool:
- dispatching different keys to different connections according to key route(Consistent hashing)
- multiplexing on top of TCP connections
- collecting and merging results from TCP connections
-
Connection: wrapper for TCP connection to each memcached server.
Each
Connection
has oneParser
, oneBufferReader
, and oneBufferWriter
. - BufferReader: buffer helper for receving buffer from memcached server
- BufferWritter: buffer helper for sending buffer to memcached server
- DataBlock: wrapper for each continuous memory space
Dynamic memory allocation and memory-copy are slow, so we tried our best to avoid them.
- Pre-allocation in BufferReader
- Use sendmsg instead of send
- Use itoa from rapidjson
- SmallVector for collecting results
We value security.
Slide: Reinventing the wheel: libmc