Rate limiting
The rate limiting algorithm works as follows:
- each function type can either count the # of calls it gets or the # of results returned
rate_calls=False
- each function type can have a weight
rate_weight=1
- each request is identified by its IP or by one value of its context if set
context_identifier
- a single query can score a maximum of
query_limit
- multiple queries can sum up to
window_limit
in awindow_sec
window - when there is multiple typegates (
N
), you can improve performance by avoiding score synchronizing while the typegate has not reachedlocal_excess
: the real maximum score is thuswindow_limit + min(local_excess, query_limit) * N
rate.ts ↗
typegraph(
{
name: "rate",
rate: {
windowLimit: 35,
windowSec: 15,
queryLimit: 25,
contextIdentifier: undefined,
localExcess: 0,
},
},
(g) => {
const random = new RandomRuntime({ seed: 0 });
const pub = Policy.public();
g.expose(
{
lightweight_call: random
.gen(t.string())
.rate({ calls: true, weight: 1 }),
medium_call: random.gen(t.string()).rate({ calls: true, weight: 5 }),
heavy_call: random.gen(t.string()).rate({ calls: true, weight: 15 }),
by_result_count: random
.gen(t.list(t.string()))
.rate({ calls: false, weight: 2 }), // increment by # of results returned
},
pub,
);
},
);
xxxxxxxxxx
query A {
lightweight_call
}
query B {
medium_call
}
query C {
heavy_call
}
query D {
by_result_count
}
Variables
Headers
x
Playing with the above should allow you to quickly hit the limits.