A high performance asynchronous Python client for Memcached with full batteries included
Project description
A high performance asynchronous Python client for Memcached with almost full batteries included
Emcache stands on the giant’s shoulders and implements most of the characteristics that are desired for a Memcached client based on the experience of other Memcached clients, providing the following main characteristics:
Support for many Memcached hosts, distributing traffic around them by using the Rendezvous hashing algorithm.
Support for different commands and different flag behaviors like noreply, exptime or flags.
Adaptative connection pool, which increases the number of connections per Memcache host depending on the traffic.
Speed, Emcache is fast. See the benchmark section.
Emcache is still on beta and has not bet yet tested in production but early feedback is wanted from the community to make it ready for production.
Full batteries must be finally provided in the following releases, the following characteristics will be added:
Support for other commands, like touch, delete, etc.
A public interface for managing the nodes of the cluster, allowing, for example, the addition or deletion of Memcached nodes at run time.
Node healthiness support which would allow, optionable, removing nodes that are not responding.
Cluster and node observability for retrieving stats or listening for significant events.
Usage
For installing
pip install emcache
The following snippet shows the minimal stuff that would be needed for creating a new client and saving a new key and retrieving later the value.
import asyncio
import emcache
async def main():
client = await emcache.create_client([emcache.MemcachedHostAddress('localhost', 11211)])
await client.set(b'key', b'value')
item = await client.get(b'key')
print(item.value)
asyncio.run(main())
Emcache has currently support for the following commands:
get Used for retrieving a specific key.
gets Cas version that returns also the case token of a specific key.
get_many Many keys get version.
gets_many Many keys + case token gets version.
set Set a new key and value
add Add a new key and value, if and only if it does not exist.
replace Update a value of a key, if an only if the key does exist.
append Append a value to the current one for a specific key, if and only if the key does exist.
prepend Prepend a value to the current one for a specific key, if and only if the key does exist.
cas Update a value for a key if and only if token as provided matches with the ones stored in the Memcached server.
Some of the commands have support for the following behavior flags:
noreply for storage commands like set we do not wait for an explicit response from the Memcached server. Sacrifice the explicit ack from the Memcached server for speed.
flags for storage we can save an int16 value that can be retrieved later on by fetch commands.
exptime for storage commands this provides a way of configuring an expiration time, once that time is reached keys will be automatically evicted by the Memcached server
For more information about usage, read the docs.
Benchmarks
The following table shows how fast - operations per second - Emcache can be compared to the other two Memcached Python clients, aiomcache and pymemcache. For that specific benchmark two nodes were used, one for the client and one for the Memcached server, using 32 TCP connections and using 32 concurrent Asyncio tasks - threads for the use case of Pymemcache. For Emcache and Aiomcache uvloop was used as a default loop.
In the first part of the benchmark, the client tried to run as mucha set operations it could, and in a second step the same was done but using get operations.
Client |
Concurrency |
Sets opS/sec |
Sets latency AVG |
Gets opS/sec |
Gets latency AVG |
---|---|---|---|---|---|
aiomcache |
32 |
33872 |
0.00094 |
34183 |
0.00093 |
pymemcache |
32 |
32792 |
0.00097 |
32961 |
0.00096 |
emcache |
32 |
49410 |
0.00064 |
49212 |
0.00064 |
Emcache performed better than the other two implementations reaching almost 50K ops/sec for get and set operations.
Another benchmark was performed for comparing how each implementation will behave in case of having to deal with more than 1 node, a new benchmark was performed with different cluster sizes but using the same methodology as the previous test by first, performing as many set operations it could and later as many get operations it could. For this specific use test with Aiomemcahce could not be used since it does not support multiple nodes.
Client |
Concurrency |
Memcahed Nodes |
Sets opS/sec |
Sets latency AVG |
Gets opS/sec |
Gets latency AVG |
---|---|---|---|---|---|---|
pymemcache |
32 |
2 |
21260 |
0.00150 |
21583 |
0.00148 |
emcache |
32 |
2 |
42245 |
0.00075 |
48079 |
0.00066 |
pymemcache |
32 |
4 |
15334 |
0.00208 |
15458 |
0.00207 |
emcache |
32 |
4 |
39786 |
0.00080 |
47603 |
0.00067 |
pymemcache |
32 |
8 |
9903 |
0.00323 |
9970 |
0.00322 |
emcache |
32 |
8 |
42167 |
0.00075 |
46472 |
0.00068 |
The addition of new nodes did not add almost degradation for Emcache, in the last test with 8 nodes Emcache reached 42K get ops/sec and 46K set ops/sec. On the other hand, Pymemcached suffered substantial degradation making Emcache ~x5 times. faster.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for emcache-0.1.0b0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0462c8f1c40bc713a1767593be31cef1aec0c34293f9ccea46ce79f71b9903e3 |
|
MD5 | 2750d46a2daeeb2e6ab1d44baf587c48 |
|
BLAKE2b-256 | f2a612c8de4429d85e7d2acd93ca2f3c1ab03c982273d60df83d93768ac55bdc |
Hashes for emcache-0.1.0b0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f2fac31686f8563c1c6f97316e5c93ca30751fb07185b805c781bb42c4a57bf |
|
MD5 | 5c8039193c2a380857ba65301f5a1206 |
|
BLAKE2b-256 | b20a90f29678ff504bbcf1fa2a7cb7a6fa3ec410459b9cab0d476231b8855f0d |
Hashes for emcache-0.1.0b0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16c45671b758a763ca03ce32308151cf11eeb377db0a85028f2bd5e10eb410ff |
|
MD5 | e29e297eaaa0442f539293263ddba3de |
|
BLAKE2b-256 | f41ab2526e66a1a90a0b95f5ffe1a2040132dbed1993fde60020266eaedc9a46 |
Hashes for emcache-0.1.0b0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20a317aa7a284449205a8f27e021659280e0c651101a4c49ed086de0342f1072 |
|
MD5 | f9e142025ddf7657e9161a3a130cf18e |
|
BLAKE2b-256 | 1b83f794d160c35aa5399354c61e197854b65d1f519a8c0c7ad2c1ab1ac8e33b |