Danh mục

Advanced PHP Programming- P10

Số trang: 50      Loại file: pdf      Dung lượng: 881.36 KB      Lượt xem: 11      Lượt tải: 0    
Thư viện của tui

Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu advanced php programming- p10, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Advanced PHP Programming- P10 18 ProfilingI F YOU PROGRAM PHP PROFESSIONALLY, THERE is little doubt that at some point youwill need to improve the performance of an application. If you work on a high-trafficsite, this might be a daily or weekly endeavor for you; if your projects are mainly intranetones, the need may arise less frequently. At some point, though, most applications needto be retuned in order to perform as you want them to. When I’m giving presentations on performance tuning PHP applications, I like tomake the distinction between tuning tools and diagnostic techniques. Until now, thisbook has largely focused on tuning tools: caching methodologies, system-level tunings,database query optimization, and improved algorithm design. I like to think of thesetechniques as elements of a toolbox, like a hammer, a torque wrench, or a screwdriverare elements of a handyman’s toolbox. Just as you can’t change a tire with a hammer, youcan’t address a database issue by improving a set of regular expressions.Without a goodtoolset, it’s impossible to fix problems; without the ability to apply the right tool to thejob, the tools are equally worthless. In automobile maintenance, choosing the right tool is a combination of experienceand diagnostic insight. Even simple problems benefit from diagnostic techniques. If Ihave a flat tire, I may be able to patch it, but I need to know where to apply the patch.More complex problems require deeper diagnostics. If my acceleration is sluggish, Icould simply guess at the problem and swap out engine parts until performance isacceptable.That method is costly in both time and materials. A much better solution isto run an engine diagnostic test to determine the malfunctioning part. Software applications are in general much more complex than a car’s engine, yet Ioften see even experienced developers choosing to make “educated” guesses about thelocation of performance deficiencies. In spring 2003 the php.net Web sites experiencedsome extreme slowdowns. Inspection of the Apache Web server logs quickly indicatedthat the search pages were to blame for the slowdown. However, instead of profiling tofind the specific source of the slowdown within those pages, random guessing was used430 Chapter 18 Profiling to try to solve the issue.The result was that a problem that should have had a one-hour fix dragged on for days as “solutions” were implemented but did nothing to address the core problem. Thinking that you can spot the critical inefficiency in a large application by intuition alone is almost always pure hubris. Much as I would not trust a mechanic who claims to know what is wrong with my car without running diagnostic tests or a doctor who claims to know the source of my illness without performing tests, I am inherently skepti- cal of any programmer who claims to know the source of an application slowdown but does not profile the code. What Is Needed in a PHP Profiler A profiler needs to satisfy certain requirements to be acceptable for use: n Transparency—Enabling the profiler should not require any code change. Having to change your application to accommodate a profiler is both highly inconvenient (and thus prone to being ignored) and intrinsically dishonest because it would by definition alter the control flow of the script. n Minimal overhead—A profiler needs to impose minimal execution overhead on your scripts. Ideally, the engine should run with no slowdown when a script is not being profiled and almost no slowdown when profiling is enabled. A high over- head means that the profiler cannot be run for production debugging, and it is a large source of internal bias (for example, you need to make sure the profiler is not measuring itself). n Ease of use—This probably goes without saying, but the profiler output needs to be easy to understand. Preferably there should be multiple output formats that you can review offline at your leisure.Tuning often involves a long cycle of introspec- tion and code change. Being able to review old profiles and keep them for later cross-comparison is essential. A Smorgasbord of Profilers As with most features of PHP, a few choices are available for script profilers: n Userspace profilers—An interesting yet fundamentally flawed category of profil- er is the userspace profilers.This is a profiler written in PHP.These profilers are interesting because it is always neat to see utilities for working with PHP written in PHP it ...

Tài liệu được xem nhiều: