SlideShare a Scribd company logo
1 of 27
Lightweight mod_perl Applications
            with Apache::Dispatch



            Fred Moyer
            fred@redhotpenguin.com
Apache::Dispatch
●   Abstraction layer for mod_perl applications
●   The power of mod_perl handlers
●   Maps URIs to application resources via
    method handlers
●   Painless migration from mod_perl handlers
Not another Framework
● There are plenty of those already
  ● OpenInteract

  ● Catalyst

  ● Jifty

  ● Axkit

  ● Woodstock

  ● ...

● Like CGI::Application in the sense

  that it's a library, but only for mod_perl
●
    MVC
HTTP Request Lifecycle
Handles Response Phase


You are here
Start with URIs
 ●   /hello
 ●   /hello/world
 ●   /hello/world/oslo
 ●   /hello/oslo
 ●   hello/oslo/mongers
Map URIs to Method Handlers
●   Method handler passes package name as first
    argument, $r as second argument
●   /hello          => My::Hello->dispatch_index
●   /hello/world    => My::Hello->dispatch_world
●   /hello/world/oslo => My::Hello::World->dispatch_oslo
●   /hello/oslo     => My::Oslo->dispatch_index
●   /hello/oslo/mongers => My::Oslo->dispatch_mongers
●   dispatch_index only works at the top level
Apache::Test is your Friend
●   You do write your tests first, don't you? ;)
●   my/app/t/01hello.t =>
     use strict;
     use warnings FATAL => 'all';
     use Apache::Test;
     use Apache::TestRequest;
     plan tests => 2;
     my $res = GET '/hello';
     ok($res->code == 200);
     ok($res->content =~ m/Hello/i);
Configuration
my/app/t/conf/extra.last.conf.in =>

 PerlLoadModule    Apache2::Dispatch
 PerlLoadModule        My::Hello
 PerlLoadModule        My::Hello::World
 DispatchRequire   On
 DispatchUpperCase On

 <Location /hello>
  SetHandler          modperl
  DispatchPrefix      My::Hello
  PerlResponseHandler Apache2::Dispatch
 </Location>
Method Handlers
my/app/lib/My/Hello.pm =>
 package My::Hello;
 use strict;
 use Apache2::Const -compile => qw( OK );
 use Apache2::RequestIO;
 use Apache2::RequestRec;

 sub dispatch_index {
   my $class = shift;
   my $r = shift;
   $r->content_type('text/plain');
   $r->print(“Hello!”);
   return Apache2::Const::OK;
 }
Apache::Test
my/app/Makefile.PL =>

 #!perl
 use strict;
 use warnings FATAL => 'all';
 use Apache::TestMM;
 Apache::TestMM->import(qw(test clean));
 Apache::TestMM::filter_args();
 Apache::TestMM::generate_script('t/TEST');
 use ModPerl::MM;
 ModPerl::MM::WriteMakefile(
  %standard_make_params );
Apache::Test
my/app/t/TEST.PL =>

 #!perl
 use strict;
 use warnings FATAL => 'all';

 use Apache::TestRunPerl();

 Apache::TestRunPerl->new->run(@ARGV);
Hello!
           ● perl Makefile.PL
           ● make

           ● make test

           ● debug if errors

           ● make install




Include the extra.last.conf.in section shown
earlier to your httpd.conf,restart httpd, and
visit http://localhost/hello
Test me, Test me
Easily test with different httpd/mod_perl builds
●   export APACHE_TEST_HTTPD = /path/to/test_httpd/bin/httpd
●   export APACHE_TEST_APXS = /path/to/test_httpd/bin/apxs

Test without having to 'make test' each time
●   export APACHE_TEST_LIVE_DEV = /path/to/my/app/lib
./t/TEST -start-httpd
●



./t/TEST t/01hello.t
●
Review
●   Created a basic test driven
    Apache::Dispatch based hello
    web service

●   Wrote a test, a config file, and a
    method handler

●   Reviewed Apache::Test basics
The Extras
●   Pre-Dispatch method handler

●   Post-Dispatch method handler

●   Custom Error method handler

●   Inheritance

●   Autoloading
Pre-Dispatch Method Handler
● DispatchExtras Pre
● Used for setup common to dispatch_* methods

● Similar functionality in most frameworks

● Best suited for code re-use - DRY




sub pre_dispatch {
  my ($class, $r) = @_;
  my %data = My::Model::Hello->data;
  # stash the data in the request for use later
  $r->pnotes( hello_common => %data );
}
Post-Dispatch Method Handler
● DispatchExtras Post
● Teardown for package dispatch_* methods

● As with pre_dispatch, similar to most

  frameworks, main function is DRY
● Still part of the response phase

● Runs after the dispatch_* handler, even if

  the response was not OK
sub post_dispatch {
  my ($class, $r) = @_;
  $r->log->info(“Request to “ .
   $r->connection->remote_ip . “ was served”);
}
Custom Error Method Handler
● DispatchExtras Error
● Handles error in dispatch_* methods

● Ignores errors in Pre/Post handlers



sub error_dispatch {
  my ($class, $r, $payload, $rc) = @_;
  $r->log->error(“Oops!: $@”);
  if ($rc == Apache2::Const::NOT_FOUND) {
    $r->print(
      $self->process_tmpl('not_found.tmpl'));
  }
  return Apache2::Const::OK;
}
Inheritance
●   DispatchISA My::BaseHandler
●   Useful for defining methods across
    different packages
●   For example, define one error_dispatch
    method and share it among other classes
●   Suggested that it be used with
    DispatchAUTOLOAD Off (default)
Autoloading
● DispatchAUTOLOAD On
● Autoloaded methos must be declared

●
  Read the camel book 3rd ed pp326-329
● Read the examples in t/lib




our $AUTOLOAD;
sub dispatch_autoloaded_method;
sub AUTOLOAD {
  my ($class, $r) = @_;
  $r->log->info(“Method $AUTOLOAD called”);
  # ....
}
Filtering
● Use mod_perl2 filtering API for mp2
● Apache::Dispatch has built-in filtering for mp1



httpd.conf =>
DispatchFilter On
PerlResponseHandler Apache::Dispatch My::Filter
package My::Filter;
sub handler {
  my $r = shift;
  $r->send_http_header();
  $r = $r->filter_register;
  my $fh = $r->filter_input;
  while (<$fh>) {
    # modify $_;
    print;
  }
}
Lightweight
●   http://chamas.com/bench
    ●   658.7 req/sec for Apache::Dispatch
    ●   856.0 req/sec for mod_perl handler
●   Geoffrey Young's benchmarks
    ●   <Location> and method handler – 14.34 req/sec
    ●   A::D with DispatchISA On – 13.78 req/sec
●   See Todo for the details
●   One Perl module, not zillions
Dependencies
●   None unless you want to do testing
●   In which case you'll need
    ● Apache::Test

    ● LWP::UserAgent



●   Compare this to other libraries/frameworks
    which use x number of modules to get
    started
Credits

●   Geoffrey Young – Author, mod_perl
    and testing guru, helping me release
    the latest version soonish
●   Thomas Klausner – Maintenance work
    and material for this talk
●   The mod_perl community
References
[1] - http://search.cpan.org/perldoc?Apache::Dispatch
[2] - mod_perl Developers Cookbook
    http://www.modperlcookbook.org
[3] - Josh Chamas' Hello World Benchmark
     http://chamas.com/bench/
[4] - Thomas Klausner's YAPC 2003 Presentation
     http://domm.zsi.at/talks/yapc2003
[5] - Apache::Test Part 2 Presentation
     http://modperlcookbook.org/~geoff/apache
[6] - http://sourceforge.net/projects/apache-dispatch
Slides
These slides are freely available at

http://www.redhotpenguin.com/talks

Try out the latest version of Apache::Dispatch at

http://sourceforge.net/projects/apache-dispatch

Coming soon to a CPAN mirror near you


         Thank you NPW 2006!

More Related Content

What's hot

OB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
OB1K - New, Better, Faster, Devops Friendly Java container by OutbrainOB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
OB1K - New, Better, Faster, Devops Friendly Java container by OutbrainEran Harel
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4Wim Godden
 
[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화NAVER D2
 
[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화NAVER D2
 
Profiling and optimizing go programs
Profiling and optimizing go programsProfiling and optimizing go programs
Profiling and optimizing go programsBadoo Development
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?Maciej Lasyk
 
Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Valerii Kravchuk
 
Centralized Logging with syslog
Centralized Logging with syslogCentralized Logging with syslog
Centralized Logging with syslogamiable_indian
 
The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014Jian-Hong Pan
 
Ob1k presentation at Java.IL
Ob1k presentation at Java.ILOb1k presentation at Java.IL
Ob1k presentation at Java.ILEran Harel
 
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevMake Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevJian-Hong Pan
 
We shall play a game....
We shall play a game....We shall play a game....
We shall play a game....Sadia Textile
 
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian DammOSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian DammNETWAYS
 
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Michael Barker
 
Like loggly using open source
Like loggly using open sourceLike loggly using open source
Like loggly using open sourceThomas Alrin
 
Linux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptLinux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptKenny (netman)
 
10 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.610 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.6Webline Infosoft P Ltd
 

What's hot (19)

OB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
OB1K - New, Better, Faster, Devops Friendly Java container by OutbrainOB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
OB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화[232]TensorRT를 활용한 딥러닝 Inference 최적화
[232]TensorRT를 활용한 딥러닝 Inference 최적화
 
[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화[232] TensorRT를 활용한 딥러닝 Inference 최적화
[232] TensorRT를 활용한 딥러닝 Inference 최적화
 
Profiling and optimizing go programs
Profiling and optimizing go programsProfiling and optimizing go programs
Profiling and optimizing go programs
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)
 
Centralized Logging with syslog
Centralized Logging with syslogCentralized Logging with syslog
Centralized Logging with syslog
 
The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014The Simple Scheduler in Embedded System @ OSDC.TW 2014
The Simple Scheduler in Embedded System @ OSDC.TW 2014
 
Ob1k presentation at Java.IL
Ob1k presentation at Java.ILOb1k presentation at Java.IL
Ob1k presentation at Java.IL
 
Xmla4js
Xmla4jsXmla4js
Xmla4js
 
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevMake Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
 
We shall play a game....
We shall play a game....We shall play a game....
We shall play a game....
 
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian DammOSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
 
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!
 
Like loggly using open source
Like loggly using open sourceLike loggly using open source
Like loggly using open source
 
Linux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptLinux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell script
 
10 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.610 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.6
 

Similar to Apache Dispatch

30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPANdaoswald
 
Creating a mature puppet system
Creating a mature puppet systemCreating a mature puppet system
Creating a mature puppet systemrkhatibi
 
Creating a Mature Puppet System
Creating a Mature Puppet SystemCreating a Mature Puppet System
Creating a Mature Puppet SystemPuppet
 
Orchestrated Functional Testing with Puppet-spec and Mspectator
Orchestrated Functional Testing with Puppet-spec and MspectatorOrchestrated Functional Testing with Puppet-spec and Mspectator
Orchestrated Functional Testing with Puppet-spec and MspectatorRaphaël PINSON
 
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...Puppet
 
PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)xSawyer
 
Perl hosting for beginners - Cluj.pm March 2013
Perl hosting for beginners - Cluj.pm March 2013Perl hosting for beginners - Cluj.pm March 2013
Perl hosting for beginners - Cluj.pm March 2013Arpad Szasz
 
Php 5.6 From the Inside Out
Php 5.6 From the Inside OutPhp 5.6 From the Inside Out
Php 5.6 From the Inside OutFerenc Kovács
 
Hadoop meet Rex(How to construct hadoop cluster with rex)
Hadoop meet Rex(How to construct hadoop cluster with rex)Hadoop meet Rex(How to construct hadoop cluster with rex)
Hadoop meet Rex(How to construct hadoop cluster with rex)Jun Hong Kim
 
Auto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK NodesAuto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK Nodesnihiliad
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingAlessandro Molina
 
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008phpbarcelona
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersKirk Kimmel
 
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...OpenShift Origin
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90minsLarry Cai
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and MaintenanceJazkarta, Inc.
 
javase8bestpractices-151015135520-lva1-app6892
javase8bestpractices-151015135520-lva1-app6892javase8bestpractices-151015135520-lva1-app6892
javase8bestpractices-151015135520-lva1-app6892SRINIVAS C
 

Similar to Apache Dispatch (20)

30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPAN
 
Creating a mature puppet system
Creating a mature puppet systemCreating a mature puppet system
Creating a mature puppet system
 
Creating a Mature Puppet System
Creating a Mature Puppet SystemCreating a Mature Puppet System
Creating a Mature Puppet System
 
Orchestrated Functional Testing with Puppet-spec and Mspectator
Orchestrated Functional Testing with Puppet-spec and MspectatorOrchestrated Functional Testing with Puppet-spec and Mspectator
Orchestrated Functional Testing with Puppet-spec and Mspectator
 
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
Orchestrated Functional Testing with Puppet-spec and Mspectator - PuppetConf ...
 
PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)
 
Perl hosting for beginners - Cluj.pm March 2013
Perl hosting for beginners - Cluj.pm March 2013Perl hosting for beginners - Cluj.pm March 2013
Perl hosting for beginners - Cluj.pm March 2013
 
Php 5.6 From the Inside Out
Php 5.6 From the Inside OutPhp 5.6 From the Inside Out
Php 5.6 From the Inside Out
 
Hadoop meet Rex(How to construct hadoop cluster with rex)
Hadoop meet Rex(How to construct hadoop cluster with rex)Hadoop meet Rex(How to construct hadoop cluster with rex)
Hadoop meet Rex(How to construct hadoop cluster with rex)
 
Auto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK NodesAuto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK Nodes
 
Catalyst MVC
Catalyst MVCCatalyst MVC
Catalyst MVC
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90mins
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and Maintenance
 
Php
PhpPhp
Php
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
javase8bestpractices-151015135520-lva1-app6892
javase8bestpractices-151015135520-lva1-app6892javase8bestpractices-151015135520-lva1-app6892
javase8bestpractices-151015135520-lva1-app6892
 

More from Fred Moyer

Reliable observability at scale: Error Budgets for 1,000+
Reliable observability at scale: Error Budgets for 1,000+Reliable observability at scale: Error Budgets for 1,000+
Reliable observability at scale: Error Budgets for 1,000+Fred Moyer
 
Practical service level objectives with error budgeting
Practical service level objectives with error budgetingPractical service level objectives with error budgeting
Practical service level objectives with error budgetingFred Moyer
 
SREcon americas 2019 - Latency SLOs Done Right
SREcon americas 2019 - Latency SLOs Done RightSREcon americas 2019 - Latency SLOs Done Right
SREcon americas 2019 - Latency SLOs Done RightFred Moyer
 
Scale17x - Latency SLOs Done Right
Scale17x - Latency SLOs Done RightScale17x - Latency SLOs Done Right
Scale17x - Latency SLOs Done RightFred Moyer
 
Latency SLOs Done Right
Latency SLOs Done RightLatency SLOs Done Right
Latency SLOs Done RightFred Moyer
 
Latency SLOs done right
Latency SLOs done rightLatency SLOs done right
Latency SLOs done rightFred Moyer
 
Comprehensive Container Based Service Monitoring with Kubernetes and Istio
Comprehensive Container Based Service Monitoring with Kubernetes and IstioComprehensive Container Based Service Monitoring with Kubernetes and Istio
Comprehensive Container Based Service Monitoring with Kubernetes and IstioFred Moyer
 
Comprehensive container based service monitoring with kubernetes and istio
Comprehensive container based service monitoring with kubernetes and istioComprehensive container based service monitoring with kubernetes and istio
Comprehensive container based service monitoring with kubernetes and istioFred Moyer
 
Effective management of high volume numeric data with histograms
Effective management of high volume numeric data with histogramsEffective management of high volume numeric data with histograms
Effective management of high volume numeric data with histogramsFred Moyer
 
Statistics for dummies
Statistics for dummiesStatistics for dummies
Statistics for dummiesFred Moyer
 
GrafanaCon EU 2018
GrafanaCon EU 2018GrafanaCon EU 2018
GrafanaCon EU 2018Fred Moyer
 
Fredmoyer postgresopen 2017
Fredmoyer postgresopen 2017Fredmoyer postgresopen 2017
Fredmoyer postgresopen 2017Fred Moyer
 
Better service monitoring through histograms sv perl 09012016
Better service monitoring through histograms sv perl 09012016Better service monitoring through histograms sv perl 09012016
Better service monitoring through histograms sv perl 09012016Fred Moyer
 
Better service monitoring through histograms
Better service monitoring through histogramsBetter service monitoring through histograms
Better service monitoring through histogramsFred Moyer
 
The Breakup - Logically Sharding a Growing PostgreSQL Database
The Breakup - Logically Sharding a Growing PostgreSQL DatabaseThe Breakup - Logically Sharding a Growing PostgreSQL Database
The Breakup - Logically Sharding a Growing PostgreSQL DatabaseFred Moyer
 
Learning go for perl programmers
Learning go for perl programmersLearning go for perl programmers
Learning go for perl programmersFred Moyer
 
Surge 2012 fred_moyer_lightning
Surge 2012 fred_moyer_lightningSurge 2012 fred_moyer_lightning
Surge 2012 fred_moyer_lightningFred Moyer
 
Ball Of Mud Yapc 2008
Ball Of Mud Yapc 2008Ball Of Mud Yapc 2008
Ball Of Mud Yapc 2008Fred Moyer
 
Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator SimplifiedFred Moyer
 

More from Fred Moyer (20)

Reliable observability at scale: Error Budgets for 1,000+
Reliable observability at scale: Error Budgets for 1,000+Reliable observability at scale: Error Budgets for 1,000+
Reliable observability at scale: Error Budgets for 1,000+
 
Practical service level objectives with error budgeting
Practical service level objectives with error budgetingPractical service level objectives with error budgeting
Practical service level objectives with error budgeting
 
SREcon americas 2019 - Latency SLOs Done Right
SREcon americas 2019 - Latency SLOs Done RightSREcon americas 2019 - Latency SLOs Done Right
SREcon americas 2019 - Latency SLOs Done Right
 
Scale17x - Latency SLOs Done Right
Scale17x - Latency SLOs Done RightScale17x - Latency SLOs Done Right
Scale17x - Latency SLOs Done Right
 
Latency SLOs Done Right
Latency SLOs Done RightLatency SLOs Done Right
Latency SLOs Done Right
 
Latency SLOs done right
Latency SLOs done rightLatency SLOs done right
Latency SLOs done right
 
Comprehensive Container Based Service Monitoring with Kubernetes and Istio
Comprehensive Container Based Service Monitoring with Kubernetes and IstioComprehensive Container Based Service Monitoring with Kubernetes and Istio
Comprehensive Container Based Service Monitoring with Kubernetes and Istio
 
Comprehensive container based service monitoring with kubernetes and istio
Comprehensive container based service monitoring with kubernetes and istioComprehensive container based service monitoring with kubernetes and istio
Comprehensive container based service monitoring with kubernetes and istio
 
Effective management of high volume numeric data with histograms
Effective management of high volume numeric data with histogramsEffective management of high volume numeric data with histograms
Effective management of high volume numeric data with histograms
 
Statistics for dummies
Statistics for dummiesStatistics for dummies
Statistics for dummies
 
GrafanaCon EU 2018
GrafanaCon EU 2018GrafanaCon EU 2018
GrafanaCon EU 2018
 
Fredmoyer postgresopen 2017
Fredmoyer postgresopen 2017Fredmoyer postgresopen 2017
Fredmoyer postgresopen 2017
 
Better service monitoring through histograms sv perl 09012016
Better service monitoring through histograms sv perl 09012016Better service monitoring through histograms sv perl 09012016
Better service monitoring through histograms sv perl 09012016
 
Better service monitoring through histograms
Better service monitoring through histogramsBetter service monitoring through histograms
Better service monitoring through histograms
 
The Breakup - Logically Sharding a Growing PostgreSQL Database
The Breakup - Logically Sharding a Growing PostgreSQL DatabaseThe Breakup - Logically Sharding a Growing PostgreSQL Database
The Breakup - Logically Sharding a Growing PostgreSQL Database
 
Learning go for perl programmers
Learning go for perl programmersLearning go for perl programmers
Learning go for perl programmers
 
Surge 2012 fred_moyer_lightning
Surge 2012 fred_moyer_lightningSurge 2012 fred_moyer_lightning
Surge 2012 fred_moyer_lightning
 
Qpsmtpd
QpsmtpdQpsmtpd
Qpsmtpd
 
Ball Of Mud Yapc 2008
Ball Of Mud Yapc 2008Ball Of Mud Yapc 2008
Ball Of Mud Yapc 2008
 
Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator Simplified
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Apache Dispatch

  • 1. Lightweight mod_perl Applications with Apache::Dispatch Fred Moyer fred@redhotpenguin.com
  • 2. Apache::Dispatch ● Abstraction layer for mod_perl applications ● The power of mod_perl handlers ● Maps URIs to application resources via method handlers ● Painless migration from mod_perl handlers
  • 3. Not another Framework ● There are plenty of those already ● OpenInteract ● Catalyst ● Jifty ● Axkit ● Woodstock ● ... ● Like CGI::Application in the sense that it's a library, but only for mod_perl ● MVC
  • 6. Start with URIs ● /hello ● /hello/world ● /hello/world/oslo ● /hello/oslo ● hello/oslo/mongers
  • 7. Map URIs to Method Handlers ● Method handler passes package name as first argument, $r as second argument ● /hello => My::Hello->dispatch_index ● /hello/world => My::Hello->dispatch_world ● /hello/world/oslo => My::Hello::World->dispatch_oslo ● /hello/oslo => My::Oslo->dispatch_index ● /hello/oslo/mongers => My::Oslo->dispatch_mongers ● dispatch_index only works at the top level
  • 8. Apache::Test is your Friend ● You do write your tests first, don't you? ;) ● my/app/t/01hello.t => use strict; use warnings FATAL => 'all'; use Apache::Test; use Apache::TestRequest; plan tests => 2; my $res = GET '/hello'; ok($res->code == 200); ok($res->content =~ m/Hello/i);
  • 9. Configuration my/app/t/conf/extra.last.conf.in => PerlLoadModule Apache2::Dispatch PerlLoadModule My::Hello PerlLoadModule My::Hello::World DispatchRequire On DispatchUpperCase On <Location /hello> SetHandler modperl DispatchPrefix My::Hello PerlResponseHandler Apache2::Dispatch </Location>
  • 10. Method Handlers my/app/lib/My/Hello.pm => package My::Hello; use strict; use Apache2::Const -compile => qw( OK ); use Apache2::RequestIO; use Apache2::RequestRec; sub dispatch_index { my $class = shift; my $r = shift; $r->content_type('text/plain'); $r->print(“Hello!”); return Apache2::Const::OK; }
  • 11. Apache::Test my/app/Makefile.PL => #!perl use strict; use warnings FATAL => 'all'; use Apache::TestMM; Apache::TestMM->import(qw(test clean)); Apache::TestMM::filter_args(); Apache::TestMM::generate_script('t/TEST'); use ModPerl::MM; ModPerl::MM::WriteMakefile( %standard_make_params );
  • 12. Apache::Test my/app/t/TEST.PL => #!perl use strict; use warnings FATAL => 'all'; use Apache::TestRunPerl(); Apache::TestRunPerl->new->run(@ARGV);
  • 13. Hello! ● perl Makefile.PL ● make ● make test ● debug if errors ● make install Include the extra.last.conf.in section shown earlier to your httpd.conf,restart httpd, and visit http://localhost/hello
  • 14. Test me, Test me Easily test with different httpd/mod_perl builds ● export APACHE_TEST_HTTPD = /path/to/test_httpd/bin/httpd ● export APACHE_TEST_APXS = /path/to/test_httpd/bin/apxs Test without having to 'make test' each time ● export APACHE_TEST_LIVE_DEV = /path/to/my/app/lib ./t/TEST -start-httpd ● ./t/TEST t/01hello.t ●
  • 15. Review ● Created a basic test driven Apache::Dispatch based hello web service ● Wrote a test, a config file, and a method handler ● Reviewed Apache::Test basics
  • 16. The Extras ● Pre-Dispatch method handler ● Post-Dispatch method handler ● Custom Error method handler ● Inheritance ● Autoloading
  • 17. Pre-Dispatch Method Handler ● DispatchExtras Pre ● Used for setup common to dispatch_* methods ● Similar functionality in most frameworks ● Best suited for code re-use - DRY sub pre_dispatch { my ($class, $r) = @_; my %data = My::Model::Hello->data; # stash the data in the request for use later $r->pnotes( hello_common => %data ); }
  • 18. Post-Dispatch Method Handler ● DispatchExtras Post ● Teardown for package dispatch_* methods ● As with pre_dispatch, similar to most frameworks, main function is DRY ● Still part of the response phase ● Runs after the dispatch_* handler, even if the response was not OK sub post_dispatch { my ($class, $r) = @_; $r->log->info(“Request to “ . $r->connection->remote_ip . “ was served”); }
  • 19. Custom Error Method Handler ● DispatchExtras Error ● Handles error in dispatch_* methods ● Ignores errors in Pre/Post handlers sub error_dispatch { my ($class, $r, $payload, $rc) = @_; $r->log->error(“Oops!: $@”); if ($rc == Apache2::Const::NOT_FOUND) { $r->print( $self->process_tmpl('not_found.tmpl')); } return Apache2::Const::OK; }
  • 20. Inheritance ● DispatchISA My::BaseHandler ● Useful for defining methods across different packages ● For example, define one error_dispatch method and share it among other classes ● Suggested that it be used with DispatchAUTOLOAD Off (default)
  • 21. Autoloading ● DispatchAUTOLOAD On ● Autoloaded methos must be declared ● Read the camel book 3rd ed pp326-329 ● Read the examples in t/lib our $AUTOLOAD; sub dispatch_autoloaded_method; sub AUTOLOAD { my ($class, $r) = @_; $r->log->info(“Method $AUTOLOAD called”); # .... }
  • 22. Filtering ● Use mod_perl2 filtering API for mp2 ● Apache::Dispatch has built-in filtering for mp1 httpd.conf => DispatchFilter On PerlResponseHandler Apache::Dispatch My::Filter package My::Filter; sub handler { my $r = shift; $r->send_http_header(); $r = $r->filter_register; my $fh = $r->filter_input; while (<$fh>) { # modify $_; print; } }
  • 23. Lightweight ● http://chamas.com/bench ● 658.7 req/sec for Apache::Dispatch ● 856.0 req/sec for mod_perl handler ● Geoffrey Young's benchmarks ● <Location> and method handler – 14.34 req/sec ● A::D with DispatchISA On – 13.78 req/sec ● See Todo for the details ● One Perl module, not zillions
  • 24. Dependencies ● None unless you want to do testing ● In which case you'll need ● Apache::Test ● LWP::UserAgent ● Compare this to other libraries/frameworks which use x number of modules to get started
  • 25. Credits ● Geoffrey Young – Author, mod_perl and testing guru, helping me release the latest version soonish ● Thomas Klausner – Maintenance work and material for this talk ● The mod_perl community
  • 26. References [1] - http://search.cpan.org/perldoc?Apache::Dispatch [2] - mod_perl Developers Cookbook http://www.modperlcookbook.org [3] - Josh Chamas' Hello World Benchmark http://chamas.com/bench/ [4] - Thomas Klausner's YAPC 2003 Presentation http://domm.zsi.at/talks/yapc2003 [5] - Apache::Test Part 2 Presentation http://modperlcookbook.org/~geoff/apache [6] - http://sourceforge.net/projects/apache-dispatch
  • 27. Slides These slides are freely available at http://www.redhotpenguin.com/talks Try out the latest version of Apache::Dispatch at http://sourceforge.net/projects/apache-dispatch Coming soon to a CPAN mirror near you Thank you NPW 2006!