fix: concurrency typo thx giveawayboat <3

This commit is contained in:
Skillz4Killz
2022-03-15 02:45:07 +00:00
committed by GitHub
parent a0a1554756
commit d62a5b71b1
5 changed files with 22 additions and 5 deletions

View File

@@ -0,0 +1,9 @@
/** Handler used to determine max number of shards to use based upon the max concurrency. */
export function calculateMaxShards(maxShards: number, maxConcurrency: number): number {
if (maxShards < 100) return maxShards;
return Math.ceil(
maxShards /
(maxConcurrency === 1 ? 16 : maxConcurrency),
) * maxConcurrency;
}

View File

@@ -23,6 +23,7 @@ import { DiscordenoShard } from "./shard.ts";
import { GatewayIntents } from "../types/shared.ts";
import { StatusUpdate } from "../helpers/misc/editBotStatus.ts";
import { DiscordGatewayPayload } from "../types/discord.ts";
import { calculateMaxShards } from "./calculateMaxShards.ts";
/** Create a new Gateway Manager.
*
@@ -97,6 +98,7 @@ export function createGatewayManager(
resume: options.resume ?? resume,
safeRequestsPerShard: options.safeRequestsPerShard ?? safeRequestsPerShard,
handleDiscordPayload: options.handleDiscordPayload,
calculateMaxShards: options.calculateMaxShards ?? calculateMaxShards,
};
}
@@ -222,4 +224,6 @@ export interface GatewayManager {
resume: typeof resume;
/** Calculates the number of requests in a shard that are safe to be used. */
safeRequestsPerShard: typeof safeRequestsPerShard;
/** Calculates the number of shards to use based on the max concurrency */
calculateMaxShards: typeof calculateMaxShards;
}

View File

@@ -12,3 +12,4 @@ export * from "./tellWorkerToIdentify.ts";
export * from "./shard.ts";
export * from "./gateway_manager.ts";
export * from "./safeRequestsPerShard.ts";
export * from "./calculateMaxShards.ts";

View File

@@ -38,12 +38,9 @@ export async function resharder(
gateway.sessionStartLimitResetAfter = results.sessionStartLimit.resetAfter;
gateway.maxConcurrency = results.sessionStartLimit.maxConcurrency;
// If more than 100K servers, begin switching to 16x sharding
if (gateway.maxShards > 60 && gateway.useOptimalLargeBotSharding) {
if (gateway.useOptimalLargeBotSharding) {
gateway.debug("[Resharding] Using optimal large bot sharding solution.");
gateway.maxShards = Math.ceil(
gateway.maxShards /
(results.sessionStartLimit.maxConcurrency === 1 ? 16 : results.sessionStartLimit.maxConcurrency),
);
gateway.maxShards = gateway.calculateMaxShards(gateway.maxShards, results.sessionStartLimit.maxConcurrency);
}
gateway.spawnShards(gateway, gateway.firstShardId);

View File

@@ -38,6 +38,12 @@ export function prepareBuckets(gateway: GatewayManager, firstShardId: number, la
}
export function spawnShards(gateway: GatewayManager, firstShardId = 0) {
// PREPARES THE MAX SHARD COUNT BY CONCURRENCY
if (gateway.useOptimalLargeBotSharding) {
gateway.debug("[Resharding] Using optimal large bot sharding solution.");
gateway.maxShards = gateway.calculateMaxShards(gateway.maxShards, gateway.maxConcurrency);
}
// PREPARES ALL SHARDS IN SPECIFIC BUCKETS
prepareBuckets(gateway, firstShardId, gateway.lastShardId ? gateway.lastShardId + 1 : gateway.maxShards);