I / O tuning of Linux server performance tuning

Time:2021-2-27

1. The number of files that the process can open (commonly used in high concurrency)

ulimit -n

View the number of files a process can open

The maximum number of files that can be opened by the modify process

Temporary modification:

Ulimit – n [number of processes]

Permanent modification: modify restricted user resource profile

vim /etc/security/limits.conf

Add at the end

  • soft nofile 102400
  • hard nofile 102400

———————————————————————————————————————————

2. The maximum number of processes that the user can open (commonly used in high concurrency)

ulimit -u

View the maximum number that the current user can open

Modify the maximum number of processes that the current user can open

Temporary modification:

Ulimit – u [number of processes]

Permanent modification: modify restricted user resource profile

vim /etc/security/limits.d/90-nproc.conf

Add at the end

  • soft nproc 102400
  • hard nproc 102400

———————————————————————————————————————————

3. View I / O resource limits

ulimit -a

I / O tuning of Linux server performance tuning

———————————————————————————————————————————

Need C / C + + Linux server architect learning materials plus Qun (563998835) (materials include C / C + +, Linux, golang technology, nginx, zeromq, mysql, redis, fastdfs, mongodb, ZK, streaming media, CDN, P2P, k8s, docker, TCP / IP, coprocessor, dpdk, ffmpeg, etc.), free sharing

I / O tuning of Linux server performance tuning

4. I / O tuning example

————————–I / O tuning example————————————-

[ [email protected] ~]#Yum install – y httpd / / install Apache test

[[email protected] ~]# echo Test > /var/www/html/index.html

[[email protected] ~]# service httpd restart

[[email protected] ~]# ab -n 2000 -c 2000 #http://192.168.1.63/index.html//- n represents the amount of concurrency each time and – C represents the total number sent

This is ApacheBench, Version 2.3 <$Revision:** 655654 **$>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.63 (be patient)

socket: Too many open files (24)

If the limit is exceeded, we cannot open our HTML file. The solution is as follows:

vim /etc/security/ limits.conf //Restrict user resource profiles

*Add these two lines at the end of soft nofile 102400

* hard nofile 102400

Note: soft is a warning value, while hard is a real threshold value. If it is exceeded, an error will be reported. Soft must be smaller than hard.

Boot system: reboot, the disadvantage of permanent effect, must restart the system

reboot

restart

service httpd restart

ab -n 2000 -c 2000 http://192.168.1.63/index.html

……

Server Software: Apache/2.2.15

Server Hostname: 192.168.1.63

Server Port: 80

Document Path: /index.html

Document Length: 5 bytes

……

———————————————————————————————————————————

5. Hard disk speed test

Execute read / write command to test hard disk speed

First understand two special equipment before use

/Dev / null pseudo device, recycle bin. Writing this file will not generate IO overhead

/Dev / zero pseudo device, will produce empty character stream, read the file will not produce IO overhead

[[email protected] ~]# dd if=/dev/zero of=/test.dbf bs=8K count=30000

3000+0 records in

3000+0 records out

24576000 bytes (25 MB) copied, 5.13755 s, 4.8 MB/s

Generate a 25m file, IO write speed is about 4.8 MB / s

Of course, this speed can be tested several times to get an average, in line with probability statistics

usetimeThe command is used to execute the following commands and time them

[[email protected] ~]# time dd if=/dev/zero of=/test1.dbf bs=8k count=3000

3000+0 records in

3000+0 records out

24576000 bytes (25 MB) copied, 1.04913 s, 23.4 MB/s

real 0m1.061s

user 0m0.002s

sys 0m0.770s

1) Real time: the elapsed time from the start of the command line to the end of the run;

2) User CPU time: the user CPU time spent on command execution, that is, the sum of command execution time in user mode;

3) System CPU time: the system CPU time spent on command execution, that is, the total execution time of the command in the core state of mind.

Among them, the sum of user CPU time and system CPU time is CPU time, that is, the sum of CPU execution time occupied by commands. The actual time is greater than the CPU time, because Linux is a multitasking operating system, often in the execution of a command, the system has to deal with other tasks.

Another problem that needs to be noticed is that even if the same command is executed each time, the time spent is different, which is related to the operation of the system.

Using hdparm tool to test hard disk speed

hdparm -T -t /dev/sda

I / O tuning of Linux server performance tuning

-t perform device read timings

Without using the pre data buffer, it indicates how fast the disk can support continuous data reading without any file system overhead under Linux, which can be understood as reading the hard disk

-T perform cache read timings

The speed at which data is read directly from the cache in memory. In fact, it shows the throughput of processor cache and memory of the system under test, which can be understood as reading memory