How to send queries simultaneously to test Transactions efficiency in Mysql?

Asked

Viewed 174 times

4

I have a table Innodb in Mysql where I store a user’s account balance. To give a UPDATE on the balance I use Transactions to prevent two or more queries from trying to give UPDATE simultaneously and ends up corrupting the value of the balance.

Using PHP preference, or some other tool specifies for this, what is the best way to perform queries testing, for example, send 10 queries simultaneously by requesting UPDATE table to test the efficiency of the use of Transactions and make sure my algorithm won’t corrupt the data?

2 answers

3

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

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

Where concurrency would be the number of simultaneous and iterations the amount of darlings that each client will execute.

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 part of 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 files in php with the same instructions and run everything together through a single command line, this will create the competition you want to exhaust your test that would be closer to a real simulation of your own scenario because programming problems may appear in php before you even reach the database, running only the test in the database is missing to test this behavior of the programming you did in php
  • It would be good practice then to simulate hundreds or even thousands of HTTP request using Apache AB? http://httpd.apache.org/docs/2.2/programs/ab.html

  • 1

    yes, with apache benchmark you can already measure the completed requests, the failed ones, the response time, and this will already be considering the time of the queries, of course depending on the results you will need to adjust the queries in BD.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.