Simulators
Rate limits
Test how your code copes when Modal refuses a call for speed. Modal’s parametrized function creation allows a burst of 1,000 calls and refills at 1 a second. With rate_limits: real on, a call past that allowance returns the gRPC status RESOURCE_EXHAUSTED, code 8.
The calls below name a function that does not exist. Each call the limit lets through returns NOT_FOUND (code 5) and each one it refuses returns code 8, since the limit counts a call before the function is looked up.
Send 1,010 calls with the setting off, then turn it on and send 10. Reset and send 1,100, wait 2 seconds and send one. Then reset again and send 1,000:
printf '\0\0\0\0\011\012\007fu-none' > call.bin
BIND="$RYSTIC_URL/modal.client.ModalClient/FunctionBindParams"
curl -s --http2-prior-knowledge -H 'Content-Type: application/grpc' -H 'TE: trailers' --data-binary @call.bin -D - $(for i in $(seq 1010); do echo "-o /dev/null $BIND"; done) | tr -d '\r' | grep '^grpc-status:' | sort -u
# -> grpc-status: 5
curl -s -X POST "$RYSTIC_URL/_rystic/network" -o /dev/null -w '%{http_code}\n' -d '{"rate_limits": "real"}'
# -> 204
curl -s --http2-prior-knowledge -H 'Content-Type: application/grpc' -H 'TE: trailers' --data-binary @call.bin -D - $(for i in $(seq 10); do echo "-o /dev/null $BIND"; done) | tr -d '\r' | grep -m1 '^grpc-status: 8'
# -> grpc-status: 8
curl -s -X POST "$RYSTIC_URL/_rystic/reset" -o /dev/null -w '%{http_code}\n'
# -> 204
curl -s "$RYSTIC_URL/_rystic/network" | jq -r .rate_limits
# -> real
curl -s --http2-prior-knowledge -H 'Content-Type: application/grpc' -H 'TE: trailers' --data-binary @call.bin -D - $(for i in $(seq 1100); do echo "-o /dev/null $BIND"; done) | tr -d '\r' | grep -E '^grpc-(status|message):' | sort -u
# -> grpc-message: No Function with ID 'fu-none' found
# -> grpc-message: Parametrized function creation rate limit exceeded. Please wait and retry.
# -> grpc-status: 5
# -> grpc-status: 8
sleep 2
curl -s --http2-prior-knowledge -H 'Content-Type: application/grpc' -H 'TE: trailers' --data-binary @call.bin -o /dev/null -D - "$BIND" | tr -d '\r' | grep '^grpc-status:'
# -> grpc-status: 5
curl -s -X POST "$RYSTIC_URL/_rystic/reset" -o /dev/null -w '%{http_code}\n'
# -> 204
curl -s --http2-prior-knowledge -H 'Content-Type: application/grpc' -H 'TE: trailers' --data-binary @call.bin -D - $(for i in $(seq 1000); do echo "-o /dev/null $BIND"; done) | tr -d '\r' | grep '^grpc-status:' | sort -u
# -> grpc-status: 5
curl -s -X POST "$RYSTIC_URL/_rystic/network" -o /dev/null -w '%{http_code}\n' -d '{"rate_limits": "off"}'
# -> 204
With the setting off, none of the 1,010 calls is refused, but they still spend the allowance, so a call in the burst right after turning the setting on is refused. A reset leaves rate_limits set to real and fills the allowance again. The burst of 1,100 then spends it and the calls past it are refused, while the 2-second wait refills enough for one more. A refusal’s message names the limit it hit. After the second reset a burst of 1,000 is not refused.