Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch update #285

Merged
merged 19 commits into from
Apr 22, 2024
Merged

Batch update #285

merged 19 commits into from
Apr 22, 2024

Conversation

didierofrivia
Copy link
Member

@didierofrivia didierofrivia commented Mar 28, 2024

This PR replaces the way Limitador, configured to use Redis Cached storage, updates (flushes the in memory cache) to Redis. Instead of updating counters one by one, Limitador sends the batch of counters to update to Redis.

TODO

  • Batch updating to redis
  • Fix rebase conficts
  • Limit batch update counters to redis (?) for the near future
  • Get back the values from redis...
  • and update cache (?)
  • Test that update counters are being updated in redis
  • Test that the cached counters are updated

Notes

  • In a setup where the Redis instance is (physically) far from the Limitador instance, it could happen that we encounter network partition error when the response timeout is exceeded:

    EC Frankfurt – Limitador Sao Paulo

Executing limitador: $ limitador-server /bench/limits.yaml redis_cached redis://test-limitador-redis.jeigrh.ng.0001.euc1.cache.amazonaws.com:6379
Limitador Server v1.4.0-dev (b7e4d87c) [] release
Executing limitador-driver: $ limitador-driver rpc://127.0.0.1:8081 1m
Hitting Limitador at rpc://127.0.0.1:8081 for a total duration of 1 minutes
Current: hits: 12195, mean: 0.081ms, p50: 0.062ms, p90: 0.073ms, p99: 0.092ms, p999: 0.106ms, max: 201.727ms
Current: hits: 15461, mean: 0.064ms, p50: 0.062ms, p90: 0.074ms, p99: 0.091ms, p999: 0.112ms, max: 0.335ms
Current: hits: 15367, mean: 0.064ms, p50: 0.062ms, p90: 0.074ms, p99: 0.092ms, p999: 0.112ms, max: 0.399ms
2024-04-03T14:58:00.941325Z ERROR limitador::storage::redis::redis_cached: Partition to Redis detected!
Current: hits: 6912, mean: 0.144ms, p50: 0.062ms, p90: 0.074ms, p99: 0.092ms, p999: 0.137ms, max: 352.255ms
Current: hits: 15414, mean: 0.064ms, p50: 0.062ms, p90: 0.074ms, p99: 0.091ms, p999: 0.107ms, max: 0.363ms
2024-04-03T14:58:02.941271Z ERROR limitador::storage::redis::redis_cached: Partition to Redis detected!

@didierofrivia didierofrivia force-pushed the batch_update branch 3 times, most recently from 9d2183b to 6d4622b Compare April 2, 2024 12:45
@alexsnaps alexsnaps force-pushed the resilient_cache branch 4 times, most recently from 7e0e86b to 0ef11c6 Compare April 2, 2024 19:21
@eguzki
Copy link
Contributor

eguzki commented Apr 2, 2024

you should rebase your branch to get some fixes in redis_cached

@didierofrivia didierofrivia force-pushed the batch_update branch 5 times, most recently from c3a0757 to b7e4d87 Compare April 3, 2024 14:36
Base automatically changed from resilient_cache to main April 3, 2024 17:17
@didierofrivia didierofrivia changed the title [WIP] Batch update Batch update Apr 8, 2024
@didierofrivia didierofrivia self-assigned this Apr 8, 2024
@didierofrivia didierofrivia marked this pull request as ready for review April 8, 2024 13:20
@@ -231,6 +233,30 @@ impl AsyncRedisStorage {

Ok(())
}

pub async fn update_counters(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fn could be named differently, a more explicit name would be batch_update_counters... will leave it to the review

@didierofrivia didierofrivia force-pushed the batch_update branch 9 times, most recently from 7d64901 to 7581f14 Compare April 15, 2024 09:38
Copy link
Member

@alexsnaps alexsnaps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me… other that rename of cached_counters into cacher that I don't understand (like I don't understand the binding's name… literally).
Now, I also think the changes to keys.rs of removing the namespace: &str from the method signature are… unfortunate. As fundamentally I think we shouldn't resend the keys back, as we could "just" send the value & ttl for each ordered as we passed them in. This would avoid that change, but mostly would save bandwidth… We can iterate over these changes tho. Again, in the vein of avoiding doing work we can avoid doing.

limitador/src/storage/redis/redis_cached.rs Outdated Show resolved Hide resolved
Copy link
Member

@adam-cattermole adam-cattermole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these changes look good to me, tested it out with the driver and can see the writes in redis

limitador/src/storage/redis/redis_cached.rs Outdated Show resolved Hide resolved
@didierofrivia didierofrivia merged commit 6d40864 into main Apr 22, 2024
20 checks passed
@didierofrivia didierofrivia deleted the batch_update branch April 22, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants