Cache Sweeper
Hello, I wanted to know why, even with these cache sweepers, my ram usage continues to increase as the bot's uptime increases. (5 process with 10 shards of ~1000 guilds and 59 shards in total, 58.7k guilds)
34 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button![email protected]
v17.9.0
Or he should return true to be removed from the cache ?
it increases because you dont have lifetime for presences, reactions, and so on.. those pile up quickly if you have their intents
why are you returing false on filter?
if you dont want to store them, just modify the makeCache object
I want to store them but only for 1 hour
you cant do that since there is no that lifetime option
??? the lifetime option is only for invites messages and threads
^
Are you blind ?
you dont get me, your usage goes up because of those specific caches (users, presences especially, ....), and since there is no option to put lifetime on it, you cant prevent ram from increasing if you dont fully disable those caches
But if i clear it every hour it shouldn't increase no ?
you can only clear it manually
then it shouldnt increase
Even with the sweeper ?
i literally just said that you cant with sweeper because half of them dont support lifetime
But on the doc i can use all of them
I will try it this day, Iβll let you know and check the ram usage after some days
I tried this:
But i have this error:
Uncaught exception: TypeError [SweepFilterReturn]: The return value of the sweepFilter function was not false or a Function
@qjuhOn which line?
at Timeout._onTimeout (C:\Users\Sayrixx\Desktop\ChilledBot\node_modules\discord.js\src\util\Sweepers.js:461:48)
So all sweepers where i use the function filter
i think that advice was wrong,
filter
is supposed to be a function that returns a function (or null)
export type GlobalSweepFilter<K, V> = () => ((value: V, key: K, collection: Collection<K, V>) => boolean) | null;
from https://old.discordjs.dev/#/docs/discord.js/14.13.0/typedef/SweepOptions
filter: The function used to determine the function passed to the sweep methodas for the original question, you probably wanted to return
true
in your filterok. I will try to return true
from https://discord.js.org/docs/packages/collection/1.5.3/Collection:Class#sweep
Removes items that satisfy the provided filter function.
Here is my code that i will push into production:
(i will just change the interval)
@sayrix how did it go? Did
true
work better?I forgot to disable something so i will re try now, i'll let you know friday
perfect, thank you
I've also had a bunch of issues similar to this and struggled with my sweepers
btw for my sharding manager i use "discord-hybrid-sharding"
@lemorrow
When i look the graph thats something like ~100MiB every 3 hours
Right, so no big improvement with that
I'll let you know if I can find any improvements with my experiments
Something that would definitely help in diagnosing where this RAM usage originates from (because i see nothing here indicating that caches are what drive up this ram usage) would be to diagnose whether the sweepers run as expected.
this event listener: would allow you to diagnose whether the numbers approximately match up. If they do, ur RAM leakage is likely caused by other stuff
If you also have a big bot like mine idk if you also use discord-hybrid-sharding for your sharding manager because maybe that it's caused by my sharding manager π€·ββοΈ
I will try to add this code in production to see
I think i will install a profiler to see what's wrong
did you ever figure this out? I have a pretty similar issue but it's a smaller bot. I have pretty aggressive makeCache settings (i think) and some sweepers but the ram still seems to go up and then crash/ i reset it before it does
the
top
command shows super low memory usage, but the free -g/-m shows a higher amount is being used, closer to what my VPS monitoring reports.