startup ~5s now

This commit is contained in:
Skillz4Killz
2021-05-23 17:41:06 +00:00
committed by GitHub
parent 05300f012b
commit 8cdfdb757e
5 changed files with 19 additions and 19 deletions
+5 -6
View File
@@ -1,10 +1,10 @@
import { delay } from "../util/utils.ts";
import { ws } from "./ws.ts";
/** The handler to clean up shards that identified but never received a READY. */
export async function cleanupLoadingShards() {
while (ws.loadingShards.size) {
ws.log("DEBUG", "Running while loop in cleanupLoadingShards function.");
export function cleanupLoadingShards() {
if (!ws.loadingShards.size) return;
ws.log("DEBUG", "Running setTimeout in cleanupLoadingShards function.");
const now = Date.now();
ws.loadingShards.forEach((loadingShard) => {
ws.log("DEBUG", `Running forEach loop in cleanupLoadingShards function.`);
@@ -16,6 +16,5 @@ export async function cleanupLoadingShards() {
);
});
await delay(1000);
}
if (ws.loadingShards.size) setTimeout(cleanupLoadingShards, 10000);
}
+2 -2
View File
@@ -95,11 +95,11 @@ export async function handleOnMessage(message: any, shardId: number) {
ws.loadingShards.get(shardId)?.resolve(true);
ws.loadingShards.delete(shardId);
// Wait 5 seconds to spawn next shard
// Wait few seconds to spawn next shard
setTimeout(() => {
const bucket = ws.buckets.get(shardId % ws.botGatewayData.sessionStartLimit.maxConcurrency);
if (bucket) bucket.createNextShard.shift()?.();
}, 5000);
}, ws.spawnShardDelay);
}
// Update the sequence number if it is present
+1 -1
View File
@@ -28,7 +28,7 @@ export async function heartbeat(shardId: number, interval: number) {
shard.heartbeat.interval = interval;
shard.heartbeat.intervalId = setInterval(async () => {
ws.log("DEBUG", `Running setInterval in heartbeat file.`);
ws.log("DEBUG", `Running setInterval in heartbeat file. Shard: ${shardId}`);
const currentShard = ws.shards.get(shardId);
if (!currentShard) return;
-1
View File
@@ -38,5 +38,4 @@ export async function startGateway(options: StartGatewayOptions) {
ws.lastShardId = options.lastShardId || ws.botGatewayData.shards - 1;
ws.spawnShards(ws.firstShardId);
await ws.cleanupLoadingShards();
}
+2
View File
@@ -26,6 +26,8 @@ export const ws = {
reshard: true,
/** The percentage at which resharding should occur. */
reshardPercentage: 80,
/** The delay in milliseconds to wait before spawning next shard. OPTIMAL IS ABOVE 2500. YOU DON"T WANT TO HIT THE RATE LIMIT!!! */
spawnShardDelay: 2500,
/** The maximum shard Id number. Useful for zero-downtime updates or resharding. */
maxShards: 0,
/** Whether or not the resharder should automatically switch to LARGE BOT SHARDING when you are above 100K servers. */