Skip to content

Commit

Permalink
Ratelimit build improvements
Browse files Browse the repository at this point in the history
Summary: Updated readme port/samples. Include a `docker-build` script in cpp-build which builds the final docker image.

Test Plan: Built a new ratelimit image

Reviewers: pete, yunjing

Reviewed By: yunjing

Differential Revision: https://phabricator-svc.smyte.com/D2813
  • Loading branch information
qix committed Oct 10, 2016
1 parent c4d994d commit 97529e3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y openssl

COPY ./ratelimit /smyte/ratelimit
RUN chmod a+x /smyte/ratelimit
COPY ./ratelimit /ratelimit/ratelimit
RUN chmod a+x /ratelimit/ratelimit

VOLUME /data
EXPOSE 9049

EXPOSE 9008
CMD ["/smyte/ratelimit", "--rocksdb_db_path", "/data/ratelimit", "--port", "9008", "--rocksdb_create_if_missing_one_off", "--version_timestamp_ms", "2461796973728"]
CMD ["/ratelimit/ratelimit", "--rocksdb_db_path", "/data/ratelimit", "--port", "9049", "--rocksdb_create_if_missing"]
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ A high-performance rate limiter written in C++ that speaks Redis protocol.

## Running it

The binary lives at `./bazel-bin/ratelimit/ratelimit`. It takes a few options:
* `--port`: the TCP port to listen on
Once compiled (as above), the binary lives at `./bazel-bin/ratelimit/ratelimit`.

It takes a few options:
* `--port`: the TCP port to listen on (default 9049)
* `--rocksdb_db_path`: path where ratelimit should persist its state
* `--rocksdb_create_if_missing_one_off`: pass this flag to create the database if it does not exist
* `--version_timestamp_ms`: this timestamp is stored in the DB when it is created. If this timestamp is older than the one in the DB it will refuse to start. This timestamp must be some time in the future.
* `--rocksdb_create_if_missing`: pass this flag to create the database if it does not exist

Example: `./bazel-bin/ratelimit/ratelimit --rocksdb_db_path ratelimit-data --rocksdb_create_if_missing`

You can also run it inside docker: `docker run -p 9049:9049 smyte/ratelimit`

## Supported commands
* `RL.REDUCE key max refilltime [REFILL refillamount] [TAKE tokens] [AT timestamp]`: create a bucket identified by `key` if it does not exist that can hold up to `max` tokens and return the number of tokens remaining. Every `refilltime` seconds `refillamount` tokens will be added to the bucket up to `max`. If `refillamount` is not provided it defaults to `max`. If there are at least `tokens` remaining in the bucket it will return true and reduce the amount by `tokens`. If `tokens` is not provided it defaults to `1`. If you want to provide your own current timestamp for refills rather than use the server's clock you can pass a `timestamp`.
Expand All @@ -25,14 +30,14 @@ The binary lives at `./bazel-bin/ratelimit/ratelimit`. It takes a few options:

### Example

Start the server:
```
./bazel-bin/ratelimit/ratelimit --port 9008 --rocksdb_db_path /data/ratelimit --rocksdb_create_if_missing_one_off --version_timestamp_ms 2461796973728
```
Start the compiled server (see [Running It](#running-it))

Send it some traffic:
```
redis-cli -p 9008 'RL.REDUCE foo 2 10'
redis-cli -p 9008 'RL.REDUCE foo 2 10'
redis-cli -p 9008 'RL.REDUCE foo 2 10'
$ redis-cli -p 9049 RL.REDUCE twoPerMin 2 60
(integer) 2
$ redis-cli -p 9049 RL.REDUCE twoPerMin 2 60
(integer) 1
$ redis-cli -p 9049 RL.REDUCE twoPerMin 2 60
(integer) 0
```
19 changes: 0 additions & 19 deletions build_docker.py

This file was deleted.

0 comments on commit 97529e3

Please sign in to comment.