cloudflare / cloudflare/rakelimit

compress countmin state to 64bits

Open
#16 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C
Stars
211
Forks
11
PR merge metrics
No merged PRs in 30d

Description

The value we store in a count-min sketch is currently 128bit:

```
struct cm_value {
fpoint value;
__u64 ts;
};
```

I think we can compress this to 64 bits total: a `__u32` for the estimated rate in pps and a `__u32` for the timestamp. This means the timestamp would wrap every 4.2s but given our current `WINDOW` that isn't a problem. It just needs code to deal with it.

Doing this will halve the memory we need, plus on 64bit arches we can (probably) use a single load and store for `struct cm_value` which reduces the likelihood of observing a race condition.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.