Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Message: deactivate sql write #37

Closed
andrenjdev opened this issue Aug 9, 2017 · 13 comments
Closed

Update Message: deactivate sql write #37

andrenjdev opened this issue Aug 9, 2017 · 13 comments

Comments

@andrenjdev
Copy link

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

@noplanman
Copy link
Member

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 👍

@andrenjdev
Copy link
Author

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

@jacklul
Copy link

jacklul commented Aug 10, 2017

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.

@noplanman
Copy link
Member

@jacklul I really like that idea!

@andrenjdev
Copy link
Author

andrenjdev commented Aug 11, 2017

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 :)

@jacklul
Copy link

jacklul commented Aug 11, 2017

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

@andrenjdev
Copy link
Author

andrenjdev commented Aug 11, 2017

@jacklul thanks a lot
You make my day :)

@andrenjdev
Copy link
Author

@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 :(

@jacklul
Copy link

jacklul commented Aug 12, 2017

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.

@andrenjdev
Copy link
Author

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

@andrenjdev
Copy link
Author

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.

@jacklul
Copy link

jacklul commented Aug 16, 2017

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!

@andrenjdev
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants