⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch39_05.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 39] 39.5 Why Is the System So Slow? </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:50:13Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch39_01.htm"TITLE="39. Time and Performance"><LINKREL="prev"HREF="ch39_04.htm"TITLE="39.4 Average Command Runtimes with runtime "><LINKREL="next"HREF="ch39_06.htm"TITLE="39.6 lastcomm: What Commands Are Running and How Long Do They Take?"></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch39_04.htm"TITLE="39.4 Average Command Runtimes with runtime "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 39.4 Average Command Runtimes with runtime "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 39<BR>Time and Performance</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch39_06.htm"TITLE="39.6 lastcomm: What Commands Are Running and How Long Do They Take?"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 39.6 lastcomm: What Commands Are Running and How Long Do They Take?"BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0066">39.5 Why Is the System So Slow? </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43763"></A>To a user, performance means: &quot;How much time does it take to runmy job?&quot; For a system manager, this question is much too simple: auser's job may take a long time to execute because it is badlywritten or because it doesn't really use the computer appropriately.Furthermore, a system manager must optimize performance for all system users&nbsp;- which is much more complicated than optimizingperformance for a single user.Here are some of the things that affect performance.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43767"></A>The UNIX utility<SPANCLASS="link"><EMCLASS="emphasis">/bin/time</EM> (<ACLASS="linkend"HREF="ch39_02.htm"TITLE="Timing Programs ">39.2</A>)</SPAN>reports the amount of timerequired to execute a program, breaking down the total time into several important components. For example, considerthe report below:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>/bin/time application</B></CODE><CODECLASS="literal">  4.8 real      0.5 user      0.7 sys</CODE></PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43777"></A><ACLASS="indexterm"NAME="AUTOID-43779"></A><ACLASS="indexterm"NAME="AUTOID-43781"></A><ACLASS="indexterm"NAME="AUTOID-43783"></A><ACLASS="indexterm"NAME="AUTOID-43786"></A>This report shows that the program ran in roughly 4.8 seconds. Thisis the <EMCLASS="emphasis">elapsed</EM> or <EMCLASS="emphasis">wallclock</EM> time: it is the actualtime that the program runs as it would be measured by a user sittingat the terminal with a stopwatch. The amount of time that the systemspent working on your program is much smaller. It spent0.5&nbsp;seconds of <EMCLASS="emphasis">user time</EM>, which is time spent executing code in theuser state, and about 0.7 seconds of <EMCLASS="emphasis">system time</EM>, which is timespent in the system state (i.e., time spent executing UNIX system code) onbehalf of the user. The total amount of CPU time (actualexecution time on the main processor) was only 1.2 seconds, or onlyone-quarter of the elapsed time.  [1] </P><BLOCKQUOTECLASS="footnote"><PCLASS="para">[1] Note that BSD and System V versions of <EMCLASS="emphasis">/bin/time</EM> have differentoutput formats but provide the same information. <EMCLASS="emphasis">/bin/time</EM> alsodiffers from the<SPANCLASS="link"> C shell's <EMCLASS="emphasis">time</EM> command , (<ACLASS="linkend"HREF="ch39_03.htm"TITLE="The csh time variable ">39.3</A>)</SPAN>which provides a more elaborate report.</P></BLOCKQUOTE><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43799"></A> Where did the rest of the time go? Some time was spent performing I/O(text input/output) operations, which <EMCLASS="emphasis">/bin/time</EM> doesn't report. Handling I/O requires some computation, which is attributed to system time.But time that is spent by disk drives, network interfaces, terminal controllers, or other hardware isn't accounted for;most of the time was spent running jobs on behalf of other users. This entails its own performance overhead (context-switch time,swapping time, etc.). </P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43803"></A> Many differentcomponents contribute to a program's total running time. When you understand the roles these components play, you will understand theproblem. Here is a summary of the different components:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43809"></A> <BCLASS="emphasis.bold">User-state CPU time.</B>  The actual amount of time the CPU spendsrunning your program in the user state. It includes time spent executing library functions but excludes time spent executing systemcalls (i.e., time spent in the UNIX kernel on behalf of the process).Programmers can control user-state time by knowing which library routines are efficient and which aren't, and theyshould know how to run profilers on the program to find out where it's spending its time.</P></LI><LICLASS="listitem"><PCLASS="para"> <ACLASS="indexterm"NAME="AUTOID-43814"></A><ACLASS="indexterm"NAME="AUTOID-43817"></A> <BCLASS="emphasis.bold">System-state CPU time.</B>  The amount of time the CPU spendsin the system state (i.e., the amount of time spent executing kernel code) on behalf of the program. This includes time spent executingsystem calls and performing administrative functions on the program's behalf.The distinction between time spent in simple library routines and time spent in system services is important and often confused. A call to<EMCLASS="emphasis">strcpy</EM>, which copies a character string, executes entirely in the user state because it doesn't require any special handling by thekernel. Calls to <EMCLASS="emphasis">printf</EM>, <EMCLASS="emphasis">fork</EM>, and many other routines are much more complex. These functions do require services from the UNIXkernel so they spend part of their time, if not most of it, in the system state. All I/O routines require the kernel's services.</P><PCLASS="para">System-state CPU time is partially under the programmer's control. Although programmers cannot change the amount of time it takes to service any systemcall, they can rewrite the program to issue system calls more efficiently (for example, to make I/O transfers in larger blocks).</P></LI><LICLASS="listitem"><PCLASS="para"> <ACLASS="indexterm"NAME="AUTOID-43827"></A><BCLASS="emphasis.bold">I/O time.</B>  The amount of time the I/O subsystem spends servicing the I/O requests that the job issues. Under UNIX, I/O time isdifficult to measure; however, there are some tools for determining whether the I/O system is overloaded and some configurationconsiderations that can help alleviate load problems. </P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43832"></A> <BCLASS="emphasis.bold">Network time.</B>  The amount of time that the I/O subsystem spendsservicing network requests that the job issues. This is really a subcategory of I/O time and depends critically on configuration andusage issues. </P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43837"></A> <BCLASS="emphasis.bold">Time spent running other programs.</B>  As system load increases, theCPU spends less time working on any given job, thus increasing the elapsed time required to run the job. This is an annoyance, but barring someproblem with I/O or virtual memory performance, there is little you can do about it.</P></LI><LICLASS="listitem"><PCLASS="para"> <ACLASS="indexterm"NAME="AUTOID-43843"></A><ACLASS="indexterm"NAME="AUTOID-43845"></A> <BCLASS="emphasis.bold">Virtual memory performance.</B>  This is by far the most complex aspect ofsystem performance. Ideally, all active jobs would remain in the system's physical memory at all times. But when physical memory is fullyoccupied, the operating system starts moving parts of jobs to disk, thus freeing memory for the job it wants to run. This takes time. It also takestime when these disk-bound jobs need to run again and therefore need to be moved back into memory. When running jobs with extremely large memoryrequirements, system performance can degrade significantly. </P></LI></UL><PCLASS="para"> If you spend most of your time running standard utilities andcommercial applications, you can't do much about user-state or system-state time. To make a significant dent in these, you have torewrite the program. But you can do a lot to improve your memory and I/O performance, and you can do a lot to run your big applicationsmore efficiently. </P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-43851"></A> <ACLASS="indexterm"NAME="AUTOID-43853"></A>Keyboard response is an extremely important issue to users, although it really doesn't contribute to a program's execution time. If thereis a noticeable gap between the time when a user types a character and the time when the system echoes that character,the user will think performance is bad, regardless of how much time it takes to run a job. In order to prevent terminal buffers from overflowing and losing characters, most UNIX systems give <SPANCLASS="link">terminal drivers (<ACLASS="linkend"HREF="ch42_01.htm#UPT-ART-1142"TITLE="Making Sense Out of the Terminal Mess ">42.1</A>)</SPAN>very high priority. As a side effect, the high priority of terminals means that keyboard response should be bad only under exceptionally high loads. If youare accessing a remote system across a network, however, network delays can cause poor keyboard response. Network performance is anextremely complex issue. </P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN> <SPANCLASS="bibliomisc">from O'Reilly &amp; Associates' <CITECLASS="citetitle">System Performance Tuning</CITE>, Chapter 1</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch39_04.htm"TITLE="39.4 Average Command Runtimes with runtime "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 39.4 Average Command Runtimes with runtime "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch39_06.htm"TITLE="39.6 lastcomm: What Commands Are Running and How Long Do They Take?"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 39.6 lastcomm: What Commands Are Running and How Long Do They Take?"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">39.4 Average Command Runtimes with runtime </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">39.6 lastcomm: What Commands Are Running and How Long Do They Take?</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -