Chapter 5. Embedding Perl into Apache with mod_perlAlthough the Perl CGI methodology we discussed in Chapter 4, is an easy and popular approach to building web-based applications, there have historically been some performance problems with this approach. Whenever a Perl CGI script is run, the rather sizeable Perl interpreter must first be brought into memory before it can interpret and execute your program. Unfortunately, that can be a very slow process. Fans of Java servlets have pointed to this performance issue in advocating that their technology be used instead of Perl. But Perl has not taken this challenge from Java evangelists lying down! Apache's mod_perl module provides an interface between Apache and Perl that allows Perl code to be cached in the web server's memory space. The effect is a substantial improvement in performance over standard Perl CGI applications. How much is substantial? As with so many things, the only real benchmarks are either for highly oversimplified cases (with no real application) or for highly specialized cases (with little extensibility). For most real-world programs, however, we can tell you that mod_perl provides a raw speed increase of approximately 40 to 60%. But this is only part of the story. The really significant gain is the vastly increased scalability provided through mod_perl because the interpreter is in memory and can be shared between processes. The mod_perl module binds the Perl interpreter directly into the heart of the Apache server, thus avoiding the overhead of loading the interpreter into memory for each script executed on the server. As well as doing memory caching, this module also allows you to extend the Apache server in the Perl language itself. With mod_perl in place, the entire server-side Apache API becomes available to Perl programs. In this chapter, we'll describe mod_perl, as well as several related Apache modules:
|