Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 有事中防护的中间件吗?如程序中有个慢SQL,拖慢数据库,数据库自动对这句SQL熔断
Is there any middleware for in-process protection? For example, if there is a slow SQL query in the program that drags down the database, can the database automatically fuse this SQL query?
Monitor long-running SQL and then kill it?
I’ve long wanted to create a stored procedure and execute it periodically, but I’m worried about unintended consequences.
You’re talking about the automatic SQL throttling feature, right?
Automatic throttling is mainly applied in the following three scenarios:
- Traffic issues: Cache penetration or abnormal calls occur, leading to a sharp increase in the concurrency of certain types of SQL.
- Data issues: An account with large order data, where the related SQL of this account occupies a large amount of database resources.
- SQL issues: SQL without indexes is called frequently, affecting normal business operations.
We have similar issues in our business. When processing data for major clients, it slows down the entire service. Currently, we are just afraid of collateral damage.
It might not be appropriate to leave this to middleware or the database. Some business processes are inherently slow, so it is more reasonable to control it at the business level.
Unverified internal information: There is this idea, and there might be a similar feature in the future.
Isn’t the MAX_EXECUTION_TIME parameter used for this purpose?
As long as the boundaries are defined, it’s like circuit breaking at the service level. Establish a circuit breaking strategy, and let the users control it themselves.
TiDB can fuse SQL with excessive memory usage when an OOM (Out of Memory) occurs.
My idea is to throttle a certain type of SQL.
This parameter can easily cause collateral damage if applied uniformly. I think we can use hints or set session-level parameters to allow developers to impose restrictions in the code.
MySQL can also be set at the SQL level, but it is a bit troublesome to use.
TiDB does not support stored procedures!
Add TiDB server nodes specifically to handle these slow SQL queries.
Yes, our business is currently running on MySQL, and we are planning to run the reporting and dashboard requirements on TiDB.