Install Linux centos 64-bit on vmware
When xshell is installed, it can be used to access servers in different remote systems on the Windows interface, so as to achieve the purpose of remote control terminal. Basic commands CD (cutting directories), ls (viewing directories), cp (copying directories), rm (deleting directories), ipconfig, hostname, firearm-cmd (firewall), vim (creating and opening a file), touch (creating a file), cat (viewing file contents), tail (viewing log files), zi p/unzip
#uptime, #w, and # TOP can view the average CPU load
Load Average: three numbers of loads, such as 4.86, 5.28, and 5.00 in the figure above, respectively represent the Average Load of the system in the past 1 minute, 5 minutes, and 15 minutes. A single-core CPU is loaded when it exceeds 1. The cat/proc/cpuinfo | grep “model name” can view the CPU and auditing. CPU load. = CPU utilization
CPU load is high and utilization is low
This indicates that there are many tasks in the wait state, possibly many dead processes. Typically, this is an IO – intensive task, where a large number of requests request the same IO, resulting in a backlog of tasks.
Then run the ps-axjf command to check whether there is a process in the D+ state, which is the process in the uninterruptible sleep state. A process in this state cannot be terminated or quit by itself. It can only be resolved by restoring its dependent resources or restarting the system.
Low load, high utilization
The CPU doesn’t have a lot of tasks, but the tasks take a long time to execute, most likely because the code you write itself has a problem, usually computationally intensive tasks, resulting in a lot of short computation tasks.
Just use the top command to find the most used tasks and go there
If the CPU usage reaches 100%
Top-hp PID Indicates the ID of the thread with a high CPU usage
Convert the thread ID to hexadecimal, printf “0x%x\n” 958, and get the thread ID0x3be
Jstack 163 | grep ‘0 x3be – C5 – color or jstack 163 | vim + / 0 x3be – find problematic code
Zero copy
read(file, tmp_buf, len);
write(socket, tmp_buf, len);
Copy the code
Traditional file transfers take four copies of the data, and there is no need to “copy from the kernel’s read buffer to the user’s buffer, and from the user’s buffer to the socket’s buffer”. Since the file transfer scenario does not “reprocess” data in user space, the data does not actually need to be moved to user space, so there is no need for user buffers to exist. There were four user-kernel context switches because two system calls were made,
- In order to reduce this overhead, we can replace the read() system call function with mmap(). The mmap() system call function “maps” the data in the kernel buffer directly to user space, so that there is no need to do any data copying between the operating system kernel and user space. And you still need four context switches because you still need two system calls. Three data copies are performed
2. In Linux kernel version 2.1, a system call function sendFile () is provided for sending files. The first two parameters of sendFile () are the file descriptors of the destination and source respectively, and the last two parameters are the offset of the source and the length of the replicated data. There are two context switches and three data copies. Since version 2.4 of the Linux kernel, the sendFile () system call process has been changed in cases where sG-DMA is supported. This process does not require copying data from the operating system kernel buffer to the socket buffer, thus reducing the need for a data copy.
However, this method is not suitable for large files, which use asynchronous I/O
Computer Fundamentals
Article source: mp.weixin.qq.com/s/24vBHgtw5… Love c c!