Preface Preface 1.1. WHY IS PERFORMANCE IMPORTANT? If you ve ever sat waiting for a computer to do something, while pounding on your desk, cursing and wondering "What is TAKING so long?" you know why it is important to have a fast and well tuned computer system. While not all performance problems can be easily solved, understanding WHY things are slow can be the difference between fixing the problem in software, upgrading the slow hardware or simply throwing the whole computer out the window. Fortunately most operating systems, Linux in particular, provide the tools to figure out why the machine runs slowly. By using a few basic tools, you can determine where the system is slowing down and fix the parts that are running inefficiently. While a slow system can be particularly annoying to an end-user, if you are an application developer, you have an even more important reason to performance tune your applications. An efficient application runs on more systems. Not everyone has the latest hardware and by writing sluggish applications that need a zippy computer, you eliminate customers who have slower computers. A well-tuned application will be usable by more customers, and have a bigger potential user base. In addition, if a potential customer must choose between two different applications with similar functionality, they will often chose the one which runs faster or is more efficient. Finally, a long lived application will likely go through several rounds of optimization to cope with different customer demands, so it is crucial to know how to track down performance problems. If you are a system administrator, you have a responsibility to the users of the system to make sure that it is running with an adequate level of performance. If the system is running slowly, users will complain. If you can figure out the problem and fix it quickly, they ll stop complaining. As a bonus, if you can solve their problem by tuning the application or operating system rather than buying new hardware, you ll make the company bean-counters happy. Knowing how to effectively use performance tools can mean the difference between spending days and spending hours on a performance problem. 1.2. LINUX: STRENGTHS AND WEAKNESS If you use Linux, maintain it, and develop on it, you are in a strange but good situation. You have unprecedented access to source code, developers, and mailing lists which often document design decisions years after they were made. Linux is an excellent environment to find and fix performance problems. This is in contrast to a proprietary environment, where it can be difficult to get direct access to software developers, may be hard to find written discussion about most design decisions, and is nearly impossible to access source code. In addition to this productive environment, Linux also has powerful performance tools that you can use to find and fix performance problems. These tools rival their proprietary counterparts. Even with these impressive benefits the Linux ecosystem still has challenges to overcome. Linux s performance tools are scattered everywhere. The tools are developed by different groups with different aims, and as a result aren t in the same location. Some tools are included in standard Linux distributions, such as Redhat, SUSE or Debian, while others are scattered through out the Internet. If you re trying to solve a performance problem, you first have to know that the tools you need exist, and then figure out where to find them. No single Linux performance tool will solve every type of performance problem, so you also must figure out how to use them together to determine what is broken. This can be a bit of an art that becomes easier with experience. Most of the general strategies can be written down, but Linux doesn t have any guide that tells you how to use the performance tools together to actually solve a problem. Most of the tools or subsystems have information about tuning the particular subsystem, but not how to use them with other tools. Many performance problems span several areas of the system and unless you know how to use the tools together you won t be able the fix the problem. 1.3. HOW CAN THIS BOOK HELP YOU? This book will help you in a few different ways. It will show you: What the different performance tools measure How to use each tool How to combine the tools to solve a performance problem How to start with a poorly performing system and pinpoint the problem How the methods are used to solve real-world problems by providing a few case studies Using the methods in this book, you will be able to make a well organized and diagnosed problem description which can be passed on to the original developers. If you re lucky, they ll solve the problem for you. 1.4. WHY LEARN HOW TO USE PERFORMANCE TOOLS? Why should anyone put effort into tuning a system or application? A well-tuned system can do more work with less resources A well-tuned application can run on older hardware A well-tuned desktop can save a user time A well-tuned server provides a higher service quality for more users If you know how to effectively diagnose performance problems, you can take a targeted approach at solving the problem, rather than simply taking a shot in the dark and hoping that it works. If you are an application developer, this means that you can quickly figure out what piece of code is causing the problem. If you are a system administrator, it means that you can figure out what part of the system needs to be tuned, or upgraded without wasting time unsuccessfully trying different solutions. If you are a end-user, you can figure out which applications are lagging, and report the problem to the developers, or update your hardware if necessary. Linux is at cross-roads. Most of the functionality for a highly productive system is already done. The next evolutionary step is for Linux and Linux applications to be tuned to compete with and surpass the performance of other operating systems. Some of this performance optimization has already begun. Projects such as SAMBA, Apache and the TUX web server have spend a lot of time tuning and optimizing the system and code. Other performance optimizations such as the Native POSIX Thread Library NPTL , which dramatically improve threading performance, and object prelinking, which improves application startup time, are just starting to be integrated into Linux. Linux is a fertile ground for performance improvements. 1.5. CAN I TUNE FOR PERFORMANCE? The best thing about performance optimization is that you don t need to know the details of the entire application or system to effectively fix performance problems. Performance optimization requires a complementary set of skills to those of a typical application developer. You need to be observant and persistent. It takes more of a detective than a programmer to hunt down and eliminate the performance problems. It is exhilarating to find and fix these. When you start, performance is terrible. However, you track down the cause. Rip it out by the roots, if you re lucky, it runs twice as fast. Voila! To get to the "viola!", you have to understand the powerful but sometimes confusing world of Linux performance tools. This takes a little bit of work, but in the end it is worth it. The tools can show you aspects of your application and system that you never expected to see. 2.1 WHO SHOULD READ THIS BOOK? This book is intended to help Linux software developers, system administrators and end users to use the Linux performance tools to find the performance problems in a given system. Beginning performance investigators will learn the basics of performance investigation and analysis. Medium to advanced performance investigators, especially those with performance experience on other proprietary operating systems, will learn about the Linux equivalents of commands from other systems they may already be familiar with. Software developers will learn how to pinpoint the exact line of source code that is causing a performance problem. System administrators who are performance tuning a system will learn about the tools that show why a system is slowing down and they can then use that information to tune the system. Finally, while not the primary focus of the book, end users will be the learn basic skills necessary to figure out which applications are consuming all of the system resources. 2.2 HOW IS THE BOOK ORGANIZED? This book is intended to teach an audience varying level of experience to find and fix performance problems. To accomplish this, the chapters are presented so that you can pick and choose to read different parts of the book without reading the entire book straight through. The book is structured as follows: The first chapter is devoted to the basic methods of performance problem hunting. It contains a series of non-Linux specific tips and suggestions that are useful for tracking down performance issues. These guidelines are general suggestions for performance problem hunting and could be applied to tracking down performance issues on any type of computer system. The next few chapters, and the bulk of the book, present the individual tools available to measure different performance statistics on a Linux system. These chapters explain what a tool measures, how it is invoked, and an example of the tool being used. Each different chapter demonstrates tools that measure aspects of different Linux subsystems such as system CPU, user CPU, memory, network I/O and disk I/O. If a tool measures aspects of more than one subsystem, it is presented in more than one chapter. However, only the appropriate tools options for that subsystem are presented in a given chapter. Each chapter contains descriptions for multiple tools. The descriptions are in the following format: Introduction: This explains what the tool is meant to measure and how it operates. Performance tool options: This section does not simply rehash the tool s documentation. Rather, it explains which options are relevant to the current topic and what those options mean. For example, some performance tool man pages state the events that a tool measures, but never explain what the events mean. This section explains the meaning of the events, and how it is relevant to the current subsystem. Example: This gives one or more examples of the tool being used to measure performance statistics. This sections shows the tool being invoked as well as any output that it generates. The next chapter is Linux specific and contains a series of steps to use when confronted with a slowly performing Linux system. It explains how to use the previously described Linux performance together to pinpoint the cause of the performance problem. This chapter is the most useful if you want to start with a misbehaving Linux system and simply diagnose the problem, without necessarily understanding the details of the tools. The next three chapters show case studies where the methodologies and tools previously described are used together to solve real world problems. The case studies show the use of Linux performance tools in finding and fixing different types of performance problems: a CPU bound application, a latency sensitive application, and an I/O bound application. The final chapter provides an overview of the performance tools and what opportunities that Linux has for improvement. The book also has two appendices. Appendix A will contain a table of the performance tools presented in the book, a URL to the latest version of each tool, and information on which Linux distributions the tool is supported. Finally, appendix B will contain information about how to install oprofile, a very powerful, but hard to install tool, on a few major Linux distributions. /> Copyright Pearson Education. All rights reserved.