Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Apple > Operating Systems

  • Print
  • + Share This
This chapter is from the book

Maximizing Performance

Most computer users are never completely satisfied with how fast their computers run. They could always be faster. Although the hardware and software place certain limits on how fast a computer can go, a computer often runs slower than it is capable of doing. In this section, I describe some ways to make sure that you are getting the best performance from your Mac.

As a starting point: A native Mac OS X program running in Mac OS X should run about as fast as a Mac OS 9 version of the same program would run in Mac OS 9. A Mac OS 9 program running in Classic, while booted from Mac OS X, will generally be slower than the same program running in Mac OS 9.

Otherwise, if your Mac appears to be running significantly slower than it typically runs, or just runs too slowly in general, consider the following techniques.

SEE

"Technically Speaking: Monitoring and Improving Performance," later in this chapter, for other ways to enhance the speed of your Mac and for how to monitor memory use.

Not enough memory

Due to Mac OS X's dynamic memory, you will rarely, if ever, see "out of memory" messages, no matter how many applications you have open. Thus, it may sometimes appear that your Mac has unlimited memory. This is not so. At some point, as you open more and more applications, the overall performance of every aspect of your Mac will slow. Keep pushing the memory envelope, and you will likely precipitate a crash. Following are two solutions:

Add more memory. The best solution to memory problems is to purchase more memory. How much? As much as you can afford or your Mac can hold. You can't have too much. Mac OS X devours whatever RAM you give it. And the less RAM you have, the more performance slowdowns you will have.

Quit unneeded applications. If you are not adding more RAM, the more immediate alternative is to quit any open applications that you do not need. Quitting Classic, if you don't need to use it, is always good advice. In some cases, if a problem has become severe, you may need to log out and log back in before performance improves.

Different programs use different amounts of memory. Thus, quitting application A may have little effect, whereas quitting application B may have a tremendous effect.

About This Mac. How do you know how much memory you have and how much you are using? The About This Mac window, which you open from the Apple menu, tells you how much physical memory (RAM) you have installed.

SEE

Chapter 4 for more background on dynamic memory and related Darwin issues.

Too slow a processor

If your Mac is more than two years old, getting a new Mac will likely give you significantly better performance. Upgrading the processor or graphics card on your existing Mac may be a more cost-effective solution.

A Mac with a PowerPC G4 processor, for example, will be noticeably snappier than one that uses a PowerPC G3. Presumably, PowerPC G5 processors will be faster still. The difference in processor speed usually is more noticeable when you're running Mac OS X than it is in Mac OS 9, as Mac OS X places more demands on the processor. Mac OS X also includes dual-processor support for OS functions; Mac OS 9 did not. So if you have a dual-processor Mac, it should seem faster in Mac OS X than it does in Mac OS 9.

A faster graphics card (ATI and nVidia are always coming out with new and improved models) can also enhance speed, especially when you're using multimedia or playing games.

Not enough free space on the drive (especially for the swap file)

If your hard drive is nearing capacity (generally, for most current hard drives of 10 GB or larger, if you have less than 1 GB of unused space), you may start to see a performance decline.

Too little free hard drive space is a concern especially when the size has become so small as to present problems for maintaining the virtual-memory swap file. Mac OS X's virtual-memory system works by storing information on your hard drive in a file called a swap file, located in the invisible /private/var/vm directory. This file can be quite large—80 MB at minimum. With too little free hard-drive space to accommodate the growth of the swap file as needed, you will start to see a performance decrease. Actually, even with a minimally sufficient amount of space available, fragmentation of the swap file can lead to a performance decrease.

The common solutions are:

  • Reduce the need to access virtual memory by decreasing the number of processes/applications you have running at one time.

  • Add more physical memory.

  • Delete unneeded files from your hard drive and defragment your hard drive to make more contiguous free space. (See "Insufficient space," earlier in this chapter, for some specific advice.)

  • Purchase a larger hard drive to replace your existing one or as an additional drive to offload rarely used files. Newer hard drives also tend to be faster than their older predecessors.

TECHNICALLY SPEAKING

Moving the Swap File to a Separate Partition

A hard drive becomes fragmented when a file is stored in several segments in different locations on the drive, typically because no single free section of the drive is large enough to hold the entire file as one segment. As more files become fragmented, the overall level of disk fragmentation increases. If the fragmentation level gets sufficiently high, drive performance can start to decline. Disk optimizers such as Norton Utilities' Speed Disk are designed to reduce this fragmentation.

Larger files are more subject to fragmentation than smaller ones. As the swap file is a large file, it is especially vulnerable to fragmentation. Moving the swap file to a separate volume (presumably, one with lots of free space) from the one that contains Mac OS X can help reduce fragmentation. This change may in turn improve virtual-memory performance as well as disk performance.

I am still not convinced that the benefit is worth the effort. But if you want to give it a try, a utility called Swap Cop automates the procedure for you. Otherwise, the procedure, which requires considerable work in Terminal and with Unix files, is beyond the scope of this book. If you want the details, see ResExcellence (www.ResExcellence.com/hack_html_01/06-01-01.shtml) or Mac FAQs and Tips (www.bombich.com/mactips/swap.html).

SEE

"Technically Speaking: Monitoring and Improving Performance," later in this chapter, for more information on memory and the swap file.

Too slow an Internet connection

If your speed problems are primarily restricted to online problems (such as slow loading of Web pages), and you have a dial-up modem connection, it's time to think about moving up to a broadband connection (cable or DSL). Your speeds be much faster, and you will have a 24/7 connection with no need to log on and no dropped connections.

If you already have a broadband connection, you can still do some things that may improve performance. The utility MOX Optimize, for example, includes an option to speed Ethernet networking by optimizing buffers. This option essentially simplifies doing what you could otherwise do in Terminal.

SEE

Chapter 8 for more information on Internet issues.

Figure 6.45Figure 6.45 MOX Optimize's Network tab.


Miscellaneous other tips

Finally, you can do a host of other minor that have a small incremental effect on performance. These techniques mostly involve turning off certain Finder and Dock features, thereby reducing the CPU usage. It's up to you to decide whether the tradeoff is worth it. You could turn off the following features:

  • Dock magnification

  • Zoom rectangles

  • Text antialiasing

  • Window shadows

  • Bouncing icons in the Dock (which can slow your Mac considerably)

You can do all these things via one or more of the following: Finder and Dock Preferences settings, TinkerTool, ShadowKiller, MOX Optimize, Dock Detox, and a host of other shareware utilities. MOX Optimize has an especially rich selection of options, including the capability to increase the Finder's Unix nice priority (see "Technically Speaking: Monitoring and Improving Performance" later in this chapter).

Quit Sherlock. Don't leave Sherlock running if you are not using it, especially if you have enabled its option to index volumes and folders. On one occasion, my Mac slowed down to the point that I could barely use it. When I ran the top command in Terminal, I discovered a process called ContentInd (presumably from Sherlock) was monopolizing almost all of the CPU usage. Quitting Sherlock, if you can, might put an end to this. I chose instead to use the kill command in Terminal (see "Kill from Terminal" in Chapter 5) to kill the process. This immediately eliminated the slowdown.

Check the Web. Various Mac Web sites have posted additional tips for enhancing Mac OS X performance. One good example (beyond my own MacFixIt) is Mac OS X FAQ (www.index-site.com/Macosxspeed.html).

TECHNICALLY SPEAKING

Monitoring and Improving Performance

Insufficient memory, too slow a processor (CPU), a nonoptimized drive—all these things (and more) can decrease the performance of Mac OS X. But if you suspect that your Mac is not up to par, how would you determine which, if any, of these factors is the major cause? And beyond adding hardware (such as more memory or a faster processor), what, if anything, can you do to improve performance? The answers to both of these questions reside in a host of utility software. Some solutions require using Terminal; others are Aqua-based. Following is an overview.

CPU Monitor. CPU Monitor, which is included when you install Mac OS X, is located in the Utilities folder. When you launch it, the program displays a small thermometer-type gauge, with a current level that keeps rising and falling. The level indicates the ever-changing extent of CPU use. Don't be alarmed if the level occasionally gets to 100 percent; that's OK as long as it doesn't stay there for a sustained period. If the gauge remains at its peak, you are likely trying to do too many processor-intensive activities at the same time. Quitting some applications or reducing how many tasks you have going simultaneously will likely help. I have rarely found this gauge to be diagnostically useful. But the CPU Monitor Processes menu also serves as a convenient launch pad for two more-useful functions: Process Viewer and top.

ProcessViewer. ProcessViewer is also part of the basic Mac OS X installation. I have discussed this utility before, primarily in Chapter 5, as a means to force-quit processes. Now I want to focus on two additional features of the utility: its %CPU and %Memory column listings. Each process listed in ProcessViewer's display has a value in each of these two columns. These values indicate how much CPU attention and memory availability the process is using. You can sort either column by clicking the column name. If you do so, the processes that move to the top are the ones that are the most likely culprits in any CPU- or memory-related performance problems. In general, regardless of what the results may be, do not quit any processes that you do not recognize, especially administrative processes. If a process name is for an application you do know, its CPU or memory percentage remains high, and you don't need it open at the moment, quitting that application would be a good idea.

One difficulty is that all Carbon applications will have the name LaunchCFMApp, making it dif-ficult to tell which one represents a particular Carbon application. Similarly, Classic applications are not listed separately but are included under the TruBlueEnvironme process. You may need to do trial-and-error guesswork to figure out the culprit.

Also note: Some applications may claim to be using 0 percent of memory. This can happen; it does not mean that something is wrong.

Terminal commands. You can view (and, in some cases, modify) a variety of important performance measures via Unix commands you enter in Terminal. Following are some examples:

  • top. If you choose the top command in CPU Monitor, it will launch Terminal and execute. You can also get there simply by launching Terminal and typing <top>. The top display is Unix's version of ProcessViewer. The PID column, for example, gives the Process ID number for a process, the Command column gives the name of each process, and the %CPU gives current CPU use. The numbers continue to update as you watch. To exit this display, type

    <q> (for quit).

    NOTE

    Note: Unlike ProcessViewer, Terminal does not list the names of all Carbon applications as LaunchCFMApp.

    At the top of the top display are some other important numbers. Load Avg is one indication of CPU use. The three numbers represent the most recent average and two averages from minutes before. Generally, the load should stay below 2.0. If it gets higher and stays there, and if performance slows, you may be trying to do something beyond what the processor can handle. If what you are trying to do is essential to your work, an upgrade to a faster processor may be required. Otherwise, you need to try to do less at the same time.

    The CPU Usage numbers give a different perspective on how the CPU is being used. These numbers indicate how much of the CPU is allocated to the system (kernel) vs. the user vs. how much is not currently being used at all (idle). Be especially on guard as the idle percentage approaches 0, which is likely to correlate with performance slowdowns.

    Finally, the VM (virtual memory) line gives an indication of memory use. The VM line looks something like this:

    VM: 3.19G + 50.7M 25092(0) pageins, 24969(0) pageouts 

    If the initial number (3.19 GB in the preceding example) is getting close to the size of your remaining free hard-drive space, you are likely to see performance slowdowns. This number indicates that your swap file does not have sufficient space. (Note: The amount of free space on your volume is listed in the status bar of any Finder window for that volume, assuming that Show Status Bar was chosen from the Finder's View menu.) For further details on memory use, read on.

  • vmstat. Unix's vmstat command provides a more focused look at Mac OS X's memory use than top provides. Of particular interest is the number of pageouts (also listed in the top display). The pageout value is an indication that physical memory is being paged (swapped) to the swap file on your drive. The higher the number of pageouts, the greater the disk access and the worse your performance is likely to be. A performance problem is especially indicated if you see pageouts continuing to increase over time.

    If pageouts equal 0, you are not using the swap file at all. This situation is the ideal, as any use of the swap file will likely result in slower performance. As long as the pageout number is near 0 and relatively stable, you need not be too concerned about memory use, even if other statistics indicate that your memory use is at or near 100 percent.

  • renice. As I discussed earlier in this book (see "Darwin" in Chapter 4), Mac OS X's preemptive multitasking attempts to allocate the processor's attention such that the most important tasks get the most attention (generally giving greater attention to a foreground application over a background one, for example). Tasks that get the greatest attention complete the fastest. One way the OS makes these decisions is by assigning each process a priority ranking. When two processes are competing for the CPU's attention, the one with the greater priority will receive the greater attention.

    On occasion, however, you may want to override the OS's default priorities. Some users have found they can give Virtual PC a needed speed boost by assigning a higher priority to it. To do this, you use Terminal's renice command. The default nice level for most applications is 0. The potential range is between –20 and +20. To increase an application's priority, you lower its nice level from 0 to a lower number. (The lower the number, the more attention a process gets.) There are limits, of course. If you give everything a score of -20, for example, you won't be increasing the performance of anything. The benefits are always relative to the priorities assigned to other processes.

    To change a nice value, type <sudo renice {nice #} {pid}>, in which where {nice #} is the integer from –20 to +20 and {pid} is the process ID number of the process you want to change. (You can determine a process pid from the top command or from ProcessViewer.) Unfortunately, these changes may not be saved after you quit the application or restart the Mac. So you may need to reenter a change each time you use the application.

    By the way, users have noticed that Virtual PC runs slower in Mac OS X than it does in Mac OS 9. Connectix claims that this slowdown is due to a rare case in which preemptive multitasking (used in Mac OS X but not Mac OS 9) turns out to be a disadvantage. In Mac OS 9, Connectix can make sure that Virtual PC gets as much processor priority as possible. In Mac OS X, preemptive multitasking prevents this situation, resulting in slower performance. An upgrade to Mac OS X is supposed to provide a workaround for this situation.

  • Optimize (update_prebinding). When you run a Mac OS X update via the Installer utility, at some point, the Installer typically says that it is optimizing the software. This process often turns out to be the longest part of the entire update.

    What the Installer is doing at this point is running the Unix update_prebinding command. To explain the process in the most nontechnical language possible, the command updates the linking among applications and the shared library files that may be required to run an application. Whenever a new application is installed, this information map needs to be updated. If the information is not updated, the resolving of these links is calculated when you launch the application, which takes added time and thus slows performance. Installers perform this task because, following the installation of new software, updating this map is desirable.

    If you add applications to your drive by any method that does not do this updating (which would be the case for most applications that do not use Apple's Installer utility), running the update_prebinding command yourself could increase the speed of Mac OS X.

    The simplest way to do this is to bypass Terminal and use Xoptimize, an Aqua-based utility that accesses the same update_prebinding command. Xoptimize also includes options (such as using less memory when running the optimization) that can prevent problems that might occur if you simply ran update_prebinding from Terminal.

    NOTE

    Mac OS 9 users may be familiar with the term optimizing, as it refers to defragment-ing the files on a disk and optimizing their locations as done via a utility such as Norton Utilities' Speed Disk. This process is different from the Unix-based optimization referred to in this sidebar. You may still get benefit from using Speed Disk on a Mac OS X volume, but I confess that I no longer bother to do this. The process is not likely to be of much value if you have a large hard dive with a good deal of unused space. The issue did come up, however, when I decided whether to move the swap file to a separate partition (see: "Technically Speaking: Moving the Swap File to a Separate Partition" earlier in this chapter).

  • netstat. Terminal's netstat command gives you a quick indication of whether your network connection is performing up to par. In Terminal, type <netstat –i>. In the display that appears, if the incoming packet count is 0, you probably don't have a connection at all. If your error count is greater than 1 to 2 percent, there is likely to be some problem with your connection (perhaps a network difficulty at your cable company's end). Type <netstat -i 10>, and the display is updated every 10 seconds. This technique allows you to test hypotheses. You could start your browser to see whether the error counts change as the browser attempts a connection, for example.

Aqua-based utilities. Many Aqua-based utilities that measure performance are actually graphical user interfaces (or GUIs) for a Unix function otherwise accessed via Terminal. I have already mentioned some of the utilities, including ProcessViewer, CPU Monitor, and Xoptimize. Following are some others.

Perfboard is an Aqua-based shareware utility that provides a quick view of most of the data covered in this sidebar. In its default view, you get a constantly updated look at CPU percentage, system load, memory use (including pageouts), network ins and outs, and disk reads and writes.

Other Aqua-based utilities provide similar feedback—usually, a subset of what Perfboard provides, but in the form of a menu-bar item or a Dock icon. One example is GMem!, which shows memory use.

The Renicer and Nicer utilities allow you to modify the nice level of a process without using Terminal.

The Netstat tab of Network Utility (included in the Utilities folder of Mac OS X) offers similar functionality to Unix's netstat command.

SEE

  • "Optimize Mac OS X volumes," in Chapter 5.

  • Chapter 8 for more information on networking issues.

Figure 6.46Figure 6.46 CPU Monitor's Processes menu and CPU gauge.


Figure 6.47Figure 6.47 Process Viewer's display.


Figure 6.48Figure 6.48 The top command output viewed in Terminal.


Figure 6.49Figure 6.49 The vm_stat command output viewed in Terminal.


  • + Share This
  • 🔖 Save To Your Account