-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: Add solver rate limiter #419
Conversation
@@ -217,7 +217,7 @@ function solver() { | |||
load-local-env | |||
export WEB3_PRIVATE_KEY=${SOLVER_PRIVATE_KEY} | |||
export LOG_LEVEL=debug | |||
go run . solver --network dev | |||
go run . solver --network dev "$@" |
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.
This adds on extra args from the command line. We had it on other services, but it was missing on the solver.
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.
This looks great! nice and clean. Tested locally and it's working.
Would it be possible to make push-limits a test so we can run them on PRs to make sure we don't regress? (if it's a big lift, we can add a task on the backlog)
d00a25e
to
0e8a7f3
Compare
Yeah, great idea! Adapted it into a test here: 0e8a7f3 |
0e8a7f3
to
35e9a8d
Compare
45e2056
to
1556f3f
Compare
* chore: Add extra args to solver command * chore: Add server rate limiter options * feat: Add httprate limiter to solver server * test: Add rate limiter integration test
Summary
This pull request makes the following changes:
httprate
limiter to solver serversolver
commandWe would like to limit the number of requests from an IP address by route.
Task/Issue reference
Closes: #417
Test plan
Start the chain and solver nodes. The other parts of stack will not be needed for testing.
Copy this script into a
push-limits.go
file:This script runs 10 requests across our get resource offer, job offer, and deals endpoints. The
makeCalls
for each endpoint are staggered so they can be viewed independently in the output.Run the script with
go run push-limits.go
.The expected output is successful calls to get resource offers at first:
We default to five requests allowed over 10 seconds. Once an endpoint has reached it's limit, it should report 429s:
The outputs for the job offer and deals endpoints will be interleaved, but should demonstrate that the rate limit is per endpoint and not global.
Test the rate limiting configuration by starting the solver with CLI options or environment variables:
Run the
push-limits.go
script again and the limits should be enforced much sooner.Details
We considered rate limiting by wallet address, but have decided to use IP address for a first pass. Some endpoints do not require our
X-Lilypad-User
header, so wallet address is not sufficient. We may want to revisit this idea in the future.In addition to httprate, we also considered tollbooth.
tollbooth
is more widely used, buthttprate
has a better algorithm based on work at Cloudflare. Also,httprate
supports Redis for tracking counts over multiple server instances.The
SERVER_RATE_REQUEST_LIMIT
andSERVER_RATE_WINDOW_LENGTH
environment variables have been added to all Doppler solver envinronments with the default values. We can update these values and restart the solver to tune them.