Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a simple stress test tool in PHP that creates a test table, loads 1000 entries into it, selects them then deletes them one by one. Run together with ab (apache benchmark), you can simulate an intensive load on your DB and compare how several servers perform. Save it as stress.php, update the connection information then run it from your browser:</p> <pre><code>&lt;pre&gt; &lt;?php $sStart = microtime(true); function random_str(){ $result=""; for ($i = 1; $i &lt;= 16; $i++) { $base10Rand = mt_rand(0, 15); $newRand = base_convert($base10Rand, 10, 36); $result.=$newRand; } return $result; } if ($_REQUEST['db']=='mon2') { mysql_connect ("server_test1", "db_user", "db_pass" || die (print 'no db'); } elseif ($_REQUEST['db']=='scooter') { mysql_connect ("192.168.33.3331", "umbrella", "umbrella") || die (print 'no db'); } elseif ($_REQUEST['db']=='camilla') { mysql_connect ("192.168.33.3332", "umbrella", "umbrella") || die (print 'no db'); } else { die (print 'no server'); } echo number_format(microtime(true) - $sStart, 2) ."s connect done\n";flush(); mysql_select_db ("test") || die (print 'no select_db'); $tbl_number=rand(1000, 9999); $query = "CREATE TABLE IF NOT EXISTS test_tbl_$tbl_number (test1 int(100) NOT NULL, test2 int(100) NOT NULL, test3 int(100) NOT NULL, test4 int(100) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;"; mysql_query($query) || die (print 'no query'); echo number_format(microtime(true) - $sStart, 2) ."s CREATE done\n";flush(); $aa=array(); for ($i=1; $i &lt;= 1000; $i++) { $a=random_str(); $aa[]=$a; $b=random_str(); $c=random_str(); $d=random_str(); $query="INSERT INTO test_tbl_$tbl_number SET test1='$a', test2='$b', test3='$c', test4='$d'"; mysql_query($query) || die (print 'no insert'); } echo number_format(microtime(true) - $sStart, 2) ."s INSERT (1.000) done\n";flush(); $query="SELECT SQL_NO_CACHE * FROM test_tbl_$tbl_number"; mysql_query($query) || die (print 'no select_db'); echo number_format(microtime(true) - $sStart, 2) ."s SELECT (1) done\n";flush(); foreach ($aa as $value) { $query="DELETE FROM test_tbl_$tbl_number WHERE test1='$value'"; mysql_query($query) || die (print 'no delete'); } echo number_format(microtime(true) - $sStart, 2) ."s DELETE (1.000) done\n";flush(); $query="DROP TABLE test_tbl_$tbl_number"; mysql_query($query) || die (print 'no drop'); echo number_format(microtime(true) - $sStart, 2) ."s DROP (1.000) done\n";flush(); ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload