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

Function benchmarkRateCleanup

benchmarks/rate-limiting.js:401–457  ·  view source on GitHub ↗

* Benchmarks rate limit cleanup for expired entries

()

Source from the content-addressed store, hash-verified

399 * Benchmarks rate limit cleanup for expired entries
400 */
401function benchmarkRateCleanup () {
402 console.log("\n📊 Rate Limit Cleanup Performance");
403 console.log("-".repeat(40));
404
405 const suite = new Benchmark.Suite();
406
407 // Create rate store with expired entries
408 const createStoreWithExpiredEntries = size => {
409 const store = new Map();
410 const currentTime = Math.floor(Date.now() / 1000);
411
412 for (let i = 0; i < size; i++) {
413 store.set(`client-${i}`, {
414 remaining: Math.floor(Math.random() * 100),
415 reset: currentTime - Math.floor(Math.random() * 1000) // Some expired, some not
416 });
417 }
418
419 return store;
420 };
421
422 const cleanupExpiredEntries = store => {
423 const currentTime = Math.floor(Date.now() / 1000);
424 const toDelete = [];
425
426 for (const [key, value] of store.entries()) {
427 if (currentTime >= value.reset) {
428 toDelete.push(key);
429 }
430 }
431
432 toDelete.forEach(key => store.delete(key));
433
434 return toDelete.length;
435 };
436
437 suite
438 .add("Rate Cleanup - Small store (100 entries)", () => {
439 const store = createStoreWithExpiredEntries(100);
440 cleanupExpiredEntries(store);
441 })
442 .add("Rate Cleanup - Medium store (1000 entries)", () => {
443 const store = createStoreWithExpiredEntries(1000);
444 cleanupExpiredEntries(store);
445 })
446 .add("Rate Cleanup - Large store (10000 entries)", () => {
447 const store = createStoreWithExpiredEntries(10000);
448 cleanupExpiredEntries(store);
449 })
450 .on("cycle", event => {
451 console.log(` ${String(event.target)}`);
452 })
453 .on("complete", function () {
454 console.log(" Cleanup time increases with store size");
455 })
456 .run();
457}
458

Callers 1

mainFunction · 0.85

Calls 3

cleanupExpiredEntriesFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected