Skip to content

Commit a0f1bb3

Browse files
committed
Build cmd in rust
## Motivation / Description The second cpu-intensive part of the request processing is building the cmd. Also instead of building dicts of flags we can use a single flags object, which also simplifies the API of the lower commands. I chose to still built a single flags object, but we could explore building one flags object per meta-command, as the flags that they support differ, and it could lead to a more type-safe low-level implementation. ## Performance: * Initial: multithreaded: Overall: 110779.55 RPS / 9.03 us/req singlethreaded: Overall: 111545.63 RPS / 8.96 us/req * Rust only for response parsing multithreaded: Overall: 245898.34 RPS / 4.07 us/req singlethreaded: Overall: 246165.19 RPS / 4.06 us/req * Now (rust also for build_cmd) multithreaded: Overall: 319587.03 RPS / 3.13 us/req singlethreaded: Overall: 323101.77 RPS / 3.10 us/req
1 parent 77e4d37 commit a0f1bb3

25 files changed

+357
-669
lines changed

poetry.lock

+49-51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ packages = [{include = "meta_memcache", from="src"}]
1414
python = "^3.8"
1515
uhashring = "^2.1"
1616
marisa-trie = "^1.0.0"
17-
meta-memcache-socket = "^0.1.0"
17+
meta-memcache-socket = "0.1.1"
1818

1919
[tool.poetry.group.extras.dependencies]
2020
prometheus-client = "^0.17.1"

src/meta_memcache/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,15 @@
3333
)
3434
from meta_memcache.protocol import (
3535
Conflict,
36-
Flag,
37-
IntFlag,
3836
Key,
3937
MetaCommand,
4038
Miss,
4139
NotStored,
4240
ServerVersion,
4341
ResponseFlags,
42+
RequestFlags,
4443
SetMode,
4544
Success,
46-
TokenFlag,
4745
Value,
4846
)
4947
from meta_memcache.routers.default import DefaultRouter

src/meta_memcache/cache_client.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, Iterable, Optional, Tuple
1+
from typing import Callable, Iterable, Optional
22

33
from meta_memcache.base.base_cache_client import BaseCacheClient
44
from meta_memcache.commands.high_level_commands import HighLevelCommandsMixin
@@ -25,7 +25,7 @@ def cache_client_from_servers(
2525
servers: Iterable[ServerAddress],
2626
connection_pool_factory_fn: Callable[[ServerAddress], ConnectionPool],
2727
serializer: Optional[BaseSerializer] = None,
28-
key_encoder_fn: Callable[[Key], Tuple[bytes, bool]] = default_key_encoder,
28+
key_encoder_fn: Callable[[Key], bytes] = default_key_encoder,
2929
raise_on_server_error: bool = True,
3030
) -> CacheApi:
3131
executor = DefaultExecutor(
@@ -48,7 +48,7 @@ def cache_client_with_gutter_from_servers(
4848
gutter_ttl: int,
4949
connection_pool_factory_fn: Callable[[ServerAddress], ConnectionPool],
5050
serializer: Optional[BaseSerializer] = None,
51-
key_encoder_fn: Callable[[Key], Tuple[bytes, bool]] = default_key_encoder,
51+
key_encoder_fn: Callable[[Key], bytes] = default_key_encoder,
5252
raise_on_server_error: bool = True,
5353
) -> CacheApi:
5454
executor = DefaultExecutor(
@@ -76,7 +76,7 @@ def ephemeral_cache_client_from_servers(
7676
max_ttl: int,
7777
connection_pool_factory_fn: Callable[[ServerAddress], ConnectionPool],
7878
serializer: Optional[BaseSerializer] = None,
79-
key_encoder_fn: Callable[[Key], Tuple[bytes, bool]] = default_key_encoder,
79+
key_encoder_fn: Callable[[Key], bytes] = default_key_encoder,
8080
raise_on_server_error: bool = True,
8181
) -> CacheApi:
8282
executor = DefaultExecutor(

0 commit comments

Comments
 (0)