Skip to main content

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 a window_sec window
  • when there is multiple typegates (N), you can improve performance by avoiding score synchronizing while the typegate has not reached local_excess: the real maximum score is thus window_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,
);
},
);
Variables
Headers

Playing with the above should allow you to quickly hit the limits.

Feedback