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

[ETCM-266]-replaced-rate-limiter-built-on-twitter #873

Merged
merged 15 commits into from
Jan 1, 2021

Conversation

dmitry-worker
Copy link
Contributor

@dmitry-worker dmitry-worker commented Dec 23, 2020

Description

Twitter-collections used for LRU cache for Scala 2.13 is unavailable.
Had to replace this LRU by something with similar functionality

Proposed Solution

The simplest possible LRU is built on LinkedHashMap
Boilerplate code is replaced by Directive0 implementation
Further improvement steps offered for JsonRPC server

@dmitry-worker dmitry-worker force-pushed the feature/ETCM-266-no-twitter-util-collection branch from 2dd8457 to cf27856 Compare December 23, 2020 14:54
}
)
if (exists) {
val err = JsonRpcError.RateLimitError(minInterval)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we separate LRU cache from RateLimit'ing?

I believe there are some rate-limiting capabilities built-in cats or Akka maybe we could use sth that is already build in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I can get the idea of separating.
Do you mean an ability to plug an opt-in rate limiting engine?

extractClientIP { ip =>
if (isBelowRateLimit(ip)) {
val err = JsonRpcError.RateLimitError(minInterval)
complete((StatusCodes.TooManyRequests, err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a minor comment, we can reduce this line:
complete((StatusCodes.TooManyRequests, JsonRpcError.RateLimitError(minInterval)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it was inline in the beginning, but I've decided that the code is quite unreadable :)
IMHO this will not affect performance and the compiler will inline it anyway because it is used once, immediately after creation. Maybe it would be better to construct a kind of builder for responses instead of serializable Tuples. WDYT?

@biandratti
Copy link
Contributor

Just a minor comment, Maybe you can create the task mentioned. So then we can continue working with improvements.
Good job!

@dmitry-worker dmitry-worker merged commit 84a2f9b into develop Jan 1, 2021
@dzajkowski dzajkowski deleted the feature/ETCM-266-no-twitter-util-collection branch April 9, 2021 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants