tdlight-team/tdlight-telegram-bot-api

optimize_memory maximum interval

cavallium opened this issue · 8 comments

Every bot should call optimize_memory sometimes to avoid memory "leaks".

Add a parameter to force optimize_memory on all bots that didn't call it in the last X hours.
This parameter should be configurable, but it shouldn't be less than 20 minutes or more than 2 days.

Bots cleaned in this way can return answers with missing data or can lose some updates, but this is not a problem, since every bot can call it for themselves every X hours to avoid this kind of problems.

The interval shouldn't be disabled by the users with an option, because disabling optimize_memory leads inevitably to out of memory.

Regarding the memory usage, how do the official servers handle that?
Or do they just have 2TB Ram and run until they crash?

levlam says that tdlib doesn't consume as much ram, they are fine with that, they say they have never had memory problems, probably because they have thousands of bots that have less than 1 message/s

Regarding the memory usage, how do the official servers handle that?
Or do they just have 2TB Ram and run until they crash?

They restart an instance when it consumes too much memory.
They do this because the vast majority of instances is composed of semi-dead bots.

Is that something we should to have as a cleanup mode as well? Like kill bots which were not used in X hours?
Should I open up an issue for that?

It isn't useful because if you kill a bot it will not free memory.
If you want to do that we should open an issue in tdlight-team/tdlight about releasing memory of closed sessions.

I was under the assumption that is what the close command is doing

close
Use this method to close the bot instance before moving it from one local server to another. You need to delete the webhook before calling this method to ensure that the bot isn't launched again after server restart. The method will return error 429 in the first 10 minutes after the bot is launched. Returns True on success. Requires no parameters.

https://core.telegram.org/bots/api#close

Close doesn't free the resources unfortunately. You can try it by yourself.