Original: https://www.cnblogs.com/leeSmall/p/9310907.html

I. Basic concepts

1. Quality characteristics of software system

Security: The ability to provide services to legitimate users while preventing unauthorized use of software and resources.

Robust and reliable: the ability, fault tolerance and recovery of the software system within a certain period of time

Extensible, maintainable, portable: How easy it is for an operating software system to adapt to new, changing requirements

Availability, ease of use, and performance: Performance refers to the ability of software to provide services in a timely manner. Specifically, performance includes the requirements of speed, throughput and sustained high speed.

2. Definition and performance of performance

Definition: how quickly to give users the results they want; Fluency and less resource footprint are two main aspects

Performance: Some pages load for more than 3 seconds, which will affect the user experience, thus losing users, so the sooner our business calculation results come out, the better

Second, the scope of performance optimization

Range of 1.

(1) Scope of hardware environment

Single machine: CPU, memory, disks, and network Multi-machine: storage architecture, network architecture, and application architecture

(2) Scope of software environment: JVM, TOMCAT, database, software system (our program code) can be optimized

(3) Application scenarios

Computing intensive, centralized resource usage IO intensive, distributed resource utilization

Note: We programmers generally focus on the performance optimization of the software environment, but the premise is that the hardware environment is not too harsh, for example, our software startup needs 512M memory, the result of the hardware environment only 128M memory, so even how to optimize is not up to the requirements

2. Performance is balance

That is, to provide the best access and processing speed with limited resources. The barrel principle: find the worst bottleneck, improve the overall efficiency. Consider throughput and response speed.

3. Tuning is tailored

Improve applicability according to different scenarios. Such as: the response speed of the front desk, the statistical results of the background. The former requires limited user patience, while the latter requires rich data analysis.

4. Some terms for performance tuning

QPS: indicates the number of queries per second

TPS: number of transactions per second

Throughput: The amount of data successfully transmitted per unit time

Response time: the time between the user request and the user receiving the result.

Performance bottlenecks

Network IO, blocking IO is the biggest problem

Network: bandwidth problems and CDN problems. When we conduct performance optimization, we should first check whether bandwidth and CDN problems are caused

6. Operation and maintenance monitoring

1. Understand basic o&M commands and how to use them

1.1 the top

Note: Using the top command, you can display the running program process. The permission is for all users. Press q to exit

Format: top [-] [d delay] [q] [c] [S] [I] [n]

Main parameters:

D: Specifies the update interval, in seconds.

Q: There are no delayed updates. If the user has a superuser, the top command will be executed in the highest order.

C: Displays the complete process path and name.

S: Cumulative mode, which accumulates CPU time for completed or missing sub-trips.

S: Safe mode.

I: No Idle or Zombie trips are displayed.

N: Displays the number of updates. After the updates are complete, the system exits top.

Command diagram:

The first line shows the current time, the system running time, the number of users currently logged in to the system, and the system load average of 1, 5 and 10 minutes. (Generally speaking, this load value should not exceed 1, unless your system is busy. If it stays above 5,….. Take a closer look at which program is affecting the overall system! .

The second line shows all started, currently running, Sleeping, and Zombie processes. The last zombie number is not zero. Take a closer look at which process has become a zombie. !). (Stop mode: it should be different from sleep, which actively abandons CPU, while stop is passive abandons CPU. For example, step tracking, stop (pause) process cannot return to the running state by itself.)

The third line shows the current CPU usage, The CPU usage of the US user space, THE SY kernel space, the CPU usage of the NI user process space whose priority has changed (interrupt processing), the idle CPU usage of id, the CPU time of WA waiting for input and output, hi, SI, and ST are not clear 🙂

The fourth line shows the physical memory usage, including total available memory, used memory, free memory, and memory occupied by buffers.

The fifth row shows swap usage, including total swap, used, free, and cache sizes.

The sixth line shows the most items, as explained below.

PID (Process ID) : Process identifier (ID of each Process)

USER: The USER name of the process owner (the USER to which the process belongs)

PR: the Priority level of a process (short for Priority, the order in which a program is first executed, the smaller it is, the sooner it is executed)

NI: The value of the Priority level of a process (short for Nice, related to Priority, also the smaller the sooner it is executed)

VIRT: indicates the virtual memory occupied by a process.

RES: physical memory occupied by the process.

SHR: shared memory value used by the process.

S: indicates the status of the process, where S indicates dormant, R indicates running, Z indicates dead, and N indicates that the priority value of the process is negative.

%CPU: indicates the CPU usage of the process.

%MEM: The percentage of physical memory and total memory occupied by the process.

TIME+ : total CPU TIME occupied by the process after it started (the sum of CPU usage TIME)

Command: the name of the Command used to start the process. If this line is not displayed, the process will have a complete Command line.

When using the top command, you can also use some interactive commands to complete the functions of other parameters. These commands are initiated by shortcut keys.

< space > : Refresh immediately.

P: Sorted by CPU usage.

T: Sort by time and accumulated time.

Q: Exits the top command.

M: Displays memory information.

T: Displays the process and CPU status.

C: Switch to display the command name and complete command line.

M: Sort by memory usage.

W: Writes the current Settings to the ~/.toprc file. This is the recommended way to write a top configuration file

1.2 free

Note: Using the free command, you can display the memory usage. The permission is for all users.

Format: free [| | – k – b – m] [-] o [-s delay] [-t] [V]

Main parameters:

– b-k-m: displays the memory usage in bytes, KB, and MB.

-s delay: displays the memory usage every seconds.

-t: displays the total memory column.

-o: does not display the buffer adjustment column.

Example:

The free command is the main command used to check memory usage. Compared to the top command, it has the advantage of being simple to use and consuming few system resources. With the -s parameter, you can use the free command to continuously monitor how much memory is being used, which can be used as a convenient real-time monitor.

# free – h – s5

1.3 df

The df command is used to check the disk usage of the file system on the Linux server. You can use this command to obtain information such as how much disk space is occupied and how much space is left. If no file name is specified, the space of all currently mounted file systems will be displayed. By default, disk space is displayed in 1KB bits.

Format: DF [option] [file]

Command parameters:

-a List of all file systems

-h Facilitates reading

-i Displays node information

The -k block is 1024 bytes

-l Displays only local file systems

The -m block is 1048576 bytes

-p The output format is POSIX

-t Indicates the type of the file system

Example:

The first column of the output list of the df command in Linux is the path name of the device file corresponding to the file system represented (usually the partition on the hard disk). The second column gives the number of blocks. The third and fourth columns represent the number of data blocks used and available, respectively. Users may be surprised that the two do not add up to the total number of data blocks, because each partition has space reserved for administrator use. Even if the normal user space is full, the administrator still has space to log in and resolve problems. The last column is the mount point of the file system.

1.4 the du

Note: The du command views and calculates the size of a directory

1.5 Viewing Log Analysis

The cat/var/log/message, cat/var/log/nginx/access. The log, the cat/var/log/tomcat

2. Other o&M monitoring software

Stat series: vnstat, iostat, and vmstat

Three, processing mode

1. Tune the sequence

Find bottlenecks from bottom up, the order is server optimization – environment optimization – database optimization – application system optimization

2. Improve hardware capabilities

Goals: Buy the best machine, use the most expensive Internet, and pick up the most beautiful women

2.1 Hardware Ratio

CPU to memory ratio, 1:2 or 1:4 disk space and partitions, multiple disk (100G) file system format and tuning. Ext4

2.2 Network Bandwidth

5M bandwidth for the public network and Intranet bandwidth for 1000 users.

2.3 System Environment

Nginx, install and configure Tomcat Mysql.

3. Improve the system processing capability

Objective: to install high-performance software, ensure security, and optimize server configuration

Install high-performance software:

WEB application server Nginx Tomcat

Guarantee security:

Firewall, Centos comes with, generally do not start selinux, use VPS to set

Server configuration optimization: Network configuration optimization connection number ipv6

4. Install the server environment

Nginx: Improve the Tomcat static file processing capability, load balancing, reverse proxy Centos environment, install server software, unified using yum

Yum install nginx

Yum install java-1.8.0-openjdk.x86_64

Yum install tomat

Yum install mariadb

5. Configure the server environment

Nginx server configuration directory: /etc/nginx/conf.d/


Four, server processing methods

1. Optimize server environment

Network optimization, security configuration, user group permissions, and directory planning

2. Perform routine server monitoring

Command:

Top Command Free command Df command

Tool: Xshell Connects to the Linux operating interface Filezilla Upload files to the Linux server. The tool is similar to that used by XFTP or winscp