danog / MadelineProto

Async PHP client API for the telegram MTProto protocol
https://docs.madelineproto.xyz
GNU Affero General Public License v3.0
2.9k stars 663 forks source link

Sessions use too much memory. #926

Closed Tivixo closed 3 years ago

Tivixo commented 3 years ago

Hi, From almost last week my ubuntu server have memory problem, my memory and swap are more than 90% used. I enter "ps aux --sort=-%mem | head" and this is result:


USER      PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     25020  0.7  9.1 480564 186760 ?       Ss   09:00   0:05 MadelineProto worker /var/www/html/tg/../sssn/acc-7
root      3129  0.6  7.5 472372 153988 ?       Ss   Apr11   6:06 MadelineProto worker /var/www/html/tg/../sssn/acc-1
root     24162  0.4  6.4 432608 132640 ?       Ss   08:37   0:09 MadelineProto worker /var/www/html/tg/../sssn/acc-4
root     25024  0.3  5.9 412124 121908 ?       Ss   09:00   0:02 MadelineProto worker /var/www/html/tg/../sssn/acc-2
root      3972  0.3  5.6 463324 115780 ?       Ss   Apr11   3:19 MadelineProto worker /var/www/html/tg/../sssn/acc-12
root      3768  0.2  5.5 424424 112584 ?       Ss   Apr11   2:34 MadelineProto worker /var/www/html/tg/../sssn/acc-6
root      3173  0.2  4.8 416220 99932 ?        Ss   Apr11   2:23 MadelineProto worker /var/www/html/tg/../sssn/acc-3
root      3169  0.3  4.4 432604 91064 ?        Ss   Apr11   2:56 MadelineProto worker /var/www/html/tg/../sssn/acc-5
root      3118  0.2  4.4 432604 90776 ?        Ss   Apr11   2:53 MadelineProto worker /var/www/html/tg/../sssn/acc-9

As you sea the created account's sessions are using too much memory.

Can you help me for fixing this? I can't increase my memory, so what I should to do for decreasing telegram sessions memory usage?

PS: I use last version (for 4/11/2021)

Thank you a lot.

danog commented 3 years ago

The number 1 solution to memory usage is switching to MySQL: https://docs.madelineproto.xyz/docs/SETTINGS.html#settingsdb

Tivixo commented 3 years ago

Thank you for your help and sorry for this noob question... this is my $setting array now:

$settings = [];
$settings['logger']['logger'] = \danog\MadelineProto\Logger::FILE_LOGGER;
$settings['logger']['logger_param'] = __DIR__.'/logFile.log';
$settings['db']['type'] = 'mysql';
$settings['db']['mysql']['password'] = 'mypwd';

[all other mysql settings are same with default values.]

but after execute the code I don't see any 'MadelineProto' database in my phpMyAdmin and the memory problem is still exist.

I know it's so amateur question but could you guide me more please? Thank you.