Karew
Karew
DIAdiscord.js - Imagine an app
Created by Karew on 1/12/2024 in #djs-questions
Cache/sweeper settings for memory constraints, mostly messages
We are in a very memory constrained environment. Our individual bot processes can't exceed 512 MB. Right now each process is managing 3 shards of our Discord connection. 1. The bot only listens for new messages and new threads to join. 2. It only determines if it needs to reply to a message, and we also log some info about the guild to an external service 3. We don't care about reactions, members, message edits, any other part of the message lifecycle, and we don't need to retain any messages longer than it takes to process them. I'm trying to configure the makeCache and sweepers settings to help optimize memory usage in this scenario. What I have is below, any other suggestions would be welcome
const BotName = new Client({
// Other config omitted
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
],
partials: [
Partials.Channel, // Required to get DM content for some reason
],
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
ReactionManager: 0,
GuildMemberManager: {
maxSize: 200, // Only store up to 200 members per guild at a time
keepOverLimit: (member) => member.id === member.client.user.id, // Keep ourselves
},
}),
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 300, // Sweep cache every 5 minutes
lifetime: 300, // Remove messages older than 5 minutes.
},
users: {
interval: 300, // Sweep cache every 5 minutes
lifetime: 7200, // Remove users older than two hours
filter: (user) => user.id !== user.client.user.id, // Keep ourselves
},
},
});
const BotName = new Client({
// Other config omitted
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
],
partials: [
Partials.Channel, // Required to get DM content for some reason
],
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
ReactionManager: 0,
GuildMemberManager: {
maxSize: 200, // Only store up to 200 members per guild at a time
keepOverLimit: (member) => member.id === member.client.user.id, // Keep ourselves
},
}),
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 300, // Sweep cache every 5 minutes
lifetime: 300, // Remove messages older than 5 minutes.
},
users: {
interval: 300, // Sweep cache every 5 minutes
lifetime: 7200, // Remove users older than two hours
filter: (user) => user.id !== user.client.user.id, // Keep ourselves
},
},
});
8 replies