From b1b8d91bda0d52bffc6b56b69c86d46843cd2058 Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:28:08 -0400 Subject: [PATCH] chore: increase concurrency and rate limit --- src/config/index.ts | 16 ++++++++-------- src/controllers/threading/threadHandler.ts | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/config/index.ts b/src/config/index.ts index ab37741..68bb76b 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -74,23 +74,23 @@ export default class Config { setLimiter() { const slowLimiter = rateLimit({ windowMs: 1 * 60 * 1000, //1min - max: parseInt(process.env.MAX_QUERIES_PER_MIN || "20"), + max: parseInt(process.env.MAX_QUERIES_PER_MIN || "50"), }); const medLimiter = rateLimit({ windowMs: 1 * 60 * 1000, //1min - max: parseInt(process.env.MAX_QUERIES_PER_MIN || "30"), + max: parseInt(process.env.MAX_QUERIES_PER_MIN || "100"), }); const fastLimiter = rateLimit({ windowMs: 1 * 60 * 1000, //1min - max: parseInt(process.env.MAX_QUERIES_PER_MIN || "6000"), + max: parseInt(process.env.MAX_QUERIES_PER_MIN || "10000"), }); this.app.use("/", fastLimiter); - this.app.use("/v1/query", slowLimiter); + this.app.use("/v1/query", medLimiter); this.app.use("/v1/team/:team_name/query", medLimiter); - this.app.use("/v1/team/:smartapiID/query", medLimiter); - this.app.use("/v1/meta_knowledge_graph", medLimiter); - this.app.use("/v1/team/:teamName/meta_knowledge_graph", medLimiter); - this.app.use("/v1/smartapi/:smartapiID/meta_knowledge_graph", medLimiter); + this.app.use("/v1/team/:smartapiID/query", fastLimiter); + this.app.use("/v1/meta_knowledge_graph", fastLimiter); + this.app.use("/v1/team/:teamName/meta_knowledge_graph", fastLimiter); + this.app.use("/v1/smartapi/:smartapiID/meta_knowledge_graph", fastLimiter); this.app.use("/v1/asyncquery", fastLimiter); this.app.use("/v1/team/:teamName/asyncquery", fastLimiter); this.app.use("/v1/smartapi/:smartapiID/asyncquery", fastLimiter); diff --git a/src/controllers/threading/threadHandler.ts b/src/controllers/threading/threadHandler.ts index 7f91bb3..8bf711e 100644 --- a/src/controllers/threading/threadHandler.ts +++ b/src/controllers/threading/threadHandler.ts @@ -22,10 +22,10 @@ import { Queue } from "bull"; const SYNC_MIN_CONCURRENCY = 2; const ASYNC_MIN_CONCURRENCY = 3; -// On most instances, there are two nodes, one for Service Provider endpoints and one for everything else -// On Dev and local instances, this isn't the case, so a lower concurrency is needed -const CORE_CONCURRENCY_RATIO = parseInt(process.env.CORE_CONCURRENCY_RATIO) || 0.25; -const MEM_CONCURRENCY_RATIO = parseFloat(process.env.MEM_CONCURRENCY_RATIO) || 0.6; +// Ratio of Queryies per core +const CORE_CONCURRENCY_RATIO = parseInt(process.env.CORE_CONCURRENCY_RATIO) || 1; +// Ratio of Queries per GB of memory +const MEM_CONCURRENCY_RATIO = parseFloat(process.env.MEM_CONCURRENCY_RATIO) || 2; const CORE_LIMIT = Math.ceil(os.cpus().length * CORE_CONCURRENCY_RATIO);