Skip to content

Commit e34db4d

Browse files
committed
remove clusters arg everywhere
1 parent 2b6cc59 commit e34db4d

3 files changed

Lines changed: 99 additions & 104 deletions

File tree

lib/Config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,7 @@ class Config extends EventEmitter {
18731873
assert(this.localCache, 'localCache must be defined when rate limiting is enabled');
18741874

18751875
// Parse and validate all rate limiting configuration
1876-
this.rateLimiting = parseRateLimitConfig(config.rateLimiting, this.clusters = this.clusters || 1);
1876+
this.rateLimiting = parseRateLimitConfig(config.rateLimiting);
18771877
}
18781878

18791879

lib/api/apiUtils/rateLimit/config.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,10 @@ const rateLimitConfigSchema = Joi.object({
199199
*
200200
* @param {string} resourceClass - Rate limit class name ('bucket' or 'account')
201201
* @param {object} validatedCfg - Already validated config from Joi
202-
* @param {number} clusters - Number of worker processes spawned per instance
203202
* @param {number} nodes - Number of instances that requests will be load balanced across
204203
* @returns {RateLimitClassConfig} Transformed rate limit config
205204
*/
206-
function transformClassConfig(resourceClass, validatedCfg, clusters, nodes) {
205+
function transformClassConfig(resourceClass, validatedCfg, nodes) {
207206
const transformed = {
208207
defaultConfig: undefined,
209208
configCacheTTL: validatedCfg.configCacheTTL,
@@ -213,23 +212,22 @@ function transformClassConfig(resourceClass, validatedCfg, clusters, nodes) {
213212
if (validatedCfg.defaultConfig?.requestsPerSecond) {
214213
const { limit, burstCapacity } = validatedCfg.defaultConfig.requestsPerSecond;
215214

216-
// Validate limit against nodes AND workers (business rule)
217-
const minLimit = nodes * clusters;
218-
if (limit > 0 && limit < minLimit) {
215+
// Validate limit against nodes (business rule)
216+
if (limit > 0 && limit < nodes) {
219217
throw new Error(
220218
`rateLimiting.${resourceClass}.defaultConfig.` +
221219
`requestsPerSecond.limit (${limit}) must be >= ` +
222-
`(nodes x workers = ${nodes} x ${clusters} = ${minLimit}) ` +
223-
'or 0 (unlimited). Each worker enforces limit/nodes/workers locally. ' +
224-
`With limit < ${minLimit}, per-worker rate would be < 1 req/s, effectively blocking traffic.`
220+
`nodes (${nodes}) ` +
221+
'or 0 (unlimited). Each node enforces limit/nodes locally. ' +
222+
`With limit < ${nodes}, per-node rate would be < 1 req/s, effectively blocking traffic.`
225223
);
226224
}
227225

228226
// Use provided burstCapacity or fall back to default
229227
const effectiveBurstCapacity = burstCapacity || transformed.defaultBurstCapacity;
230228

231-
// Calculate per-worker interval using distributed architecture
232-
const interval = calculateInterval(limit, nodes, clusters);
229+
// Calculate per-node interval using distributed architecture
230+
const interval = calculateInterval(limit, nodes);
233231

234232
// Store both the original limit and the calculated values
235233
transformed.defaultConfig = {
@@ -248,11 +246,10 @@ function transformClassConfig(resourceClass, validatedCfg, clusters, nodes) {
248246
* Parse and validate the complete rate limiting configuration
249247
*
250248
* @param {Object} rateLimitingConfig - config.rateLimiting object from config.json
251-
* @param {number} clusters - Number of worker clusters (must be numeric)
252249
* @returns {Object} Fully parsed and validated rate limiting configuration
253250
* @throws {Error} If configuration is invalid
254251
*/
255-
function parseRateLimitConfig(rateLimitingConfig, clusters) {
252+
function parseRateLimitConfig(rateLimitingConfig) {
256253
// Validate configuration using Joi schema
257254
const { error: validationError, value: validated } = rateLimitConfigSchema.validate(
258255
rateLimitingConfig,
@@ -282,8 +279,8 @@ function parseRateLimitConfig(rateLimitingConfig, clusters) {
282279
),
283280
};
284281

285-
parsed.bucket = transformClassConfig('bucket', validated.bucket, clusters, parsed.nodes);
286-
parsed.account = transformClassConfig('account', validated.account, clusters, parsed.nodes);
282+
parsed.bucket = transformClassConfig('bucket', validated.bucket, parsed.nodes);
283+
parsed.account = transformClassConfig('account', validated.account, parsed.nodes);
287284

288285
return parsed;
289286
}

0 commit comments

Comments
 (0)