An insert query is constantly getting logged in my MySQL slow query log.
I want to see how much time the INSERT query is taking with 100 simultaneous insert operations(to the same table).
So I need to simulate the follwoing.
500 different simultaneous connections from PHP to the same database on a mysql server, all of which are inserting a row(simultaneously) to the same table.
DO I need to use any load testing tool? Or Can I simply write a PHP script to do this?
Any thoughts?
PS: I am using apache on windows.
If you've installed apache on windows, you should have the apache benchmark tool (ab.exe). Create your php script to insert a row and make it accessible via: http://127.0.0.1/insert.php. Test 100 concurrent connections by running this ab command:
ab.exe -n 100 -c 100 http://127.0.0.1/insert.php
That should run those 100 inserts simultaneously via your php script.
Are you using PHP5.3 ?
The new MySQL driver (mysqlnd) can handle parallel queries.
Try this :
<?php
$query = "SELECT 'test'";
$all_links = array();
for($i=0; $i<100; $i++) {
$link = mysqli_connect();
$link->query($query, MYSQLI_ASYNC);
$all_links[] = $link;
}
$processed = 0;
do {
$links = $errors = $reject = array();
foreach ($all_links as $link) {
$links[] = $errors[] = $reject[] = $link;
}
if (!mysqli_poll($links, $errors, $reject, 1)) {
continue;
}
foreach ($links as $link) {
if ($result = $link->reap_async_query()) {
print_r($result->fetch_row());
mysqli_free_result($result);
$processed++;
}
}
} while ($processed < count($all_links));
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