And why actually write performance tests in php? You can make a simple benchmark literally in a minute right in the terminal window by writing a simple script for bash:
while :; do ps waux | grep mysql| grep -v grep >> mysql_benchmark.log; sleep 3; done
Here an infinite loop starts, which calls the ps
command with options, grep
filter the necessary process from the list and redirect the result to a file. It’s not hard to guess that ps
run every 3 seconds until you press CTRL + C.
After running the above command, you give the server a load (with pens or another script). After the end of the work you stop the script.
It's time to analyze the resulting log file. The most interesting columns for us are the third (% CPU - how many percent of the processor mysql consumed), the fifth (VSZ - how much virtual memory our experimental person took) and the sixth (RSS - how many real memory pages the process ate). The description of all columns needs to be looked in man ps
.
$ cat mysql_benchmark.log | awk '{print $3, $5, $6}' 0.0 1979852 32376 0.0 1979852 32376 0.0 1979852 32376 и ещё много циферок...
After the filter CPU became the first, VSZ - the second, and RSS - the third column. As you can see, the mysql process is asleep and eats little memory. Large VSZs can often be scored on 64-bit boxes, since each process has its own address space and is virtual.
The main thing is to look at the CPU and RSS. If the CPU is close to 100% during the test, it will not hurt to buy the processor more powerfully, if RSS mysql is large and close to the total memory on the machine, the system will soon start to push unnecessary processes into the swap, and then kill the fattest processes. At the same time, mysql is the first candidate to kill, by strange default. This is solved conceived by the purchase of memory strip.
If mysql uses too little memory and is slow, then most likely you need to tweak a number of settings in mysql.conf for the storange engines used. Here this report can be useful in this question.
It still does not prevent me from trying to measure the amount of I / O on the hard disk and the network interface, but this is not so simple, and that is another story. An indirect sign of the people: if the brakes are observed - most likely, there is an active I / O, and most likely on the hard disk. For normal operation of the entire application, it is necessary that the amount of hot data does not exceed the amount of memory allocated for mysql.
I would also add that before the test, it is desirable to let the whole system " warm up " for a few minutes - just use your application without measurements, so that everyone can read the most frequently used data from the disk into RAM.
A similar simple technique has been used more than once for simple benchmarks of various applications: mysql, apache, server-side Python-processes. It works even in Windows :) But there are used batch file and some other utilities.