///|
fn main {
let high_cardinality = @quota.QuotaEngine::new()
ignore(
high_cardinality.add_limit(@quota.LimitSpec::per_second("requests", 10)),
)
for i = 0; i < 1000; i = i + 1 {
let key = @quota.QuotaKey::new("tenant", "user-\{i}", "search")
ignore(high_cardinality.check_token_bucket(key, "requests", 0L, 1))
}
let hot_key = @quota.QuotaKey::new("tenant", "hot", "search")
let hot = @quota.QuotaEngine::new()
ignore(
hot.add_limit(@quota.LimitSpec::new("hot", 10000, 10000, 1000L, 10000)),
)
for i = 0; i < 10000; i = i + 1 {
ignore(hot.check_token_bucket(hot_key, "hot", 0L, 1))
}
let transaction_engine = @quota.QuotaEngine::new()
ignore(
transaction_engine.add_limit(
@quota.LimitSpec::new("dimension", 3000, 3000, 1000L, 3000),
),
)
let user = @quota.QuotaKey::new("tenant", "alice", "request")
let tenant = @quota.QuotaKey::new("tenant", "all", "request")
let model = @quota.QuotaKey::new("model", "shared", "request")
let mut committed = 0
for i = 0; i < 1000; i = i + 1 {
let report = transaction_engine.check_atomic_token_buckets(
[
@quota.QuotaCharge::new(user, "dimension", 1),
@quota.QuotaCharge::new(tenant, "dimension", 1),
@quota.QuotaCharge::new(model, "dimension", 1),
],
0L,
)
if report.committed {
committed = committed + 1
}
}
println(
"high_cardinality_checks=1000 buckets=\{high_cardinality.bucket_count()}",
)
println("hot_key_checks=10000 buckets=\{hot.bucket_count()}")
println(
"atomic_transactions=1000 charges=3000 committed=\{committed} buckets=\{transaction_engine.bucket_count()}",
)
}