Closed bgins closed 2 weeks ago
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)
Yeah, great idea! Adapted it into a test here: https://github.com/Lilypad-Tech/lilypad/pull/419/commits/0e8a7f3e3d0d98e04a2faf01044c6801838c8b4a
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.