]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/doc/papers/sysperf/2.t
MFV r309587:
[FreeBSD/FreeBSD.git] / share / doc / papers / sysperf / 2.t
1 .\" Copyright (c) 1985 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)2.t 5.1 (Berkeley) 4/17/91
29 .\"
30 .ds RH Observation techniques
31 .NH
32 Observation techniques
33 .PP
34 There are many tools available for monitoring the performance
35 of the system.
36 Those that we found most useful are described below.
37 .NH 2
38 System maintenance tools
39 .PP
40 Several standard maintenance programs are invaluable in
41 observing the basic actions of the system.  
42 The \fIvmstat\fP(1)
43 program is designed to be an aid to monitoring
44 systemwide activity.  Together with the
45 \fIps\fP\|(1)
46 command (as in ``ps av''), it can be used to investigate systemwide
47 virtual memory activity.
48 By running \fIvmstat\fP
49 when the system is active you can judge the system activity in several
50 dimensions: job distribution, virtual memory load, paging and swapping
51 activity, disk and cpu utilization.
52 Ideally, to have a balanced system in activity,
53 there should be few blocked (b) jobs,
54 there should be little paging or swapping activity, there should
55 be available bandwidth on the disk devices (most single arms peak
56 out at 25-35 tps in practice), and the user cpu utilization (us) should
57 be high (above 50%).
58 .PP
59 If the system is busy, then the count of active jobs may be large,
60 and several of these jobs may often be blocked (b).  If the virtual
61 memory is active, then the paging demon will be running (sr will
62 be non-zero).  It is healthy for the paging demon to free pages when
63 the virtual memory gets active; it is triggered by the amount of free
64 memory dropping below a threshold and increases its pace as free memory
65 goes to zero.
66 .PP
67 If you run \fIvmstat\fP
68 when the system is busy (a ``vmstat 5'' gives all the
69 numbers computed by the system), you can find
70 imbalances by noting abnormal job distributions.  If many
71 processes are blocked (b), then the disk subsystem
72 is overloaded or imbalanced.  If you have several non-dma
73 devices or open teletype lines that are ``ringing'', or user programs
74 that are doing high-speed non-buffered input/output, then the system
75 time may go high (60-80% or higher).
76 It is often possible to pin down the cause of high system time by
77 looking to see if there is excessive context switching (cs), interrupt
78 activity (in) or system call activity (sy).  Long term measurements
79 on one of
80 our large machines show
81 an average of 60 context switches and interrupts
82 per second and an average of 90 system calls per second.
83 .PP
84 If the system is heavily loaded, or if you have little memory
85 for your load (1 megabyte is little in our environment), then the system
86 may be forced to swap.  This is likely to be accompanied by a noticeable
87 reduction in the system responsiveness and long pauses when interactive
88 jobs such as editors swap out.
89 .PP
90 A second important program is \fIiostat\fP\|(1).
91 \fIIostat\fP
92 iteratively reports the number of characters read and written to terminals,
93 and, for each disk, the number of transfers per second, kilobytes
94 transferred per second,
95 and the milliseconds per average seek.
96 It also gives the percentage of time the system has
97 spent in user mode, in user mode running low priority (niced) processes,
98 in system mode, and idling.
99 .PP
100 To compute this information, for each disk, seeks and data transfer completions
101 and the number of words transferred are counted;
102 for terminals collectively, the number
103 of input and output characters are counted.
104 Also, every 100 ms,
105 the state of each disk is examined
106 and a tally is made if the disk is active.
107 From these numbers and the transfer rates
108 of the devices it is possible to determine
109 average seek times for each device.
110 .PP
111 When filesystems are poorly placed on the available
112 disks, figures reported by \fIiostat\fP can be used
113 to pinpoint bottlenecks.  Under heavy system load, disk
114 traffic should be spread out among the drives with
115 higher traffic expected to the devices where the root, swap, and
116 /tmp filesystems are located.  When multiple disk drives are
117 attached to the same controller, the system will
118 attempt to overlap seek operations with I/O transfers.  When
119 seeks are performed, \fIiostat\fP will show
120 non-zero average seek times.  Most modern disk drives should
121 exhibit an average seek time of 25-35 ms.
122 .PP
123 Terminal traffic reported by \fIiostat\fP should be heavily
124 output oriented unless terminal lines are being used for
125 data transfer by programs such as \fIuucp\fP.  Input and
126 output rates are system specific.  Screen editors
127 such as \fIvi\fP and \fIemacs\fP tend to exhibit output/input
128 ratios of anywhere from 5/1 to 8/1.  On one of our largest
129 systems, 88 terminal lines plus 32 pseudo terminals, we observed
130 an average of 180 characters/second input and 450 characters/second
131 output over 4 days of operation.
132 .NH 2
133 Kernel profiling
134 .PP
135 It is simple to build a 4.2BSD kernel that will automatically
136 collect profiling information as it operates simply by specifying the
137 .B \-p
138 option to \fIconfig\fP\|(8) when configuring a kernel.
139 The program counter sampling can be driven by the system clock,
140 or by an alternate real time clock.
141 The latter is highly recommended as use of the system clock results
142 in statistical anomalies in accounting for
143 the time spent in the kernel clock routine.
144 .PP
145 Once a profiling system has been booted statistic gathering is
146 handled by \fIkgmon\fP\|(8).
147 \fIKgmon\fP allows profiling to be started and stopped
148 and the internal state of the profiling buffers to be dumped.
149 \fIKgmon\fP can also be used to reset the state of the internal
150 buffers to allow multiple experiments to be run without
151 rebooting the machine.
152 .PP
153 The profiling data is processed with \fIgprof\fP\|(1)
154 to obtain information regarding the system's operation.
155 Profiled systems maintain histograms of the kernel program counter,
156 the number of invocations of each routine,
157 and a dynamic call graph of the executing system.
158 The postprocessing propagates the time spent in each
159 routine along the arcs of the call graph.
160 \fIGprof\fP then generates a listing for each routine in the kernel,
161 sorted according to the time it uses
162 including the time of its call graph descendents.
163 Below each routine entry is shown its (direct) call graph children,
164 and how their times are propagated to this routine.
165 A similar display above the routine shows how this routine's time and the
166 time of its descendents is propagated to its (direct) call graph parents.
167 .PP
168 A profiled system is about 5-10% larger in its text space because of
169 the calls to count the subroutine invocations.
170 When the system executes,
171 the profiling data is stored in a buffer that is 1.2
172 times the size of the text space.
173 All the information is summarized in memory,
174 it is not necessary to have a trace file
175 being continuously dumped to disk.
176 The overhead for running a profiled system varies;
177 under normal load we see anywhere from 5-25%
178 of the system time spent in the profiling code.
179 Thus the system is noticeably slower than an unprofiled system,
180 yet is not so bad that it cannot be used in a production environment.
181 This is important since it allows us to gather data
182 in a real environment rather than trying to
183 devise synthetic work loads.
184 .NH 2
185 Kernel tracing
186 .PP
187 The kernel can be configured to trace certain operations by
188 specifying ``options TRACE'' in the configuration file.  This
189 forces the inclusion of code that records the occurrence of
190 events in \fItrace records\fP in a circular buffer in kernel
191 memory.  Events may be enabled/disabled selectively while the
192 system is operating.  Each trace record contains a time stamp
193 (taken from the VAX hardware time of day clock register), an
194 event identifier, and additional information that is interpreted
195 according to the event type.  Buffer cache operations, such as
196 initiating a read, include 
197 the disk drive, block number, and transfer size in the trace record.
198 Virtual memory operations, such as a pagein completing, include
199 the virtual address and process id in the trace record.  The circular
200 buffer is normally configured to hold 256 16-byte trace records.\**
201 .FS
202 \** The standard trace facilities distributed with 4.2
203 differ slightly from those described here.  The time stamp in the
204 distributed system is calculated from the kernel's time of day
205 variable instead of the VAX hardware register, and the buffer cache
206 trace points do not record the transfer size.
207 .FE
208 .PP
209 Several user programs were written to sample and interpret the
210 tracing information.  One program runs in the background and
211 periodically reads the circular buffer of trace records.  The
212 trace information is compressed, in some instances interpreted
213 to generate additional information, and a summary is written to a
214 file.  In addition, the sampling program can also record
215 information from other kernel data structures, such as those
216 interpreted by the \fIvmstat\fP program.  Data written out to
217 a file is further buffered to minimize I/O load. 
218 .PP
219 Once a trace log has been created, programs that compress
220 and interpret the data may be run to generate graphs showing the
221 data and relationships between traced events and
222 system load.
223 .PP
224 The trace package was used mainly to investigate the operation of
225 the file system buffer cache.  The sampling program maintained a
226 history of read-ahead blocks and used the trace information to
227 calculate, for example, percentage of read-ahead blocks used.
228 .NH 2
229 Benchmark programs
230 .PP
231 Benchmark programs were used in two ways.  First, a suite of
232 programs was constructed to calculate the cost of certain basic
233 system operations.  Operations such as system call overhead and
234 context switching time are critically important in evaluating the
235 overall performance of a system.  Because of the drastic changes in
236 the system between 4.1BSD and 4.2BSD, it was important to verify
237 the overhead of these low level operations had not changed appreciably.
238 .PP
239 The second use of benchmarks was in exercising
240 suspected bottlenecks.
241 When we suspected a specific problem with the system,
242 a small benchmark program was written to repeatedly use
243 the facility.
244 While these benchmarks are not useful as a general tool
245 they can give quick feedback on whether a hypothesized
246 improvement is really having an effect.
247 It is important to realize that the only real assurance
248 that a change has a beneficial effect is through
249 long term measurements of general timesharing.
250 We have numerous examples where a benchmark program
251 suggests vast improvements while the change
252 in the long term system performance is negligible,
253 and conversely examples in which the benchmark program run more slowly, 
254 but the long term system performance improves significantly.