MCPcopy Create free account
hub / github.com/avoidwork/tenso / benchmarkHighConcurrency

Function benchmarkHighConcurrency

benchmarks/rate-limiting.js:270–317  ·  view source on GitHub ↗

* Benchmarks rate limiting with high concurrency

()

Source from the content-addressed store, hash-verified

268 * Benchmarks rate limiting with high concurrency
269 */
270function benchmarkHighConcurrency () {
271 console.log("\n📊 Rate Limiting High Concurrency");
272 console.log("-".repeat(40));
273
274 const suite = new Benchmark.Suite();
275 const rateStore = new Map();
276
277 const concurrentRateCheck = clientCount => {
278 const currentTime = Math.floor(Date.now() / 1000);
279
280 for (let i = 0; i < clientCount; i++) {
281 const clientId = `client-${i}`;
282
283 if (!rateStore.has(clientId)) {
284 rateStore.set(clientId, {
285 remaining: 100,
286 reset: currentTime + 900
287 });
288 }
289
290 const state = rateStore.get(clientId);
291 if (state.remaining > 0) {
292 state.remaining--;
293 }
294 }
295 };
296
297 suite
298 .add("Rate Limit - 10 concurrent clients", () => {
299 concurrentRateCheck(10);
300 })
301 .add("Rate Limit - 100 concurrent clients", () => {
302 concurrentRateCheck(100);
303 })
304 .add("Rate Limit - 500 concurrent clients", () => {
305 concurrentRateCheck(500);
306 })
307 .add("Rate Limit - 1000 concurrent clients", () => {
308 concurrentRateCheck(1000);
309 })
310 .on("cycle", event => {
311 console.log(` ${String(event.target)}`);
312 })
313 .on("complete", function () {
314 console.log(" Performance degrades with more concurrent clients");
315 })
316 .run();
317}
318
319/**
320 * Benchmarks rate limit override functionality

Callers 1

mainFunction · 0.85

Calls 2

concurrentRateCheckFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected