Performance Testing Of Concurrently Running SQL Commands In PHP / MySQL
Ever wondered, how to perform several SQL commands simultaneously from within a PHP script without the use of AJAX?
Well, there is a very simple method, which helped myself several times for example for testing locking problems with SQL or evaluating, if multi core support does work for the MySQL database system.
Just create an HTML file with several iframes. In each iframe with the parameter src=”test.php” you call a PHP file that calls the SQL statement to be tested.
When opened with Internet Explorer the iframes will be opened simultaneously and the PHP files within will be processed at the same time. With Firefox this will not work!
Sometimes you may want to simulate the parallel execution of several SQL statements with a defined delay. You can do so by adding a timer in each of the PHP files before the execution of the SQL statement.
With the time(); command in PHP in the HTML file you can measure exactly when each PHP file started and ended execution.
One important point: Don’t forget to disable MySQL Caching by Adding the phrase SQL_NO_CACHE in each SQL Statement.
I used this configuration to check how a MySQL database behaves in a multi core environment in comparison to an single core environment. Actually in a single core environment the SQL commands are processed simultaneously as well, but the execution time increases proportionally to the number of statements. In a multi core environment there ist only a small increase until all cores are in use.
Another application for this configuration is to simulate table locking by performing SELECT and UPDATE statements in a certain order.
In a MySQL database with MyISAM Tables there is a default priority for concurrent UPDATE and SELECT commands. To ensure that SELECT statements always retrieve the most up-to-date information, UPDATES have priority over SELECTs in the processing queue. On the other hand if a SELECT statement is already running when an UPDATE is in the queue, the UPDATE has to wait until the SELECT has finished.
And here our customer ran in trouble: When there was one very slow SELECT command followed by an UPDATE command on the same table, all other SELECT commands on this table had to wait until the long lasting SELECT command had finished. One idea to solve this problem is to duplicate tables: all fast SELECTs and all UPDATEs are performed on the master table. All slow SELECTs are performed on the SLAVE table. With this architecture and an intelligent replication mechanism we could solve the problem of our customer.
About us: We at PAGEmachine AG, are MySQL performance and TYPO3 specialists located near Frankfurt, Germany. Our emphasize lies on complex multi-national TYPO3 websites and database applications like application management systems and data warehouse systems.
For those who are searching Internet for information about the sphere of Public Relations for Small Business , then please check out the website that was mentioned in this line.










