Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Upcoming SlideShare
mod_perlで動くアプリをどう置くか #hachiojipm
Next

Share

mod_perl温故知新 〜Perl CGIの高速化からメールサーバまで〜

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

mod_perl温故知新 〜Perl CGIの高速化からメールサーバまで〜

  1. 1. mod_perl Perl CGI fonfun (OGATA Tetsuji) Twitter: @xtetsuji 2011/7/16
  2. 2. (1/2)• (OGATA Tetsuji) Twitter: @xtetsuji• http://post.tetsuji.jp/ ( )• ( ) 18
  3. 3. (2/2)• ( …)•( ) Perl 30• JavaScript / Shell Script(bash) // Emacs Lisp• :
  4. 4. (1/2)• fonfun( ) http://www.fonfun.co.jp/ • http://rmail.jp/• g15 http://g15.jp/
  5. 5. (2/2)• fonfun( : ) • 1999 ( : ) • 2003 4 (Perl + Apache/ mod_perl + Oracle + Postfix) •
  6. 6. •• YAPC::Asia2010• (@onagatani)• Hokkaido.pm•
  7. 7. Agenda
  8. 8. Agenda• I. mod_perl• II. mod_perl Apache• III. Apache2&mod_perl2 HTTP• IV. - qpsmtpd & nginx...•
  9. 9. I. mod_perl
  10. 10. Apache+mod_perl?• ※1 WAF PSGI/Plack Apache ※1. WAF=Web Application Framework•• Plack+mod_perl2 ※ http://subtech.g.hatena.ne.jp/cho45/20101221/1292941055
  11. 11. Apache+mod_perl?• Apache+mod_perl+WAF mod_perl … • •
  12. 12. Apache+mod_perl?• Apache• Linux Apache mod_perl ( )
  13. 13. Apache+mod_perl?• Apache• Apache 2011 7 65.86% (2011 6 64.88%) (http://news.netcraft.com/ archives/2011/07/08/ july-2011-web-server- Market Share for Top Servers Across All Domains survey.html ) August 1995 - June 2011• Apache
  14. 14. Apache+mod_perl?• WAF• Apache Perl CGI(or PHP)• ...
  15. 15. mod_perl• Apache1.3 → mod_perl1• Apache2.x → mod_perl2• 1 2 mod_perl• mod_perl1.99( )• ※ Apache1 deprecated mod_perl1
  16. 16. mod_perl• mod_perl1 first public release: 1996/3/25 (http://perl.apache.org/dist/mod_perl-1.0-current/Changes )• mod_perl2 first public release: 2002/4/6 (http://perl.apache.org/dist/mod_perl-2.0-current/Changes )
  17. 17. Perl CGI # ↓Apache Configurations• mod_perl1 AddHandler perl-script .pl PerlHandler Apache::Registry• mod_perl2 AddHandler perl-script .pl PerlResponseHandler ModPerl::Registry• ”.pl” Perl CGI
  18. 18. hello.pl
  19. 19. mod_perl1 Hello1.pm•• ($r) handler• http://hello.example.jp/ Content-Type: text/plain
  20. 20. mod_perl1 Hello1.pm # apache1.3 configuration <VirtualHost A.B.C.D:80> ServerName hello.example.jp SetHandler perl-script PerlHandler Hello1 </VirtualHost>
  21. 21. mod_perl1 Hello1.pm
  22. 22. mod_perl2 Hello2.pm•• mod_perl1•
  23. 23. mod_perl2 Hello2.pm # apache2.x configuration <VirtualHost A.B.C.D:80> ServerName hello.example.jp SetHandler perl-script PerlResponseHandler Hello2 </VirtualHost>
  24. 24. mod_perl2 Hello2.pm• PerlHandler → PerlResponseHandler• Hello2.pm
  25. 25. mod_perl2 Hello2.pm
  26. 26. mod_perl2 Hello2.pm• mod_perl1 mod_perl Apache::• mod_perl2 mod_perl Apache2:: ModPerl:: APR:: mod_perl1 (Apache object ) Mix-in
  27. 27. Hello ...• CGI WAF HTTP• ...
  28. 28. II. mod_perl Apache
  29. 29. mod_perl Apache• HTTP• mod_perl HTTP
  30. 30. Apache• MPM Prefork• (prefork)• HTTP• HTTP ...
  31. 31. Apache••• URL DocumentRoot• (BASIC )• MIME• ( )• ( )•
  32. 32. Apache•• →Apache Module mod_xxxxxx)• Apache Module Perl mod_perl• mod_perl
  33. 33. Apache/mod_perl• : ( )•• Apache/mod_perl 1 2• Apache/mod_perl 2
  34. 34. :mod_perl1 PerlChildInitHandler PerlPostReadRequestHandler PerlInitHandler PerlTransHandler PerlHeaderParserHandler PerlAccessHandler PerlAuthenHandler PerlAuthzHandler PerlTypeHandler PerlFixupHandler PerlFixupHandler PerlHandler PerlLogHandler PerlCleanupHandler PerlChildExitHandler ※http://perl.apache.org/docs/1.0/guide/config.html#toc_Perl_Handlers
  35. 35. :mod_perl1 ※ Practical mod_perl
  36. 36. :mod_perl2 PerlChildInitHandler PerlPostReadRequestHandler PerlInitHandler PerlTransHandler PerlMapToStorageHandler PerlHeaderParserHandler PerlAccessHandler PerlAuthenHandler PerlAuthzHandler PerlTypeHandler PerlFixupHandler PerlFixupHandler PerlResponseHandler PerlLogHandler PerlCleanupHandler PerlChildExitHandler※ http://perl.apache.org/docs/2.0/user/config/config.html
  37. 37. :mod_perl2 ※ Practical mod_perl
  38. 38.
  39. 39. : mod_rewrite• mod_rewrite• URL• ( )
  40. 40. : mod_rewrite• mod_rewrite URL PerlTransHandler•( ) Perl• mod_rewrite PerlTransHandler C API ※ PerlFixupHandler
  41. 41. : mod_rewrite# required “RewriteURL.pm”<VirtualHost A.B.C.D:80> ServerName hello.example.jp PerlTransHandler RewriteURL</VirtualHost>
  42. 42. : mod_rewrite
  43. 43. : mod_rewrite•• sub handler { my $r = shift; ... }•
  44. 44. ••
  45. 45. • PerlPostReadRequestHandler DDoS ( ) • return DONE; # cut off!• PerlAccessHandler• LB iptables
  46. 46. • PerlTransHandler• mod_rewrite PerlTransHandler• URL (return REDIRECT; )
  47. 47. • Perl{Authen,Authz}Handler PHP Cookie Perl• Access,Authen,Authz 3 3A
  48. 48. • HTML• User-Agent *.html Content-Type text/html application/xhtml+xml• PerlTypeHandler PerlFixupHandler ( : $r->headers_in, $r->headers_out)
  49. 49. • HTML </body> (ry• PerlHandler / PerlResponseHandler• $r->print(thiswork(slurp($r->filename())));
  50. 50. • i HTML HTML SBM (ry• PerlHandler / PerlResponseHandler
  51. 51. Kepler/Apache/ConvertEmoji.pm
  52. 52. • HTTP / PerlHandler / PerlResponseHandler ...• PerlLogHandler $r HTTP• DB
  53. 53. • mod_perl HTTP
  54. 54. III. Apache2&mod_perl2 HTTP
  55. 55. Apache2&mod_perl2 HTTP• mod_perl HTTP Request/Response • $r : Apache (mod_perl1) • $r : Apache2::RequestRec (mod_perl2)• $r r request/response r
  56. 56. Apache2/mod_perl2• Apache2 HTTP • ServerLifeCycle • Protocol / Connection • Filter • Thread• mod_perl2 HTTP ※ http://perl.apache.org/docs/2.0/user/config/config.html
  57. 57. Apache2/mod_perl2Connection• Connection• (HTTP )Protocol• Connection HTTP• Apache2 : mod_ssl
  58. 58. Connection PerlPreConnectionHandler PerlProcessConnectionHandler ※ Practical mod_perl
  59. 59. Connection•2 HTTP• PerlPreConnectionHandler • Apache• PerlProcessConnectionHandler • SMTP
  60. 60. Apache2 SMTP•• Postfix pipe Perl I/O fork• DB
  61. 61. Apache2 SMTP• : 2 (load balancing) • SMTP• Apache2 SMTP Postfix ...
  62. 62. Apache2 SMTP• SMTP• Postfix• Apache2 SMTP 1 Postfix
  63. 63. mod_perl2PerlProcessConnectionHandler•• $r $c (Apache2::Connection)• sub handler { my $c = shift; ... }• Apache •
  64. 64. PerlProcessConnectionHandler SMTPListen 10025 gmfilterAcceptFilter gmfilter none<VirtualHost 127.0.0.1:10025> TransferLog /var/log/httpd/gmfilter.log ErrorLog /var/log/httpd/gmfilter_error.log PerlModule Encode::NV ARM::G4::Apache2::GMFilter Apache::DBI PerlProcessConnectionHandler ARM::G4::Apache2::GMFilter</VirtualHost>
  65. 65. PerlProcessConnectionHandler SMTP ARM/G4/Apache2/GMFilter.pm 1:
  66. 66. PerlProcessConnectionHandler SMTP• use• $c use Apache2::Connection• Socket I/O APR::Socket, APR::Brigade, APR::Bucket use
  67. 67. PerlProcessConnectionHandler SMTP ARM/G4/Apache2/GMFilter.pm 2:handler
  68. 68. PerlProcessConnectionHandler SMTP• Socket I/O• Prefork chdir() OK
  69. 69. PerlProcessConnectionHandler SMTP• Postfix pipe Perl DB• : URL: http://rmail.jp/feature/4_5.html•
  70. 70. IV.qpsmtpd & nginx...
  71. 71. • Apache2 Connection SMTP••• qpsmtpd Perl SMTP
  72. 72. qpsmtpd• http://smtpd.develooper.com/•
  73. 73. qpsmtpd• Perl daemon ( POE )• qpsmtpd Engine•
  74. 74. qpsmtpd• qpsmtpd Engine=Transport • pipe (CGI like) • fork-server • prefork-server • Apache (Apache::Qpsmtpd) • async (Danga::Socket base?)
  75. 75. qpsmtpd• Apache::Qpsmtpd•
  76. 76. qpsmtpd• Danga::Socket qpsmtpd• Postfix pipe qpsmtpd
  77. 77. qpsmtpd• Apache SMTP qpsmtpd(Apache::Qpsmtpd)•
  78. 78. nginx• http://nginx.org/•• stable• FastCGI
  79. 79. nginxEmbeddedPerlModule ※ http://wiki.nginx.org/EmbeddedPerlModule
  80. 80. nginxEmbeddedPerlModule ※ http://wiki.nginx.org/EmbeddedPerlModule
  81. 81. nginx EmbeddedPerlModule• mod_perl1• mod_perl1•
  82. 82. nginx EmbeddedPerlModule• worker(single threaded process) I/O• (mod_perl )
  83. 83. nginx EmbeddedPerlModule•• mod_perl1• C10K Apache(mod_perl)
  84. 84. • mod_perl ( )• mod_perl• Apache2/mod_perl2 Connection HTTP (Apache ) Perl(mod_perl)• mod_perl
  85. 85. • Filter • mod_perl1 Filter Apache::Filter, Apache::OutputChain • mod_perl2 Filter Perl{Input,Output}FilterHandler
  86. 86. • mod_perl 3 • Practical mod_perl (Orelly 2003; http://modperlbook.org/) • The mod_perl Developer’s Cookbook (Sams Publishing 2002; http://www.modperlcookbook.org/) • mod_perl2 User’s Guide (Onyx Neon 2007; http://modperl2book.org/)
  87. 87. • Apache C API(mod_*.c) • Apache ( ) (Oreilly 2000; C API mod_perl ) • The Apache Modules Book (Prentice Hall 2007; C API )
  88. 88. • WEB+DB PRESS Vol.33 (2006/6) Recent Perl World 2 mod_perl 2.0• Net::DNS DNS http://gihyo.jp/magazine/wdpress/archive/2006/vol33
  • meganepro

    Jan. 26, 2015
  • tomohiroarakawa10

    Dec. 25, 2014
  • motohirokikkawa

    Feb. 8, 2014
  • seikensato

    Sep. 18, 2013
  • taikisaito330

    Sep. 17, 2013
  • hino0308

    May. 27, 2013
  • maiguchi

    Oct. 11, 2012
  • jun1108

    Sep. 14, 2012

Views

Total views

12,498

On Slideshare

0

From embeds

0

Number of embeds

68

Actions

Downloads

0

Shares

0

Comments

0

Likes

8

×