php-telegram-bot/telegram-bot-manager

Update Message: deactivate sql write

andrenjdev opened this issue ยท 13 comments

Hi,
I have to remove update in sql Db only when i do editMessage command because the level of cpu is always over 80% and sometime it go down :/
Can you say me how to deactivate this feature? I have to edit Request file?

Thank you for your great work.

Andrea

Hi, could you please explain in more detail what your are doing that causes this?

Of course it would make sense to fix the problem for everyone, not just remove the code in your personal project ๐Ÿ‘

It's not a problem but my costumer start a process at the same time and this process update every minutes a message.
I have a small server on AWS and every day the CPU level is over 80%. I wish to deactivate the writing on my db to improve the service. I can edit the message without store it on db?

Thanks

This gives me idea to have some kind of options for the DB to select which tables to insert to.

PS. You can copy DB.php from the core library into your project then either autoload it with composer or include/require in hook script, then you can remove the query that inserts edited message from there, this is mostly a workaround but should do what you want. You will have to watch for DB.php updates in the future to not break the bot.

@jacklul I really like that idea!

So,

elseif ($update_type === 'edited_message') {
            $edited_message = $update->getEditedMessage();

            if (self::insertEditedMessageRequest($edited_message)) {
                $chat_id                 = $edited_message->getChat()->getId();
                $edited_message_local_id = self::$pdo->lastInsertId();

                return self::insertTelegramUpdate(
                    $update_id,
                    $chat_id,
                    null,
                    null,
                    null,
                    null,
                    $edited_message_local_id
                );
            }
        }

I can edit it and do that, it works?

elseif ($update_type === 'edited_message') {
            $edited_message = $update->getEditedMessage();

            return true;
        }

Could be a correct solution?
Thank you :)

Yes but putting return true; just after elseif ($update_type === 'edited_message') { would be better, no need to execute any code before that.

@jacklul thanks a lot
You make my day :)

@noplanman @jacklul
schermata 2017-08-12 alle 19 03 59

This is the CPU Utilization Percent chart. Are you sure that this patch can be the right solution?
My DB went down again :(

The patch does what you wanted, prevents inserting edited messages to the database.

There might be some misconfiguration error on the database server or something.
As far as I can tell, the library itself doesn't spike that much on CPU usage on very active bots.

I improved my db and my code. I will update you. thank you:)

Hei,
the problem still exist so I improved the database CPU power. I have seen that the size table named: request_limiter is 264 MB (after 1 month of time-live ) and every minutes the number of row increase by 100 rows.

Yes, every request that can cause a bot to get limited by the API is inserted there, you can set up a SQL task to clean that table from records older than 5 minutes, that will make the trick!

I think it's not a solution for my problem but I can try to add this task :)