mirror of
https://github.com/mCaptcha/cache.git
synced 2024-11-22 00:25:20 +03:00
benchmark script
This commit is contained in:
parent
8300ad82ed
commit
2b9144f560
6 changed files with 96 additions and 54 deletions
84
Makefile
84
Makefile
|
@ -5,59 +5,65 @@ DOCKER_CONTAINER = "mcaptcha_cache_test"
|
||||||
default:
|
default:
|
||||||
cargo build --release
|
cargo build --release
|
||||||
|
|
||||||
test:
|
bench:
|
||||||
cargo test --all --all-features --no-fail-fast
|
./scripts/bench.sh
|
||||||
./tests/test.py
|
|
||||||
|
|
||||||
docker-build:
|
clean:
|
||||||
docker build -t $(DOCKER_IMG) .
|
cargo clean
|
||||||
|
|
||||||
docker-stop:
|
|
||||||
docker stop $(DOCKER_CONTAINER) || true
|
|
||||||
docker rm $(DOCKER_CONTAINER)
|
|
||||||
|
|
||||||
docker-run:
|
|
||||||
docker run --detach --name=$(DOCKER_CONTAINER) \
|
|
||||||
--publish 6379:6379 \
|
|
||||||
$(DOCKER_IMG)
|
|
||||||
|
|
||||||
run-redis-server:
|
|
||||||
redis-server --loadmodule ./target/release/libcache.so &
|
|
||||||
|
|
||||||
stop-redis-server:
|
|
||||||
killall redis-server
|
|
||||||
|
|
||||||
dev-env:
|
|
||||||
./scripts/setup.sh
|
|
||||||
|
|
||||||
docker:
|
|
||||||
docker build -t mcaptcha/cache:0.1.0-beta -t mcaptcha/cache:latest .
|
|
||||||
docker push mcaptcha/cache:0.1.0-beta
|
|
||||||
docker push mcaptcha/cache:latest
|
|
||||||
|
|
||||||
xml-test-coverage:
|
|
||||||
cargo tarpaulin -t 1200 --out Xml --all --all-features --no-fail-fast
|
|
||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
cargo tarpaulin -t 1200 --out Html --all --all-features --no-fail-fast
|
cargo tarpaulin -t 1200 --out Html --all --all-features --no-fail-fast
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
cargo build
|
cargo build
|
||||||
|
|
||||||
doc:
|
doc:
|
||||||
cargo doc --no-deps --workspace --all-features --document-private-items
|
cargo doc --no-deps --workspace --all-features --document-private-items
|
||||||
|
|
||||||
clean:
|
docker:
|
||||||
cargo clean
|
docker build -t mcaptcha/cache:0.1.0-beta -t mcaptcha/cache:latest .
|
||||||
|
docker push mcaptcha/cache:0.1.0-beta
|
||||||
|
docker push mcaptcha/cache:latest
|
||||||
|
|
||||||
|
docker-build:
|
||||||
|
docker build -t $(DOCKER_IMG) .
|
||||||
|
|
||||||
|
docker-run:
|
||||||
|
docker run --detach --name=$(DOCKER_CONTAINER) \
|
||||||
|
--publish 6379:6379 \
|
||||||
|
$(DOCKER_IMG)
|
||||||
|
|
||||||
|
docker-stop:
|
||||||
|
docker stop $(DOCKER_CONTAINER) || true
|
||||||
|
docker rm $(DOCKER_CONTAINER)
|
||||||
|
env:
|
||||||
|
./scripts/setup.sh
|
||||||
|
|
||||||
|
test:
|
||||||
|
cargo test --all --all-features --no-fail-fast
|
||||||
|
./tests/test.py
|
||||||
|
|
||||||
|
xml-test-coverage:
|
||||||
|
cargo tarpaulin -t 1200 --out Xml --all --all-features --no-fail-fast
|
||||||
|
|
||||||
|
run-redis:
|
||||||
|
redis-server --loadmodule ./target/release/libcache.so &
|
||||||
|
|
||||||
|
stop-redis:
|
||||||
|
killall redis-server
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@echo ' run - run developer instance'
|
|
||||||
@echo ' test - run unit and integration tests'
|
@echo ' bench - run benchmarks'
|
||||||
|
@echo ' clean - drop builds and environments'
|
||||||
|
@echo ' coverage - build test coverage in HTML format'
|
||||||
|
@echo ' doc - build documentation'
|
||||||
@echo ' docker-build - build docker image'
|
@echo ' docker-build - build docker image'
|
||||||
@echo ' docker-run - run docker container'
|
@echo ' docker-run - run docker container'
|
||||||
@echo ' docker-stop - stop docker container'
|
@echo ' docker-stop - stop docker container'
|
||||||
@echo ' dev-env - setup dev env'
|
@echo ' env - setup dev env'
|
||||||
@echo ' doc - build documentation'
|
@echo ' run-redis - load and run redis on local machine'
|
||||||
@echo ' clean - drop builds and environments'
|
@echo ' stop-redis - kill local redis instance'
|
||||||
@echo ' coverage - build test coverage in HTML format'
|
@echo ' test - run unit and integration tests'
|
||||||
@echo ' xml-coverage - build test coverage in XML for upload to codecov'
|
@echo ' xml-coverage - build test coverage in XML for upload to codecov'
|
||||||
@echo ''
|
@echo ''
|
||||||
|
|
19
README.md
19
README.md
|
@ -166,25 +166,28 @@ better suited to your workload.
|
||||||
To run benchmarks locally, launch Redis server with module loaded and:
|
To run benchmarks locally, launch Redis server with module loaded and:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ ./scripts/bench.sh
|
$ make bench
|
||||||
```
|
```
|
||||||
|
|
||||||
- platform: `Intel core i7-9750h`
|
- platform: `Intel core i7-9750h`
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
➜ cache git:(master) ✗ make bench
|
||||||
|
./scripts/bench.sh
|
||||||
running set and get without pipelining
|
running set and get without pipelining
|
||||||
SET: 125046.89 requests per second, p50=0.199 msec
|
SET: 128600.82 requests per second, p50=0.191 msec
|
||||||
GET: 124502.00 requests per second, p50=0.199 msec
|
GET: 128617.36 requests per second, p50=0.191 msec
|
||||||
|
|
||||||
mCaptcha cache without piplining
|
mCaptcha cache without piplining
|
||||||
MCAPTCHA_CACHE.COUNT mycounter 45: 124828.37 requests per second, p50=0.215 msec
|
MCAPTCHA_CACHE.ADD_VISITOR mycounter: 127811.86 requests per second, p50=0.207 msec
|
||||||
|
MCAPTCHA_CACHE.GET mycounter: 123243.77 requests per second, p50=0.199 msec
|
||||||
running set and get with pipelining
|
running set and get with pipelining
|
||||||
SET: 1353179.88 requests per second, p50=0.487 msec
|
SET: 1416430.62 requests per second, p50=0.479 msec
|
||||||
GET: 1633987.00 requests per second, p50=0.383 msec
|
GET: 1644736.88 requests per second, p50=0.391 msec
|
||||||
|
|
||||||
mCaptcha cache with piplining
|
mCaptcha cache with piplining
|
||||||
MCAPTCHA_CACHE.COUNT mycounter 45: 385653.69 requests per second, p50=1.959 msec
|
MCAPTCHA_CACHE.ADD_VISITOR mycounter: 396039.59 requests per second, p50=1.903 msec
|
||||||
|
MCAPTCHA_CACHE.GET mycounter: 889679.75 requests per second, p50=0.791 msec
|
||||||
```
|
```
|
||||||
|
|
||||||
## Hacks
|
## Hacks
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
readonly NUM_REQUESTS=1000000
|
readonly NUM_REQUESTS=1000000
|
||||||
|
|
||||||
|
readonly CAPTCHA_NAME=mycounter
|
||||||
|
readonly DURATION=45
|
||||||
|
|
||||||
|
scripts/setupbench.py $CAPTCHA_NAME $DURATION
|
||||||
|
|
||||||
echo "running set and get without pipelining"
|
echo "running set and get without pipelining"
|
||||||
redis-benchmark -n 1000000 -t set,get -q
|
redis-benchmark -n 1000000 -t set,get -q
|
||||||
|
|
||||||
echo "mCaptcha cache without piplining"
|
echo "mCaptcha cache without piplining"
|
||||||
redis-benchmark -n $NUM_REQUESTS -q MCAPTCHA_CACHE.COUNT mycounter 45
|
redis-benchmark -n $NUM_REQUESTS -q MCAPTCHA_CACHE.ADD_VISITOR $CAPTCHA_NAME
|
||||||
|
redis-benchmark -n $NUM_REQUESTS -q MCAPTCHA_CACHE.GET $CAPTCHA_NAME
|
||||||
|
|
||||||
echo "running set and get with pipelining"
|
echo "running set and get with pipelining"
|
||||||
redis-benchmark -n 1000000 -t set,get -q -P 16
|
redis-benchmark -n 1000000 -t set,get -q -P 16
|
||||||
|
|
||||||
echo "mCaptcha cache with piplining"
|
echo "mCaptcha cache with piplining"
|
||||||
redis-benchmark -P 16 -n $NUM_REQUESTS -q MCAPTCHA_CACHE.COUNT mycounter 45
|
redis-benchmark -P 16 -n $NUM_REQUESTS -q MCAPTCHA_CACHE.ADD_VISITOR $CAPTCHA_NAME
|
||||||
|
redis-benchmark -P 16 -n $NUM_REQUESTS -q MCAPTCHA_CACHE.GET $CAPTCHA_NAME
|
||||||
|
|
26
scripts/setupbench.py
Executable file
26
scripts/setupbench.py
Executable file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/env /usr/bin/python3
|
||||||
|
#
|
||||||
|
# Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
import sys
|
||||||
|
import pathlib
|
||||||
|
|
||||||
|
sys.path.append("tests/")
|
||||||
|
|
||||||
|
import mcaptcha
|
||||||
|
|
||||||
|
captcha_name = sys.argv[1]
|
||||||
|
duration = sys.argv[2]
|
||||||
|
mcaptcha.register(captcha_name, duration)
|
|
@ -24,8 +24,8 @@ r = utils.connect()
|
||||||
utils.ping(r)
|
utils.ping(r)
|
||||||
|
|
||||||
COMMANDS = {
|
COMMANDS = {
|
||||||
"COUNT" : "mcaptcha_cache.add_visitor",
|
"COUNT" : "MCAPTCHA_CACHE.ADD_VISITOR",
|
||||||
"GET" : "mcaptcha_cache.get",
|
"GET" : "MCAPTCHA_CACHE.GET",
|
||||||
}
|
}
|
||||||
|
|
||||||
def incr(key):
|
def incr(key):
|
||||||
|
|
|
@ -42,7 +42,7 @@ def delete_captcha(key):
|
||||||
r.execute_command(COMMANDS["DELETE_CAPTCHA"], key)
|
r.execute_command(COMMANDS["DELETE_CAPTCHA"], key)
|
||||||
|
|
||||||
|
|
||||||
def add_captcha(key):
|
def add_captcha(key, duration=5):
|
||||||
r.execute_command(COMMANDS["ADD_CAPTCHA"], key, payload)
|
r.execute_command(COMMANDS["ADD_CAPTCHA"], key, payload)
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,11 +54,11 @@ def captcha_exists(key):
|
||||||
if exists == 1:
|
if exists == 1:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def register(key):
|
def register(key, duration=5):
|
||||||
if captcha_exists(key):
|
if captcha_exists(key):
|
||||||
delete_captcha(key)
|
delete_captcha(key)
|
||||||
|
|
||||||
add_captcha(key)
|
add_captcha(key, duration=5)
|
||||||
|
|
||||||
async def captcha_exists_works():
|
async def captcha_exists_works():
|
||||||
key = "captcha_delete_works"
|
key = "captcha_delete_works"
|
||||||
|
|
Loading…
Reference in a new issue