performance tuning

What is performance tuning?

computer architecture
As shown in the figure above, it includes three parts: hardware, operating system, and applications. In fact, performance tuning is to adjust these contents, including hardware, operating system, and applications.

Hardware includes: CPU, memory, disk, network card, other...,
operating system includes: process, virtual memory, file system, network, other...,
application: Apache, MySQL, Nginx, Memcahed, etc. are common.

So what is performance tuning?

Performance tuning is to have a fairly in-depth understanding of computer hardware, operating systems and applications, adjust the relationship between the three, maximize the performance of the entire system (including hardware, operating systems, and applications), and continuously meet existing requirements. business needs.

Why do you need performance tuning?

One is to obtain better system performance (that is, your existing system runs well, but it can run better if you optimize it).
Second, it is through performance tuning to meet the ever-increasing business needs

Where do you need performance tuning?

1. Hardware selection (select the server according to the server application type)
2. The operating system adjusts the system parameters
3. Components (Nginx, MySQL, etc.)
4. Code

How to perform performance tuning?

  • Performance Metrics –> Confirmation Metrics
  • Performance testing –> Verify performance metrics
  • Performance analysis -> find performance bottlenecks
  • Performance Tuning -> Solve Performance Issues
  • Performance monitoring –> check the tuning effect

Performance

Generally, there are three indicators to measure a project (here refers to a website):

  • Throughput –> is the number of user or system requests completed per unit time.
  • Concurrency –> How many user access requests can be accepted at the same time
  • Response Time –> The time interval between the user sending the request and receiving the response.

performance analysis

1. Look at the CPU utilization first. If the CPU utilization is not high, but the Throughput and Latency of the system cannot go up, it means that our program is not busy with calculation, but with other things, such as IO.

2. Then, we can look at the size of IO. IO and CPU are generally reversed. If the CPU utilization is high, the IO is not large, and if the IO is large, the CPU is small. Regarding IO, we need to look at three things, one is the disk file IO, the other is the driver's IO (such as: network card), and the other is the memory paging rate. All three things can affect system performance.

3. Then, check the network bandwidth usage. In Linux, you can use the commands iftop, iptraf, ntop, tcpdump to check.

4. If the CPU is not high, the IO is not high, the memory usage is not high, and the network bandwidth usage is not high. But the performance of the system does not go up. This indicates that there is a problem with your program, for example, your program is blocked. It may be because of which lock to wait for, because of waiting for a resource, or because of switching contexts.

performance monitoring

CPU usage CPU load memory usage Disk I/O Network traffic disk space system process

Hardware selection

Hardware selection is to choose the hardware foundation that is most suitable for your application to run under limited resources (money). (It doesn't matter if you are a local tyrant, it is always good to be expensive anyway).
So how to choose hardware? In fact, it depends on the applications or components installed on the server.

  • If you say it is to install a simple application to play. It only needs to buy to run the application, and that's it.
  • If you want to install Mysql, the focus is on the number of revolutions of the disk, and the cpu is normal.
  • If you want to install a cache, such as Memcache, the focus is on the memory size, and the cpu is normal (the cache may also need a good network, which depends on the bottleneck of your application)
  • If you want to install a computing application, the focus is on the cpu. Generally, 4G memory is enough.

In general, it is: what the application or component depends on, then we spend more money and match it. No need for rich oil, just enough

The operating system adjusts the system parameters

Operating system Linux, windows, why should these be tuned? Because operating systems are not designed for you, but for most people. It has to be adapted to the public in order to be popularized.

Not very proficient in this one. Here's what I've adjusted

system handle

Linux has a file handle limit, usually 1024. In fact, it is easy to reach this number
for encountered these errors
java.lang.OutOfMemoryError: Unable to create new native thread
Can't open so many files
too many open files

  • View the number of handles currently in use
cat /proc/sys/fs/file-nr
  • Set handle to user
vi /etc/security/limits.conf

*   soft noproc   65535  
*   hard noproc   65535  
*   soft nofile   65535  
*   hard nofile   65535 
说明:* 代表针对所有用户 
noproc 是代表最大进程数 
nofile 是代表最大文件打开数
修改完重新登录就可以见到,使用 ulimit -a 查看确认
  • system level handle
//用户句柄不能超过系统句柄
sysctl -w fs.file-max 65536 
或者 
echo "65536" > /proc/sys/fs/file-max
或者
echo "fs.file-max = 65536" >> /etc/sysctl.conf

swap area

Swap space is a piece of disk space. The operating system uses this space to save page data that is not commonly used by the operating system swapped out of memory, so that more memory can be allocated for page cache. This usually improves the throughput and IO performance of the system, but also creates many problems. Frequent swapping in and out of pages will cause IO read/write and operating system interruptions, all of which affect system performance.

So it is best to close it when there is sufficient memory

swapoff -a

components

Components are the key to supporting application performance, so the selection of components and configuration parameters are very important

optional components

Under the strong open source community, there are many choices for components in different parts. For example, the cache has memcache, redis, tair, aerospike, etc., we are dazzled. In fact, they have different characteristics. I believe that developers are reluctant to build wheels repeatedly. They each have their own suitable scenarios. And you choose them based on the scenarios you face.

Here are the steps I took to select the components

1. Clearly understand the scene you are facing
2. Extract keywords according to the scene and go to google search. (Because my knowledge is not broad enough, I do n’t know what components are there)
3. Go to the official website to check their advantages and disadvantages , and deliberately mark the shortcomings as black, the most likely places to step on the pits
4. Reduce the scope of components 6. In-depth understanding
of the official website of Dongxi

application code

The quality of code writing also directly affects performance, which depends on experience and hands-on testing

//哈哈,这段代码有什么问题吗?
public String test(List<String> list){

    for( int i =0 ; i < list.size ; i++ ){
        if("test".equale(list.get(i)){
            return list.get(i);
        }
    }
    return null;

}

JVM tuning

The tuning of jvm mainly depends on the frequency of gc. This will not be discussed. There are many online

code tuning

Depending on your code skills, practice is king.

Locating performance issues

System consumption analysis

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325768257&siteId=291194637