Five optimized skills and timely optimization methods of UNIX [zt]

xiaoxiao2021-03-06  46

main content:

* Five optimization skills

* Timely optimization method

Timely adjustment:

Sometimes, you don't have time to understand some details: users and management makes you breathless, and you must solve a problem right away. Perhaps you are a backup system administrator, which day when your colleagues rushed into your public office, requiring improvement before the performance. Perhaps you are a system administrator who has set a contract requires a short directory to record some possible system errors. Maybe you have already read this book one page, find a concise reference manual, so you can leave those who filled with notes.

In this chapter, we will summarize two common but not simple questions: in order to determine and solve the problem of generally common performance, I should look at this section, what is optimized. In general, do I need to optimize in a new system to ensure optimization performance? Some warnings before we enter these themes.

Warning! This chapter contains some dangerous commands. It clarifies a lot of solutions and steps, but there is no explanation. As a result, it has taken the risk of turning you into a crane performance analyst (see the introduction of the second chapter) carefully.

Five primary optimization skills

When you see a systematic performance, there are five most basic questions to ask. Note --- If there is no particularly specified, all of these critical guidelines, their data is assumed to collect once every 30 seconds.

Where is the bottleneck of the hard disk?

Almost every running system is overloaded because of the I / O load of the disk. View the hard drive, if its service time is greater than 50 milliseconds, and more than a number of busy. The service time is actually called "response time", which measures a time interval that issues a read request to complete this request. This measurement is often performed on a critical path to the user's application. This is very likely - a serious overloaded disk response time will be calculated in milliseconds. (Not a printing error). On the Solaris system, you can get such information by command iostat -xnp 30.

# iostat -xnp 30

....

Extended Device Statistics

Statistics of expansion equipment

R / S W / S KR / S KW / S WAIT ACTV WSVC_T ASVC_T% W% B Device

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 C0T0D0S0

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 C0T0D0S2

0.7 2.7 5.3 9.5 0.0 0.1 0.0 16.1 0 2 C0T0D0S3

....

On the Linux system, install the optional packages containing the iostat command, check the columns of AWAIT.

# iostat -x -d 30

Linux 2.4.2-2 (aiua) 07/29/2001

....

Device: RRQM / S WRQM / S R / S W / S RSEC / S WSEC / S AVGRQ-SZ Avgqu-SZ AWAIT

SVCTM% UTIL

HDE 4.79 1.40 86.95 3.26 158.87 37.43 2.18 1.01 11.22

8.14 7.34

HDE1 0.00 0.00 82.15 0.00 82.15 0.00 1.00 0.46 5.64

5.64 4.63

HDE2 4.79 1.40 4.80 3.26 76.70 37.43 14.16 0.55 68.05

34.40 2.77

HDE5 0.00 0.00 0.00 0.00 0.02 0.00 8.00 0.00 100.00

100.00 0.00

HDG 9.85 2.36 36.69 5.20 371.85 60.86 10.33 8.60 205.22

45.61 19.11

HDG1 0.00 0.00 0.06 0.00 0.07 0.00 1.03 0.00 2.94

2.94 0.00

HDG2 9.85 2.36 36.63 5.20 371.78 60.86 10.34 8.60 205.54

45.68 19.10

....

Due to the fsflush command, the UFS file system sometimes has a very high service time, otherwise, the UFS file system is generally idle. Since the file system is basically idle, this is not a problem. But I have never seen this phenomenon on Linux systems. If this is a Solaris system, it has more than 512m memory, and the i node cache is big enough. However, on systems with a small memory, increasing the cache may help reduce the number of I / O operations required by file system management.

There is a basic technique that solves the disk I / O problem and as much as possible. These requirements can be achieved by investing in a non-volatile memory cache disk array by investing in a non-volatile memory cache disk array by porting some frequently accessible directories or files to other loads.

Do you have enough memory? On the Solaris system, there is an indicator to see if you miss memory, which is the sr field of the vmstat command. Remember that the first line of VMSTAT output is not significant. Other fields are largely useless for answering this problem. Especially in Solaris7 and earlier versions. There are a lot of misunderstandings about this point, two of which are very common.

The size of the idle list is not a logo that is missing memory, because the Solaris system will consume unused memory in order to cache the most recently used files. × The transfer of the page per second or the number of pages is a bad measure scale because the Solaris system processes the I / O operation of all file systems through the page mechanism. The transfer and tuning of thousands of pages of thousands K, means that the system is working.

Unfortunately, if you have become accustomed to viewing the output of the command VMSTAT on the Solaris7 system, the Solaris8 system changes its output. It can now display some relevant information appropriately: The page used by the file cache system is considered idle (because they are also actually). So everyone will now ask "Where is these idle memory?" And they ask "My idle memory in the Solaris7 system?"

One way to determine if you are missing memory remains the rate - Page Scanner Scan page to see if they have been released. If you miss memory if you are in Solaris7 or earlier, you should customize memory 250 pages per second. If you are on the Solaris8 system, any page scan activity means you missing memory.

Whether the processor is overloaded? The best measurement of whether the processor is overloaded is to view the length of the run queue. To view the length of the queue using the vmstat command and the value of the View Procs R field on the Solaris system and the Linux system. If this value is about four times greater than the number of processors, this value is likely to wait for a long time to get a time film.

If the number of mutex stalls (may be the SMTX field of the mpstate command on the Solaris system), (probably 250 times the number of processors), you should upgrade your central processor (CPU) to speed faster Not add more.

Is the process blocked by disk I / O? If a process is blocked, it is a sign of disk bottleneck. You can view the number of blocked processes through the procs b field of the vmstat command, and any process is blocked, then the system will report that all CPUs are idle because of waiting for I / O.

If the number of processes blocked or exceeds the number of processes in the run queue, there is a serious disk bottleneck, you should reuse the iostat command to see it. If you are managed by a system of batch processing, you will see a quite part of the blocked process. There is nothing to worry here, but to improve the performance of the disk subsystem is an indication, which will improve the throughput of your batch work. Is the system time dominated by the user? If any of the commands of the CPU time (VMSTAT, MPSTAT, etc.) show more CPU time by the kernel (system time) instead of using (user time) (user time), then you may encounter problems. The NFS (Network File System) server of the Solaris system is completely running in the kernel, just like Linux's optional package KNFSD, in this case, the system time is expected to dominate.

If the system being discussed is not an NFS (Network File System) server, it may be difficult to trace this problem. The best solution is to determine the primary numerous process based on the CPU's usage time (by using the PRSTAT, TOP or PS commands), then use a process tracking tool such as Truss to see what is issued. If the MUTEX Stall value is relatively high (the SMTX field of the mpstat command) you should start consider upgrading your central processor to a speed (but not adding the number of processor).

Timely optimization skills

This section introduces some of the skills of performance optimization. Of course, these recommendations are to deal with some general contexts, so you can make some modifications to them based on your own specific environment. For any machine, the best optimization skill is to use it as a server or a workstation, install the latest version of the operating system, and it is necessary to maintain a patch package. Installing performance patches is quite common, and sometimes it will have dramatic effects. Otherwise you will make you want to use a new set of operational rules in the old version of the operating system (for example, using the page priority to the Solaris system).

One of the most common optimization of the workstation of a single user's development environment is that a computer is used by a development user. Users like this require a relatively high performance for compilation and other tasks (which are closely related to processors and file system relationships), but these users may not have high speeds you expected on a large server. Disk.

File system

My preferred file system layout format is divided into two partitions into two partitions, one as a swap space, and one of the rest as other purposes. The SWAP partition should be divided on the partition of the disk above the disk. Why do you do this, please see the fifth chapter "Search for the file system through the layout of the file system". However, many people will not agree with my point of view, this topic is implicated to religious beliefs. If you are more A local disk, in order to uniformly distribute the load, you should configure a swap spatial partition on each disk. On the Solaris system, all file systems should be selected when they are mounted, thus when suddenly It is time to recover quickly. (See Chapter 5 "Log File System")

Mounted NFS

File System (Network File System) contains some basic non-changeable files, such as applications, to avoid accessing time of NFS write files should be hung into read-only state. If it is possible for you to the platform, you should also use the file cache system, cache the files that you want to use - is especially useful for the application directory. However, it is not because it is used to the mail directory, which may be useful for the primary directory, depending on the side focus of the file read and write operation. Any application generally needs a lot of write operations, so a cache file system should not be used. You can see more information about achieving cache file systems in Chapter 5, Cache File System '. Exchange Space

The size of the appropriate swap space is actually quite difficult. If you don't get a better suggestion from an application vendor, then configure at least 128M virtual memory. Using the exchange file is disordered than using the exchange partition, and the disk is also cheaper, and will never be damaged. Most desktop hosts will never take more than 512m paging memory.

Kernel optimization

Most operating systems have been configured with this aspect, so there is not much job in this way. We need to do it. In addition to one exception, if you are running in Solaris7 or earlier, you should

Open the page priority schedule by adding the following line below / etc / system plus. Open page priority scheduling settings in a version lower than Solaris 8, for a detailed explanation of page priority schedules, see Chapter 4, Page Priority Scheduling.

Working group server

In this part, we will consider a working group server as a whole to complete a wide variety of tasks. These tasks may include email services, file storage, lightweight mail services, etc. In a environment where only UNIX is only, the directory will be associated with the outside world; in a system environment using Samba's Windows network, we will have to support SMB / CIFS. This server may also be The primary agent buffer of this department's online browser also restarts any thin client, X terminal, or other computers with dependencies with the network. This system may connect to the Internet through some relatively fast Ethernet.

Mixed workload may grow significantly to NFS (network file system or samba).

The basic sending mail software provided by the Solaris system can support at least hundreds of users, but cannot exceed. If you want to do any optimization, if you need to support more users, you may exceed the scope of this workgroup server. But like IPlanet transmitter software products It takes more effective storage messages to support millions of users. The use of web servers may also become lightweight. The Ultrasparc-II of a single processor or the run 3 system can easily complete these tasks.

RAM

This type of work and memory have no special relationship: the largest active user program is probably sent, and the remainder of the main memory will be used as a buffer of the file system. Because due to client cache mechanism

Most files will only be requested once, so the file system cache does not need too much. Any program is more suitable for the client through the file cache system if it is frequently read frequently (for example, the application).

As a rough rule, the initial memory of 128M is configured for the system, and then increases about 64m of the system that is subjected to the system. If you support X terminals or Sun's array, you will need to increase approximately 128M for each terminal or an array machine. The client will run according to the workload (there is also a rule in the same way as you have added memory, you will increase memory at the client, which is at least 32M memory to each client).

Disk

In order to ensure the reliability of the data and the speed of writing as much as possible, the configuration of the hard disk involves two most important things. If you have a hardware device (such as Sun's StoredGe A1000), configure it into RAID1 0 or RAID 5 devices. Everything is more important to store the above content (you can refer to Chapter 6 "RAID Tips".). If you are configuring the software RAID, you will use the Dissuite logging option instead of the UFS logging option, the latter reduces the performance of the system. DISKSUITE-based logging file system should use a distributed disk with a speed of at least 7200. Hardware-based disk arrays can be safely histed with logging option status, and the written log content will be cached inside the fixed memory of the array control. In this configuration, you should mirror the system's disk. File system

I will create a separate, enough root partition, just like the skills mentioned in the Workgroup Server. However, / var should be distributed in a separate partition. It will need to accelerate write speed. These are not much associated with the log file system. Instead, we try to improve some of the performance, such as sending an email to the receiving box (a customer rewriting this mail file is an important disk operation when exiting) / var partition should be quite large, how big is With your way of use. Create a separate file system for the user's home directory.

Swap space

For this type of work, there should be no too much swap space. It is already enough for hundreds.

Optimized network file system

For network file system servers, there are three most important optimization changes: Make sure that you are using the NFS (network file system) of version 3, increase the number of threads of the network file system, and add TCP buffering on the Solaris system The size of the unit. The NFS (Network File System) of version 3 implements changes in the rule system, which significantly improves performance, especially for files. All of your client's NFS (network file system) should be huddled to their file system and set parameter vers = 3. You can use the nfsstat command to check whether any call on version 2 is performed on your server. For more detailed information, please see Chapter 7 "NFS (Network File System)". It is important to choose a suitable NFS (network file system) number of kernel threads. The ready-made default is acceptable, but of course it can't make your system to achieve performance optimization. In fact, you can adjust the parameters NFSD by editing this line /etc/init.d/nfs.server, 128 is a reasonable start value. / usr / lib / nfs / nfsd -a 128

On the Solaris system, you will need to increase the acceptance of TCP acceptance and transfer buffer, which is achieved by adjusting TCP_RECV_HIWAT and TCP_Xmit_hiWat. You will have to test some reasonable values. A good start value is set to 56KB (57344) with TCP_Xmit_hiwat, set TCP_RECV_LOWAT to 32KB (32768). To avoid adjustment (?) In the TCP zoom window (?), You should not set these values ​​to greater than 64,000 range. The Linux network server has the same meaning parameter value, but their default is large enough, and no adjustment is required. For more information, please see Chapter 7 "Cache, High Water Levels and Windows"

Kernel adjustment

You may want to increase the value of the variable maxphys variable, so that the kernel can allocate more consecutive films for the modified files that are not on the hard disk. You can see more about maxphys in Chapter 4, "Document Cache System and Hard Disk". If your Solaris system has implemented a network file system and less memory is less than 128m, you should add the size of the directory name addressing cache, and i node cache. You can see more information about cache on the "Directory Name Address Cache" and Chapter 5, "I Node Cache". Increases each variable to 8,000 is enough. × Low memory server improves DNLC and I node buffers

Set ncsize = 8000

Set UFS (UNIX File System) UFS_NINODE = 8000

In the Solaris8 version, you must open the page priority schedule. Please see the introduction of the single user workstation or the fourth chapter "page priority schedule"

Network Server

Rebuilding a web server to provide static content seems to be a clear tendency. A single UltrasParc-II or a high-performance Pentium 3 processor can easily give the 100M Ethernet segment to the static content, and the stability of at least 4 processor systems is also effective in efficient linearity. When the network develops a more dynamic media, however, the performance of the processor is more concerned. Unfortunately, there is no better rule to measure dynamic HTTP workloads only because the workload changes are so frequent.

RAM

The web server requires considerable memory in order to run fast, because they tend to play the performance when there is a maximum TCP cache, (when there are a lot of connections, TCP cache consumption is very fast) and A wide range of file system caching. As a rough criterion, I will use 256m as the starting value of the memory, then increase the uppercase of the file to probably satisfy 90% request (you can get this message by looking at the log file). These will give you enough memory to cache the most 'hot' page. The system before the Solaris8 version should open the priority schedule of the page. Please see Chapter 4 "Priority Dispatching"

Disk

For every large website or those that provide network services for many websites, disk storage has become a problem. A single-sided speed of 7,200 disk can support approximately 50 static HTTP operations per second, so you should calculate how many times each second is calculated when you plan to support and strip magnets until they reach the limit. Peak. RAID5 disk arrays are a quite a good choice. While maintaining good performance, they provide some fault-tolerant elastic mechanisms. (Mainly because the workload is just a tendency to read). In some busy websites, stripes and mirrors that contain the HTTP logs are necessary. These logs will grow very fast.

Especially in the peak of capacity.

File system

I still recommend creating a separate, big root partition, just like the recommendations mentioned in the Working Group Server section. However, as mentioned earlier, you should make sure you create a distributed file system for the HTTP log file.

At the same time take measures to improve the speed of writing. Whether mirror system hard drive, you decide yourself. In a large-scale installation system, the web server is a set of NETRA TLS, or a lightweight machine that is balanced, or a complete DNS entry. If your internal organization is established for it, the failure of a machine is not a big problem. You can only wait for this machine to be replaced, you can reload it through some automated tools. The actual content you are provided to the front desk is through the NFS (network file system) backup system through the E-mail server, which is best.

Swap space

Refamered again, the web server tends to do not need too much swap space. 512M should be sufficient, just like absorbing anonymous memory requirements it is not used. More detailed information, please see Chapter 4 "Anonymous Memory"

The network system determines that the size of the network has a little small skill. Here, we will focus on static operation. If your web server provides a lot of dynamic content services, you will need to summarize some method skills based on your own work. The purpose of Table 9-1 is to provide you with a rough way to adjust your network capacity. For example, if you have 1000 users dial-up through the 56K modem, you don't need to consider supporting more than 400 http operation per second. Conversely, if you try to support 1000 operations per second in a fast Ethernet connection, you may be destined to fail.

Table 9-1

NetWork Utilization for HTTP Clients HTTP Customer Network Tool

Network Connection Bandwidth Network Connection Bandwidth

(Per Second) peak static http operations / second (per second)

Static HTTP operation peak / second

56k Dialup 56 Kbps 0.4

ISDN 128 KBPS 1

768K SDSL

(Full-Duplex) 768 Kbps 5 (duplex)

T1 1.5 MB / SEC 10

Cable Modem 6 35 cable dialer

Ethernet 10 60 Ethernet

DS3 45 MB / SEC 300

Fast Ethernet Quick Ethernet

(Full-Duplex) 200 MB / SEC 600

Gigabit Ethernet

(Full-Duplex) 2,000 MB / Sec5,000

There are two questions about the performance of the web server, you should be very clear. The first is the safety socket (also known as secure HTTP) it is absolutely the performance of Kars. The number of HTTP operations that each processor can support is divided by 10. The new generation of hardware security socket acceleration card has entered the market. But for them, I have no experience, I can't give you a good suggestion.

The second question is that we should pay attention to the software product of the Solaris network cache accelerator. These products run in kernel space, which acts as a cache mechanism for (usually static) upcoming HTTP requests. This situation causes troubles from kernel copy requesting to user space, awakening web server applications. Save from the page in any cache (or bad disk) get the data and then return it to memory. The NCA product only puts the static web page in a single core cache, the transparent answer request, but the speed is much faster. A new generation of NCAs will might support the recovery of dynamic content. Another product with the same function is TUX, which is a high-performance web server for the kernel space Linux for a considerable part of the line. We must pay attention to that these products sometimes have a stability, so you will need to test them carefully before configuring them.

Kernel optimization

For incomplete connection queues and complete connection queues, you will might want to increase the default. In the Solaris system, two parameters of TCP_CONN_REQ_MAX_Q0 and TCP_CONN_REQ_MAX_Q, respectively, respectively, 1024 and 128 are their default values. This indication indicates that you should improve TCPListendrop and TCPListendropq0 variables to a relatively large value, they can be seen by command NetStat -sp TCP. Tcp_conn_req_max_q0 parameter should not be set to about 10,000, tcp_conn_req_max_q should not be exceeded provided tcp_conn_req_max_q0., And tcp_conn_req_max-q0 parameters have equal effect on Linux systems tcp_max_syn_backlog, which can be found in / proc / sys / net / ipv4 in . For more information on the connection queue, please see Chapter VII "Connection initialization and SYN flood"

You will also recall to improve TCP acceptance and send caches. On the Solaris system, it is controlled by TCP_RECV_HIWAT and TCP_XMIT_HIWAT. You will have to test some reasonable values, but I tend to raise TCP_Xmit_hiwat to 48kb (49, 152) to increase TCP_RECV_LOWAT to 32KB (32, 768). To avoid opening the TCP window scaling, you should not set these values ​​over 64,000. The Linux web server sets a more appropriate value to the value of the same role to a more suitable value, the system can get higher performance. Of course, you can also adjust according to your preference. For more details, please see the seventh chapter "Cache, High Water Level and Window" Special Situation: Proxy Server

The biggest difference between proxy servers and web servers is that proxy servers may have more write operations (because they write some cached pages to disk). Therefore, ideal configurations for a proxy server should include a cache and accelerate write impulse hard disk array memory. You can get a similar effect by using a distributed hard drive to get the transaction write log to the cache file system. For example, if you are configuring a fast UNIPROCESSOR proxy server, 8 9GB data disks, I bring the strip to 64m with 64M interlaced roots or some software RAID software. The remaining two will have a 128M partition to be mirrored and used to store log files. Don't put your other except for things outside the log on the disk of the storage log. It can be seen from a service time that even if they have excess storage space and throughput, these disks are quite busy.

转载请注明原文地址:https://www.9cbs.com/read-59599.html

New Post(0)