new menches

This commit is contained in:
realaravinth 2021-06-05 14:17:24 +05:30
parent be961398bd
commit 8e7a7dd093
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
5 changed files with 15 additions and 10 deletions

View file

@ -55,7 +55,7 @@ jobs:
uses: actions-rs/tarpaulin@v0.1
with:
version: '0.15.0'
args: '-t 1200'
args: '-t 1200 --all-features'
- name: Upload to Codecov
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/target
*.rdb
tmp/
tarpaulin-report.html

View file

@ -164,18 +164,18 @@ $ ./scripts/bench.sh
```bash
running set and get without pipelining
SET: 86095.57 requests per second, p50=0.311 msec
GET: 87519.70 requests per second, p50=0.311 msec
SET: 125046.89 requests per second, p50=0.199 msec
GET: 124502.00 requests per second, p50=0.199 msec
mCaptcha cache without piplining
MCAPTCHA_CACHE.COUNT mycounter 45: 85375.22 requests per second, p50=0.479 msec
MCAPTCHA_CACHE.COUNT mycounter 45: 124828.37 requests per second, p50=0.215 msec
running set and get with pipelining
SET: 822368.44 requests per second, p50=0.855 msec
GET: 900090.06 requests per second, p50=0.775 msec
SET: 1353179.88 requests per second, p50=0.487 msec
GET: 1633987.00 requests per second, p50=0.383 msec
mCaptcha cache with piplining
MCAPTCHA_CACHE.COUNT mycounter 45: 274876.31 requests per second, p50=2.767 msec
MCAPTCHA_CACHE.COUNT mycounter 45: 385653.69 requests per second, p50=1.959 msec
```
## Hacks

View file

@ -50,7 +50,7 @@ lazy_static! {
rng.gen()
};
/// counter/captcha key prefix
pub static ref PREFIX_COUNTER: String = format!("{}:captcha:", PKG_NAME);
pub static ref PREFIX_COUNTER: String = format!("{}:captcha:{}:", PKG_NAME, *ID);
/// pocket key prefix
pub static ref PREFIX_POCKET: String = format!("{}:pocket:{{{}}}:", PKG_NAME, *ID);
}

View file

@ -68,7 +68,6 @@ impl Pocket {
let pocket_name = pocket_name.unwrap();
let pocket = ctx.open_key_writable(&pocket_name);
Pocket::decrement_runner(ctx, &pocket);
if pocket.key_type() == KeyType::Empty {
ctx.log_debug(&format!("Pocket doesn't exist: {}", &key_name));
return;
@ -78,6 +77,7 @@ impl Pocket {
}
/// creates new pocket and sets off timer to go off at `duration`
#[inline]
pub fn new(ctx: &Context, duration: u64) -> Result<Self, RedisError> {
let decrement = HashMap::with_capacity(1);
@ -97,9 +97,10 @@ impl Pocket {
}
/// increments count of key = captcha and registers for auto decrement
#[inline]
pub fn increment(ctx: &Context, duration: u64, captcha: &str) -> Result<(), RedisError> {
let captcha_name = get_captcha_key(captcha);
ctx.log_warning(&captcha_name);
ctx.log_debug(&captcha_name);
// increment
let captcha = ctx.open_key_writable(&captcha_name);
@ -149,6 +150,7 @@ impl Pocket {
/// decrement runner that decrements all registered counts _without_ cleaning after itself
/// use [decrement] when you require auto cleanup. Internally, it calls this method.
#[inline]
fn decrement_runner(ctx: &Context, key: &RedisKeyWritable) {
let val = key.get_value::<Pocket>(&MCAPTCHA_POCKET_TYPE).unwrap();
match val {
@ -205,12 +207,14 @@ impl Pocket {
}
}
#[inline]
pub fn parse_str(data: &str, format: Format) -> Result<Pocket, CacheError> {
match format {
Format::JSON => Ok(serde_json::from_str(data)?),
}
}
#[inline]
pub fn from_str(data: &str, format: Format) -> Result<Self, CacheError> {
Ok(Pocket::parse_str(data, format)?)
}