mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
fix: concurrency typo thx giveawayboat <3
This commit is contained in:
9
gateway/calculateMaxShards.ts
Normal file
9
gateway/calculateMaxShards.ts
Normal 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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user