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.
OPTIMIZE TABLE reorganizes the physical storage of table data and associated index data, to reduce storage space and improve I/O efficiency when accessing the table. The exact changes made to each table depend on the storage engine used by that table.
OPTIMIZE is 'safe' in all respects since it locks the table, copies all the data over, then renames the new copy in place of the old.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With