The first thing to understand is two special devices:
/dev/null: Recycle Bin, bottomless pit
/dev/zero: Generating characters
Ø Test Disk Write ability
Time DD If=/dev/zero of=/test.dbf bs=8k count=300000
Because/dev//zero is a pseudo device that produces only a stream of empty characters and does not produce IO for it, IO is concentrated in the of file, and the of file is used only for writing, so this command is equivalent to the ability to write a test disk.
Ø Test Disk Read ability
Time DD IF=/DEV/SDB1 Of=/dev/null bs=8k
Because/DEV/SDB1 is a physical partition, the reading of which produces io,/dev/null is a pseudo device, the equivalent of a black hole, of which the device does not produce IO, so the IO for this command only occurs on the/DEV/SDB1 and is equivalent to the reading ability of the test disk.
Ø test simultaneous reading and writing ability
Time DD IF=/DEV/SDB1 of=/test1.dbf bs=8k
Under this command, one is the physical partition, the other is the actual file, the read and write to them will produce IO (/DEV/SDB1 is read,/TEST1.DBF is written), assuming they are all on a disk, this command is equivalent to the test disk's simultaneous reading and writing capabilities
Here are a few common DD commands to see the difference
DD bs=64k count=4k If=/dev/zero of=test
DD bs=64k count=4k If=/dev/zero of=test; Sync
DD bs=64k count=4k If=/dev/zero of=test Conv=fdatasync
DD bs=64k count=4k If=/dev/zero of=test Oflag=dsync
The four DD commands differ in how memory write caching is handled.
1.
DD bs=64k count=4k If=/dev/zero of=test
No parameters are added, dd default does not include the sync (sync) command. That is, the DD command did not allow the system to actually write files to disk before it was completed. So the above commands simply read the 128MB data into the memory buffer (write cache). So what you get is going to be a super fast speed. Because in fact, DD gives you only read speed, until the DD is finished, the system began to actually write data to disk, but this speed you can not see. So if it's fast, it's not going to work.
Actual operation Result:
268435456 bytes (268 MB) copied, 1.3529 seconds, 198 MB/s
2.
DD bs=64k count=4k If=/dev/zero of=test; Sync
Exactly the same as in the previous 1. Separated by semicolons are only two separate commands. When the sync command is ready to start actually writing data to disk, the previous DD command has displayed the wrong "write speed" value on the screen. So you still can't get the actual write speed.
Actual operation Result:
268435456 bytes (268 MB) copied, 0.522815 seconds, 513 MB/s
3.
DD bs=64k count=4k If=/dev/zero of=test Conv=fdatasync
When this parameter is added, the DD command performs a "sync" operation at the end, so this time you get the time required to read the 128M data to memory and write to the disk, so that the calculated time is more consistent with the actual results.
Actual operation Result:
268435456 bytes (268 MB) copied, 2.8046 seconds, 95.7 MB/s
4.
DD bs=64k count=4k If=/dev/zero of=test Oflag=dsync
When this parameter is added, the DD writes synchronously every time it executes. That is to say, this command writes 64k to the disk each time after reading 64k, and then reads the following 64k, altogether repeats 128 times. This may be the slowest way, because write caching is largely not used.
Actual operation Result:
268435456 bytes (268 MB) copied, 3.40069 seconds, 78.9 MB/s
In general, the fourth method is the most stringent, you can simulate the insert operation of the database, so very slow, but also used to test the performance of the VPS hard drive a benchmark, in general, test results, if more than 10M, the normal station will have no effect. More than 50M, is very give the state, see this VPS hard disk performance is very good, dd speed reached the 78.9mb/s.
In these commands, bs=64k represents a block size of 64k bytes for simultaneous read/output, count=4k indicates that the number of copy blocks is 4,000, and if the test is more rigorous, we run the 1G data volume of DD:
DD If=/dev/zero of=test bs=64k count=16k Oflag=dsync
Indicates that each block size is 64k bytes, the test 16k number of blocks, the actual test results:
1073741824 bytes (1.1 GB) copied, 18.9098 seconds, 56.8 MB/s
To write here, I think the use of the DD command to test the hard drive should be very clear, usually we test with the fourth command can, of course, DD faster and can not represent the performance of the server, the normal hard disk of the server to execute the DD command results in about 30M is good, in addition, the implementation of the DD command The damage to the hard disk is very large, not recommended many times or long time to try!
Example
The first thing to understand is two special devices:
/dev/null: Recycle Bin, bottomless pit
/dev/zero: Generating characters
Time has a timing effect, DD is used for copying, reading from If, and writing to. If=/dev/zero does not produce IO, so it can be used to test pure write speed. Similarly of=/dev/null does not produce IO, which can be used to test the pure read speed. BS is the size of each read or write, that is, the size of a block, and count is the number of read-write blocks.
To measure the pure write speed of the disk on which the/data directory resides:
[Root@nagios ~]# time DD If=/dev/zero of=/var/test bs=8k count=1000000
1000000+0 Records in
1000000+0 Records out
8192000000 bytes (8.2 GB) copied, 52.5749 seconds, 156 MB/s
Real 0m55.841s
User 0m0.507s
SYS 0m15.706s
# #红色部分是因为使用了time命令才显示的, so the time command is required to calculate the replication times.
To measure the pure read speed of the disk on which the/data directory resides:
[Root@nagios ~]# time DD if=/var/test of=/dev/null bs=8k
1000000+0 Records in
1000000+0 Records out
8192000000 bytes (8.2 GB) copied, 49.0088 seconds, 167 MB/s
Real 0m49.025s
User 0m0.559s
SYS 0m6.383s
Read and write Speed:
[Root@nagios ~]# time DD if=/dev/zeroof=/tmp/test bs=64k
125000+0 Records in
125000+0 Records out
8192000000 bytes (8.2 GB) copied, 129.239 seconds, 63.4 MB/s
Real 2m9.251s
User 0m0.114s
SYS 0m21.494s
Looks like the test results are good, hehe.