Mod_perl High speed dynamic content. Definitions Apache – OpenSource httpd server Perl – OpenSource interpreted programming language mod_perl – OpenSource.

Slides:



Advertisements
Similar presentations
More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld.
Advertisements

Lecture 11 Server Side Interaction
PHP Reusing Code and Writing Functions.
1/16 Steven Leung Introduction to HTML/CGI/JavaScript Intro to HTML/CGI/JavaScript How the Web Works HTML: Basic Concept CGI: Basic Concept JavaScript:
METALOGIC s o f t w a r e © Metalogic Software Corporation DACS Developer Overview DACS – the Distributed Access Control System.
Compiling Web Scripts for Apache Jacob Matthews Luke Hoban Robby Findler Rice University.
Puppet for GENI Experiments
Adding Dynamic Content to your Web Site
Murali Mani SQL-PL Interface. Murali Mani Some Possible Options Web Interface Perl /CGI with Oracle/mySQL Install your own web server and use servlets.
Michael Parker1998 O'Reilly Perl Conference Mod_Perl: Putting it all Together 1998 O’Reilly Perl Conference San Jose, CA.
20-753: Fundamentals of Web Programming 1 Lecture 11: Web Server Case Study Fundamentals of Web Programming Lecture 11: Web Server Case Study.
ASP Tutorial. What is ASP? ASP (Active Server Pages) is a Microsoft technology that enables you to make dynamic and interactive web pages. –ASP usually.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
Chapter Apache Installation in Linux- Mandrake. Acknowledgment The following information has been obtained directly from
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
1 CS6320 – Why Servlets? L. Grewe 2 What is a Servlet? Servlets are Java programs that can be run dynamically from a Web Server Servlets are Java programs.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Tomcat Configuration A Very, Very, Very Brief Overview.
Sharepoint Portal Server Basics. Introduction Sharepoint server belongs to Microsoft family of servers Integrated suite of server capabilities Hosted.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Using Ant to build J2EE Applications Kumar
Linux Operations and Administration
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Apache Tomcat Web Server SNU OOPSLA Lab. October 2005.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
ZFApp Preview Walkthrough. What is ZFApp? ZFApp is an application framework built on top of Zend Framework Fully compatible with the latest ZF Versions.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Input/Output Controller (IOC) Overview Andrew Johnson Computer Scientist, AES Controls Group.
Apache Server The Apache Server Apache is a WWW server that implements the HTTP protocol. Apache runs as a daemon. This means that it is a resident.
Introduction to Shell Script Programming
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
Internet Forms and Database Bob Kisel Amgraf, Inc.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormack 3rd floor 607.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
1 Apache. 2 Module - Apache ♦ Overview This module focuses on configuring and customizing Apache web server. Apache is a commonly used Hypertext Transfer.
Apache Web Server v. 2.2 Reference Manual Chapter 1 Compiling and Installing.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Phone: Mega AS Consulting Ltd © 2007  CAT – the problem & the solution  Using the CAT - Administrator  Mega.
Chapter 6 Server-side Programming: Java Servlets
Templates, Databases and Frameworks. Databases: DBI Common database interface for perl Provides a functional,
Module 10 Administering and Configuring SharePoint Search.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
The HTTP is a standard that all Web browsers and Web servers must speak in order for the Web portion of the Internet to work.
Programming Perl in UNIX Course Number : CIT 370 Week 6 Prof. Daniel Chen.
Intermediate CGI & CGI.pm Webmaster II - Fort Collins, CO Copyright © XTR Systems, LLC CGI Programming & The CGI.pm Perl Module Instructor: Joseph DiVerdi,
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
ASP. ASP is a powerful tool for making dynamic and interactive Web pages An ASP file can contain text, HTML tags and scripts. Scripts in an ASP file are.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
Apache Web Server Architecture Chaitanya Kulkarni MSCS rd April /23/20081Apache Web Server Architecture.
Chap 2 – Getting Started COMP YL Professor Mattos.
 History  Ease of use  Portability  Standard  Security & Privacy  User support  Application &Popularity Today  Ten Most Popular Programming Languages.
12. MODULES Rocky K. C. Chang November 6, 2015 (Based on from Charles Dierbach. Introduction to Computer Science Using Python and William F. Punch and.
Program Libraries 1. What is a program library? A library is a collection of implementations of behavior, written in terms of a language, that has a well-defined.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
Apache Web Server v. 2.2 Reference Manual Chapter 2 Starting Apache.
Node.js Modules Header Mastering Node.js, Part 2 Eric W. Greene
Apache web server Quick overview.
Python’s Modules Noah Black.
Introduction to Programming the WWW I
PHP / MySQL Introduction
Perl Modules.
Apache Tomcat Web Server
APACHE WEB SERVER.
Web Application Development Using PHP
Presentation transcript:

mod_perl High speed dynamic content

Definitions Apache – OpenSource httpd server Perl – OpenSource interpreted programming language mod_perl – OpenSource interface between Apache and Perl

Scenario Unix hosted web-site using CGI Perl scripts to create web pages with dynamic content. As the site becomes larger and more popular, the speed slows The web servers are not resource constrained How can we speed the delivery of content?

Topics covered Why use mod_perl? How mod_perl works Installation highlights Commonly encountered problems when porting from CGI to mod_perl

Take home messages use strict; Use the PerlTaintCheck directive mod_perl enabled scripts are fast Possibly faster than C code… Effective use of mod_perl is not trivial

Why use mod_perl? CGI scripts written in Perl and served from Apache can be slow Generally the more dynamic the content, the slower the page return As sites grow, their content usually becomes more dynamic Sites ported to mod_perl show request return rates 200% to 2000% higher!!!

Evolution of a web-site

Why is CGI slow? For each CGI script called: Apache must load the Perl interpreter Perl must load the the CGI script including all used Modules The CGI script must initialize itself on each load Database initialization is a common slow-down

Dynamic content options

The embedded interpreter There are increasingly sophisticated solutions: Only load the Perl interpreter once (PerlRun) Only load the CGI scripts and modules once (PerlRegistry) Only do initializations once (Code re-factoring)

The mod_perl version Each Apache instance loads the Perl interpreter when it initializes (PerlRun) mod_perl loads CGI scripts the first time they are executed (PerlRegistry) We can move CGI initialization code into a separate script that is executed when each Apache instance starts (Code re-factoring)

How does mod_perl work? Its invoked by Apache so… How does Apache work? Its running Perl code so… How does Perl work? The mod_perl handler

How does Perl work? Interpreted language To run a Perl program The Perl interpreter is loaded The Program is compiled by the Perl interpreter The Program is executed

array Analogous to the LD_LIBRARY_PATH environment variable This array contains the paths that Perl will search when loading libraries or modules With mod_perl this is set during Apaches initialization phase and cannot be change later

Perls %INC hash After Perl has compiled a program, it is added to %INC as a key with the fully qualified filename and compile time as a values Before loading a program, Perl searches %INC for a match. If it finds one, it uses the %INC entry and does not re-load the program

How does Apache work? Apache serves documents requested via HTTP A sample request:

The Apache request cycle

The mode _perl handlers You can interact with the Apache request cycle at any point with a handler A handler is a program that is defined for a Directory, Location, Files or FilesMatch directive in Apaches configuration files

The Apache handler API Apache calls the handler, passes information about the current transaction and server state and expects an integer status code in return If the handler returns an error, Apache short- circuits to the logging phase

The PerlHandler: part 1 Called prior to serving the requested document Two default handlers PerlRun PerlRegistry

The PerlHandler: part 2 Unless you are using a custom handler, your CGI programs are executed as subroutines inside the handler subroutine (nested subroutines) Since Apache never exits, the CGI programs are never reaped by Perls garbage collection

A handler subroutine sub handler { my $request = my $status = &do_something($request); return $status; }

Installation highlights Install Apache and mod_perl together Configure Apache to use mod_perl Port your CGI scripts

Installation: part 1 (The following is for Unix, Win32 installs are more difficult) Download Apache current version is Download mod_perl current version is 1.24 Check perl version (mod_perl 1.24 or earlier works best with Perl not 5.6.0)

Installation: part 2 By default building mod_perl will also build Apache > perl Makefile.PL APACHE_SRC=../apache \ DO_HTTPD=1 USE_APACI=1 EVERYTHING=1 > make;make test;make install > cd../apache ; make install

Configuration Configure Apache to use mod_perl: modify httpd.conf Include conf/perl.conf

perl.conf: part 1 PerlSetEnv PERL5LIB /my/perl/lib PerlRequire conf/startup.pl Alias /cgi-bin /my/cgi/dir PerlTaintCheck On

perl.conf: part 2 SetHandlerperl-script PerlHandlerApache::Registry OptionsExecCGI

perl.conf: part 3 A good initial check of mod_perl SetHandlerperl-script PerlHandlerApache::Status

startup.pl Loads commonly used modules Initializes database = qw( $dbh ); use lib qw( /home/matt/perl/Modules /opt/apps/lib ); my $dbh = DBI->connect($db,$user,$passwd);

Porting CGI scripts to mod_perl use strict; during porting use diagnostics; And check the error.log Run the Apache server single threaded Add the following to perl.conf PerlInitHandlerApacheStatINC

Common porting problems: part 1 As someone pointed out during the presentation, all of these problems could be solved by using re-entrant coding techniques If you used them when you wrote the CGI scripts, porting will be easy That being said, most CGI scripts are not written by people familiar with such techniques…

Common porting problems Run-time attempts to add paths Implicit variable passing Assigning anonymous sub to $SIG{__DIE__} Compiled regular expressions No closure of file or dbm handles

Adding paths This will not work is fixed after the initialization of Apache Use startup.pl to add paths BEGIN blocks only get executed at compile time

Implicit variable passing The value of the variable in subroutines will not be updated after the first call Perl considers the two variables to be separate Solutions Fully qualify the variable in the subroutine Pass by value or reference Make the variable global

$SIG{__DIE__} problems $SIG{__DIE__} is global Your anonymous subroutine will be called by any die statement Solutions Write your own exception method Error.pm (try, throw, catch)

Compiled regular expressions Only compiled for the first pattern used Solution Add an eval block eval q{ foreach { &mysub($_) if ( /$pattern/o ); }

No closure of file or dbm handles Common to use close on exit fh management Now the script does not exit…. Solution Close your file and dbm handles

Conclusions mod_perl will speed up CGI scripts by 200% to 2000% use strict; Use the PerlTaintCheck directive Effective use of mod_perl is not trivial, plan accordingly

Further Reading Writing Apache Modules with Perl and C Lincoln Stein and Doug MacEachern mod_perl Guide Stas Bekman FAQ Frank Cringle

Apache %INC hash detail The handler subroutine changes the name of the nested subroutines to the fully qualified filename plus the prefix Apache::ROOT Apache::ROOT::My::Dir::script_2epl This reduces the likelihood of namespace collisions, but frustrates tampering