How to send queries simultaneously to test the efficiency of Transactions in MySQL?

4

I have an InnoDB table in MySQL where I store a user's account balance. To give a% of the balance I use Transactions to prevent two or more queries from attempting to give UPDATE simultaneously and end up corrupting the balance amount.

Using PHP preferably, or some other specific tool for this, how best to perform query tests, for example, send 10 queries simultaneously by requesting% of the table to test the efficiency of the Transactions and make sure my algorithm will not corrupt the data?

    
asked by anonymous 06.07.2015 / 10:07

2 answers

2

When you say you prefer to use a test-ready tool,

  • I would use the mysqlslap tool as the last test, because then you end up testing only the database, it is a test that validates the part of the transactions until the end, but ...
  • It would give more value to a custom test, it would be more efficient to make php files with the same instructions and run it all together through a single command line, this will create the competition you want to exhaust your test that would be closest of a real simulation of your own scenario because programming problems may appear in php before even reaching the database, running only the test in the bank is missing to test this programming behavior you did in php
06.07.2015 / 13:55
3

You can use mysqlslap to test your transactions . Create a .sql file with the cases that you want to test. Your script would look something like:

> mysqlslap --concurrency=5 --iterations=5 --query=query.sql --delimiter=";"

Where concurrency would be the number of concurrent clients and iterations the amount of queries that each client will execute.

    
06.07.2015 / 12:53