-
Notifications
You must be signed in to change notification settings - Fork 75
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
[ETCM-266]-replaced-rate-limiter-built-on-twitter #873
Conversation
2dd8457
to
cf27856
Compare
src/main/scala/io/iohk/ethereum/jsonrpc/server/http/RateLimit.scala
Outdated
Show resolved
Hide resolved
src/main/scala/io/iohk/ethereum/jsonrpc/server/http/RateLimit.scala
Outdated
Show resolved
Hide resolved
src/test/scala/io/iohk/ethereum/jsonrpc/server/http/JsonRpcHttpServerSpec.scala
Outdated
Show resolved
Hide resolved
src/main/scala/io/iohk/ethereum/jsonrpc/server/http/RateLimit.scala
Outdated
Show resolved
Hide resolved
src/main/scala/io/iohk/ethereum/jsonrpc/server/http/JsonRpcHttpServer.scala
Show resolved
Hide resolved
src/test/scala/io/iohk/ethereum/jsonrpc/server/http/JsonRpcHttpServerSpec.scala
Show resolved
Hide resolved
} | ||
) | ||
if (exists) { | ||
val err = JsonRpcError.RateLimitError(minInterval) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
src/main/scala/io/iohk/ethereum/jsonrpc/server/http/JsonRpcHttpServer.scala
Show resolved
Hide resolved
extractClientIP { ip => | ||
if (isBelowRateLimit(ip)) { | ||
val err = JsonRpcError.RateLimitError(minInterval) | ||
complete((StatusCodes.TooManyRequests, err)) |
There was a problem hiding this comment.
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)))
There was a problem hiding this comment.
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 Tuple
s. WDYT?
Just a minor comment, Maybe you can create the task mentioned. So then we can continue working with improvements. |
Description
Twitter-collections used for
LRU
cache for Scala 2.13 is unavailable.Had to replace this
LRU
by something with similar functionalityProposed Solution
The simplest possible
LRU
is built onLinkedHashMap
Boilerplate code is replaced by
Directive0
implementationFurther improvement steps offered for JsonRPC server