MySQL 去优化
是否有一个简单的命令可以让我调整 MySQL 数据库实例,使其运行速度比正常情况慢?
我正在研究记录和重放数据库交互的代码。它所做的事情之一是跟踪给定查询/命令的执行时间,如果在重放期间运行速度明显减慢,它会发出警告。当然,如果你不测试它,它就不起作用;我正在尝试为此功能提出一个自动化测试。我可以对测试数据库做一些会降低性能的事情吗?我需要做的就是为任何给定的查询可靠地添加 2+ 毫秒,然后我就完成了。
Is there a simple command that will let me tweak a MySQL DB instance to run slower than normal?
I'm working on code that records and replays database interactions. One of the things it does is keep track of how long a given query/command takes to execute, and if it runs substantially slower during the replay, it throws a warning. Of course, If You Don't Test It, It Doesn't Work; I'm trying to come up with an automated test for this feature. Is there something I can do to my test DB that will screw up performance? All I need to do is reliably add 2+ milliseconds to any given query and I'm set.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想测试长查询,请执行以下操作:
SELECT SLEEP(1);
如果您只想测试持续时间检测是否有效,那么查询本身是什么并不重要。
(我知道这破坏了真正的“重播”方面,但在“播放”期间将
SLEEP(1)
添加到某些选择语句应该是微不足道的。)编辑:
第二个想法,您可能会喜欢更好:从另一个连接在表上创建锁。运行脚本。稍等一下。把那个锁去掉。它不会干扰您的任何播放查询。
If you just want to test long queries, do this:
SELECT SLEEP(1);
It shouldn't matter what the query is itself if all you want to do is test if your duration detection works.
(I know this breaks the true "replay" aspect, but it should be trivial to add
SLEEP(1)
during "playback" to some select statements.)EDIT:
A second idea, which you might like better: Create a lock on a table from another connection. Run the script. Wait a bit. Remove that lock. It won't involve messing with any of your playback queries.
基本过程如下:
开始事务
执行 sql 操作
在 perl 或 sql 中睡眠 2ms
commit
关键是开始/提交部分:它将保留您获取的所有锁,使事情按照您想要的速度慢下来。
需要考虑的其他测试:
在两个进程中开始事务
在第一个进程中执行 sql 操作
执行 sql 操作在第二个进程中
在每个进程中执行更多 sql 操作
提交每个进程
Basic procedure like so:
begin transaction
do your sql stuff
sleep 2ms in perl or sql
commit
the key is the begin/commit part: it'll keep any locks you acquired, making things as slow as you want them.
Other test to consider:
begin transaction in two processes
do your sql stuff in first process
do your sql stuff in second process
do more sql stuff in each process
commit each process