Skip to content

Commit

Permalink
chore: increase concurrency and rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Sep 20, 2024
1 parent 488665f commit b1b8d91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/threading/threadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b1b8d91

Please sign in to comment.