Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
mod_perl温故知新 〜Perl CGIの高速化からメールサーバまで〜
Search
OGATA Tetsuji
July 16, 2011
Technology
0
7
mod_perl温故知新 〜Perl CGIの高速化からメールサーバまで〜
2011/07/16に Hokkaido.pm#5 で発表したスライドです。
OGATA Tetsuji
July 16, 2011
Tweet
Share
More Decks by OGATA Tetsuji
See All by OGATA Tetsuji
Hokkaido.pmがあって YAPCでトークできた
xtetsuji
0
17
モダンmod_perl入門 #yapcasia
xtetsuji
0
12
札幌でテンプレート #hokkaidopm
xtetsuji
0
20
すごいmod_perl
xtetsuji
0
8
Perl WAF Overview, with mod_perl - Hokkaido.pm#7 #hokkaidopm
xtetsuji
0
8
PerlのTwitterモジュールの紹介
xtetsuji
0
12
mod_perl hacks PHP
xtetsuji
0
5
文字化け2011〜まだまだ化けます〜
xtetsuji
0
11
Other Decks in Technology
See All in Technology
UI State設計とテスト方針
rmakiyama
2
620
サーバレスアプリ開発者向けアップデートをキャッチアップしてきた #AWSreInvent #regrowth_fuk
drumnistnakano
0
200
20241214_WACATE2024冬_テスト設計技法をチョット俯瞰してみよう
kzsuzuki
3
530
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
1
260
Qiita埋め込み用スライド
naoki_0531
0
5.1k
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
210
複雑性の高いオブジェクト編集に向き合う: プラガブルなReactフォーム設計
righttouch
PRO
0
120
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
2
270
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1.1k
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
270
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
110
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
130
Featured
See All Featured
Building Applications with DynamoDB
mza
91
6.1k
Building Adaptive Systems
keathley
38
2.3k
The Cost Of JavaScript in 2023
addyosmani
45
7k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
KATA
mclloyd
29
14k
What's in a price? How to price your products and services
michaelherold
243
12k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Transcript
mod_perlԹނ৽ ʙPerl CGIͷߴԽ͔Β ϝʔϧαʔό·Ͱʙ גࣜձࣾfonfun ඌܗ మ࣍ (OGATA Tetsuji) Twitter:
@xtetsuji 2011/7/16
ࣗݾհͳͲ
ࣗݾհ(1/2) • ඌܗ మ࣍ (OGATA Tetsuji) Twitter: @xtetsuji • http://post.tetsuji.jp/
(࠷ۙϒϩά࢝Ί·ͨ͠) ͜͜ͰޠΓ͖Εͳ͍͜ͱॻ͖͍ͨͰ͢ • ւಓͷԻߋொ(ଳࢢͷྡொ)ग़Ͱ͢ɻ ߴߍଔۀ·Ͱͷ18ؒΛւಓͰա͝͠· ͨ͠
ࣗݾհ(2/2) • ਓੜॳεϐʔΧʔ (͓खॊΒ͔ʹ…) • (ϙετ)ϞμϯPerlʹΕ͍ͯͳ͍30 • JavaScript / Shell
Script(bash) // Emacs Lisp • झຯ: ΫϥγοΫԻָɺΧϑΣࢄࡦɺ ࿏ઢόε
ॴଐհ(1/2) • גࣜձࣾfonfun(ϑΥϯϑΝϯ) http://www.fonfun.co.jp/ • ओྗɿϦϞʔτϝʔϧ http://rmail.jp/ • ҙஂମg15ΞιγΤʔγϣϯ http://g15.jp/
ॴଐհ(2/2) • גࣜձࣾfonfun(چ໊ࣾ:ωοτϏϨοδ) • 1999͔ΒΣϒϝʔϧ (໊:ϦϞʔτϝʔϧ)Λӡ༻ • 2003ʹୈ4ੈγεςϜ(Perl + Apache/
mod_perl + Oracle + Post fi x)Λ։ൃ • ࠷ۙ৽͍ٕ͠ज़తͳࢼΈʹνϟϨϯδத
ࠓճ͓Λ͍ͤͯͨͩ͘͞ ͜ͱʹͳͬͨܦҢ • ݩʹεΧΠΞʔΫγεςϜͱ͍͏ձ͕ࣾ͋Δ • YAPC::Asia2010ͰεϙϯαʔΛ͍ͯ͠ΔͷΛൃݟ • ڵຯ͕͋Δͱݴ͍ͬͯͨΒɺͱ͋Δਓ͕தͷਓ Ͱ͋ΔӬ୩͞Μ(@onagatani)Λհͯ͘͠Εͨ •
͔͠ Hokkaido.pm ͷҒ͍ਓͩͬͨʂ • ͍·͜͜
Agenda
Agenda • I. mod_perlΛৼΓฦͬͯΈ·ͤΜ͔ʁ • II. mod_perlͷਅApacheͷ֦ு • III. Apache2&mod_perl2ͰHTTPͷ֎
• IV. ଵଦͱԠ༻ - qpsmtpd & nginx... • ·ͱΊ
I. mod_perlΛ ৼΓฦͬͯΈ·ͤΜ͔ʁ
͍·͞Β Apache+mod_perl? • ʲ࣭ʳWAFɺPSGI/PlackΛ͑ɺ ApacheͳͲҙࣝ͠ͳ͍͍ͯ͘ͷͰʁ • ʲճʳ͔֬ʹͦ͏͔͠Ε·ͤΜɻ ͚ͩͲɺࣝͱ͓͍ͯͬͯͯ͠ଛ ແ͍ͣͰ͢ •
ྫ͑Plack+mod_perl2Ͱɺมͳόά Λ౿ΜͰ͠·͏͜ͱ͋ΔΑ͏Ͱ͢ ※ http://subtech.g.hatena.ne.jp/cho45/20101221/1292941055 ※1. WAF=Web Application Framework ※1
͍·͞Β Apache+mod_perl? • Apache+mod_perl+WAFͰmod_perlͷ ଆΛଟগ͓͚ͬͯ… • όάΛ౿Μͩ࣌ɺཱͭ • ύϑΥʔϚϯεվળͷώϯτ͕͋Δ
͍·͞Β Apache+mod_perl? • ࠓApache࠷ΘΕ͍ͯΔαʔό • ͲͷLinuxσΟετϦϏϡʔγϣϯʹ େApacheͱmod_perlͷύοέʔδ ඪ४Ͱ༻ҙ͞Ε͍ͯΔ(ͣ)
͍·͞Β Apache+mod_perl? • ࠓApache࠷ ΘΕ͍ͯΔαʔό • ApacheͷγΣΞ 20117݄ݱࡏ65.86% (20116݄ͩͱ64.88%) (http://news.netcraft.com/
archives/2011/07/08/ july-2011-web-server- survey.html ΑΓ) • ͍ͭͷੈҎ্Apache Market Share for Top Servers Across All Domains August 1995 - June 2011
͍·͞Β Apache+mod_perl? • ͍ͭͰθϩ͔Β࠷৽ͷWAFΛͬͯ ։ൃ͕Ͱ͖ΔͱݶΒͳ͍ • डୗҊ݅ίϯςϯπҠҊ݅ͳͲɺ ϨΨγʔͳApacheͱPerl CGI(or PHP)ͷ
Λ͞ΕΔ͜ͱ͋Δେਓͷੈք • ϦϑΝΫλϦϯάɺ ϚΠάϨʔγϣϯ...
mod_perlͷόʔδϣϯ • Apache1.3 → mod_perl1 • Apache2.x → mod_perl2 •
1ͱ2Ͱmod_perlͷจ๏ͷҧ͍େ͖͍ • ྺ࢙ͷڱؒͷmod_perl1.99(ཁҙ) • ※ݱࡏApache1deprecated͕ͩɺੈؒͰݱͱݴ͑ΔͷͰɺmod_perl1 ʹ͍ͭͯɺͳΔ͘৮Ε·͢
mod_perlͷྺ࢙ • mod_perl1 fi rst public release: 1996/3/25 (http://perl.apache.org/dist/mod_perl-1.0-current/Changes ΑΓ)
• mod_perl2 fi rst public release: 2002/4/6 (http://perl.apache.org/dist/mod_perl-2.0-current/Changes ΑΓ)
• mod_perl1 • mod_perl2 • ͜͏ॻ͘͜ͱͰɺ֦ுࢠ”.pl”ͷPerl CGI ͕ߴԽ͢Δ Perl CGI
ͷߴԽ AddHandler perl-script .pl PerlHandler Apache::Registry AddHandler perl-script .pl PerlResponseHandler \ ModPerl::Registry # ↓Apache Con fi gurations
ྫ͑ hello.pl
mod_perl1ͰHello1.pm • ʮϨεϙϯεϋϯυϥʯΛॻ͘ • ϨεϙϯεϋϯυϥͱɺୈҰҾʹϦΫ ΤετΦϒδΣΫτ($r)Λड͚औΔ handler αϒϧʔνϯ͕ఆٛ͞Εͨύοέʔδ • http://hello.example.jp/
ҎԼʹΞΫηεͨ͠ Βɺว͘ Content-Type: text/plain Ͱఆܗͷѫ ࡰ͢Δ͚ͩͷαϯϓϧΛ࡞ͬͯΈΔ
mod_perl1ͰHello1.pm # apache1.3 con fi guration <VirtualHost A.B.C.D:80> ServerName hello.example.jp
SetHandler perl-script PerlHandler Hello1 </VirtualHost>
mod_perl1ͰHello1.pm
mod_perl2ͰHello2.pm • ಉ༷ͷαϯϓϧΛ࡞ • جຊmod_perl1ͱಉ͡ • จ๏݁ߏҧ͍·͢
mod_perl2ͰHello2.pm # apache2.x con fi guration <VirtualHost A.B.C.D:80> ServerName hello.example.jp
SetHandler perl-script PerlResponseHandler Hello2 </VirtualHost>
mod_perl2ͰHello2.pm • PerlHandler → PerlResponseHandler ໊લ͕Α͏͘໌շʹͳͬͨ • ͨͩ Hello2.pm ͷίʔυ݁ߏҧ͍·͢
mod_perl2ͰHello2.pm
mod_perl2ͰHello2.pm • mod_perl1mod_perlͷύοέʔδ໊લ ۭؒ Apache:: ͷΈ • mod_perl2mod_perlͷύοέʔδ໊લ ۭ͕ؒ Apache2::ɺModPerl::ɺAPR::
ͱ ࡉԽ͞Εɺmod_perl1ͷڊେͳΫϥε (Apache object)Mix-inతʹׂ͞Εͨ
Helloͱѫࡰͯ͠... • ࠓ·Ͱ͖ͬͯͨͷCGIWAFͰ Ͱ͖Δ؆୯HTTPϨεϙϯεΛฦ͢ॲཧ • Α͏͘ຊ...
II. mod_perlͷਅ Apacheͷ֦ு
mod_perlͷਅ Apacheͷ֦ு • ࠓ·Ͱݟ͖ͯͨͷɺHTTPϨεϙϯε Λฦ͢ॲཧ • mod_perlHTTPϨεϙϯεΛฦ͚ͩ͢ Ͱͳ͘ɺͦͷલॲཧޙॲཧͰ͖Δ
Apacheͷ෦ॲཧ • MPMଟ͘ΘΕ͍ͯΔPreforkΛԾఆ • ϓϩηεΛىಈ͢Δͱɺઃఆʹैͬ ͯࢠϓϩηεΛઃఆͷ͚ͩىಈ (prefork) • ֤ࢠϓϩηεHTTPϦΫΤετΛͭ •
Ͱࢠϓϩηε͝ͱͷHTTPॲཧ...
Apacheͷ෦ॲཧ • ϦΫΤετΛड͚Δ • ϔομΛղੳ͢Δ • ඞཁʹԠͯ͡URLΛมͨ͠ΓɺDocumentRootΛख͕͔Γʹ࣮ύε ΛׂΓग़͢ • ΞΫηε੍ޚɺೝূɺঝೝ(BASICೝূͳͲ)
• MIMEλΠϓΛߟ͑Δ • ϨεϙϯεΛग़͢(੩తϑΝΠϧɺϓϩάϥϜग़ྗ) • ϩά(ΞΫηεϩάɺΤϥʔϩά)Λग़ྗ͢Δ • ࣍ͷϦΫΤετΛͭ
Apacheͷ෦ॲཧ • ͬ͘͟Γྻڍ͚ͨͩ͠ͳͷʹϏογϦ • ֤ॲཧΛߦ͍ͬͯΔ෦ʹϑοΫ͕͋ͬͯɺ ͜͜ʹ֤छॲཧΛڬΉ͜ͱ͕Մೳ →Apache Moduleʢmod_xxxxxx) •Apache Module
ͰͰ͖Δ͜ͱΛ Perl ͰͰ͖ ΔΑ͏ʹͨ͠ͷ͕mod_perl • ͜Ε͕mod_perlͷਅͰ͢
Apache/mod_perl ॲཧϑΣʔζ • ֤ϑοΫ͕͋Δ෦: ʮ(ॲཧ)ϑΣʔζʯ • ϦΫΤετͪঢ়ଶ͔Β֤ϑΣʔζΛҰ ८͢ΔͷͰɺશମΛʮϦΫΤεταΠΫ ϧʯͱݺͼ·͢ •
Apache/mod_perlͷ1ͱ2Ͱ݁ߏҧ͍·͢ • Apache/mod_perlͷ2ͷ΄͏͕ߴػೳ
ॲཧϑΣʔζ: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/con fi g.html#toc_Perl_Handlers
ॲཧϑΣʔζ:mod_perl1 ※ʮPractical mod_perlʯΑΓൈਮ
ॲཧϑΣʔζ: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/con fi g/con fi g.html
ॲཧϑΣʔζ:mod_perl2 ※ʮPractical mod_perlʯΑΓൈਮ
࣮ྫ • ࣌ؒͷ߹্ɺଟ͘Λ͝հͰ͖·ͤ Μ͕ɺগ࣮͠ྫΛݟͯΈ·͠ΐ͏
࣮ྫ: mod_rewriteͷ ϦϑΝΫλϦϯά • Α͘ΘΕ͍ͯΔ͝ଘmod_rewrite • ୯७ͳURLਖ਼نදݱஔʹศར • ͨͩɺॲཧߦ͕ଟ͘ͳ͖ͬͯͨΓɺ (ؤுΕॻ͚Δ͕)݅ذ෮ॲཧ
ʹखΛग़͢ͱ్ʹࠇຐज़Խ
࣮ྫ: mod_rewriteͷ ϦϑΝΫλϦϯά • mod_rewriteॲཧΛɺURLΛॻ͖͑Δ ϑΣʔζͷPerlTransHandlerͰ࣮͢Δ • (͏ͳΒ)݅ذ෮ॲཧ͕Perlͷ ίʔυʹͳΔͷͰՄಡੑ͕Α͘ͳΔ •
mod_rewriteࣗPerlTransHandlerʹରԠ ͢ΔC APIͷϑΣʔζͰಈ࡞͍ͯ͠·͢ ※࣮ࡍPerlFixupHandlerʹରԠ͢ΔϑΣʔζͰ͓ࣄΛ͍ͯ͠·͢
࣮ྫ: mod_rewriteͷ ϦϑΝΫλϦϯά # required “RewriteURL.pm” <VirtualHost A.B.C.D:80> ServerName hello.example.jp
PerlTransHandler RewriteURL </VirtualHost>
࣮ྫ: mod_rewriteͷ ϦϑΝΫλϦϯά
• ʮϨεϙϯεϋϯυϥʯͱಉ͡Α͏ͳ จࣈ௨ΓʮϋϯυϥʯΛॻ͖·͢ • sub handler { my $r =
shift; ... } • ଞͷϑΣʔζͰ͜ͷॻ͖ग़͠ఆੴ ࣮ྫ: mod_rewriteͷ ϦϑΝΫλϦϯά
ଞʹͰ͖Δ͜ͱҰྫ • ֤ϑΣʔζͰ͜Μͳ͜ͱ͕Ͱ͖ΔΑʂ ͱ͍͏֓೦͚ͩ͝հ͠·͢ɻ • ࣮ࡍͷମݧஊΛଟ͘Γ͜ΜͰΈ·͢
ଞʹͰ͖Δ͜ͱҰྫ • PerlPostReadRequestHandler औΓٸ͗ѱ࣭ͳDDoSΛःஅ(Ԡٸાஔ) • return DONE; # cut off!
• ຊདྷPerlAccessHandlerͰ͢Δͷ͕ྑ͍ • ࠷ऴతʹLBiptablesͰःஅ͔ͳ
ଞʹͰ͖Δ͜ͱҰྫ • PerlTransHandlerຊʹཱͪ·͢ • mod_rewrite͕εΠεΞʔϛʔφΠϑ ͳΒɺPerlTransHandlerϓϩͷྉཧਓ ͕͏ߴڃแஸʁͦΕͱຊʁ • URLॻ͖͚͑ͩͰͳ͘ϦμΠϨΫτ વͰ͖·͢(return
REDIRECT; ͳͲ)
ଞʹͰ͖Δ͜ͱҰྫ • Perl{Authen,Authz}Handler γϯάϧαΠϯΦϯ࣮ PHPͰϨεϙϯεॲཧʹೖΔલʹ CookieॲཧͳͲΛPerlͰߦ͑Δ • Access,Authen,Authzͷ3छ3Aͱݺ ΕΔɻΞΫηε੍ޚɺೝূɺڐՄɻ
ଞʹͰ͖Δ͜ͱҰྫ •طʹେྔͷHTMLϑΝΠϧͷ͋Δ੩తαΠτΛड ͚औͬͨϓϩάϥϚͷݽ܉ฃಆ • ґཔʮUser-AgentΛݟͯ *.html ͷ Content-Type Λ text/html
͔ application/xhtml+xml ͔ɺग़͚ͯ͠͠ ͍͚ͨͩ·͔͢ʁʯ • PerlTypeHandler ͔ PerlFixupHandler ͰΓ·͠ΐ͏ (ೖग़ྗϔομॲཧ: $r->headers_in, $r->headers_out)
ଞʹͰ͖Δ͜ͱҰྫ • ґཔʮΞϑΟϦΤΠτͰશͯͷHTML ϑΝΠϧͷ</body>ͷલʹಈతʹίʔυ ΛೖΕ͍͖ͯͨͩ(ryʯ • PerlHandler / PerlResponseHandler Λ͑
͓खܰʹղܾ • $r->print(thiswork(slurp($r-> fi lename())));
ଞʹͰ͖Δ͜ͱҰྫ • ґཔʮiϞʔυHTMLͰॻ͔Εͨֆจࣈ ೖΓ੩తHTML͕େྔʹ͋ΔΜͰ͕͢ɺ SBM͕དྷͨΒม(ryʯ • ͜Ε PerlHandler / PerlResponseHandler
Ͱ͓ख͔ܰͭಁա తʹղܾ͠·͠ΐ͏
ଞʹͰ͖Δ͜ͱҰྫ ࣾίʔυ Kepler/Apache/ConvertEmoji.pm ΑΓൈਮ
ଞʹͰ͖Δ͜ͱҰྫ • HTTPϨεϙϯεग़ྗॲཧ / PerlHandler / PerlResponseHandler ͕ྃͨ͠ޙ... • PerlLogHandler$r͔ΒHTTPϨεϙϯε
݁Ռૹ৴αΠζ͕औಘՄೳͳঢ়ଶ • ༷ʑͳDBʹϩάΛॻ͖ग़ͨ͠Γ௨Λ ͨ͠ΓͰ͖·͢
ଞʹͰ͖Δ͜ͱҰྫ • ଞʹຊʹ৭ʑͳ͍ํ͕Ͱ͖Δ mod_perlͷHTTPॲཧͰ͕͢ɺͦΖͦΖ ࣍ͷʹҠΓ·͢
III. Apache2&mod_perl2 ͰHTTPͷ֎
Apache2&mod_perl2Ͱ HTTPͷ֎ • ઌ΄Ͳհͨ͠mod_perlͷॲཧϑΣʔ ζHTTP Request/Responseͷ͓ • $r : Apache
(mod_perl1) • $r : Apache2::RequestRec (mod_perl2) • ׳श໊ $r ͷ r request/response ͷ r
Apache2/mod_perl2 Ͱͷ৽ઃαΠΫϧ • Apache2ʹHTTPΛѻ͏Ҏ֎ͷαΠΫϧ͋Δ • ServerLifeCycle ؔ࿈ • Protocol /
Connection ؔ࿈ • Filter ؔ࿈ • Thread ؔ࿈ •વmod_perl2ͰɺͦΕΛͬͯHTTPҎ֎ͷॲ ཧ͕ॻ͚Δ ※ http://perl.apache.org/docs/2.0/user/con fi g/con fi g.html Λࢀর
Apache2/mod_perl2 Connection αΠΫϧ • ࠓճConnectionαΠΫϧʹ • (HTTPͰͳ͍)ProtocolαΠΫϧͱ • ConnectionαΠΫϧHTTPΛѻ͏ αΠΫϧɾϑΣʔζΑΓલʹҐஔ͢Δ
• Apache2ͰͷԠ༻ྫ: mod_ssl
Connection αΠΫϧͷ ॲཧϑΣʔζ PerlPreConnectionHandler PerlProcessConnectionHandler ※ʮPractical mod_perlʯΑΓൈਮ
• 2͚ͭͩɻHTTPΑΓγϯϓϧʁ • PerlPreConnectionHandler • Apacheॲཧͷຊʹ಄ʹҐஔ͢Δ • PerlProcessConnectionHandler •ࠓճ͜͜ʹSMTPαʔόΛ࡞Γ·͢ Connection
αΠΫϧͷ ॲཧϑΣʔζ
Apache2 SMTPαʔόͷ ࡞ಈػ • ։ൃ༰ϝʔϦϯάϦεταʔϏε • Post fi x pipeΛ͑PerlϓϩάϥϜͰI/O
ॲཧ͕ॻ͚Δ͕ɺforkͷίετ͕ߴ͍ • ॏ͍DBॲཧɺֆจࣈॲཧ͕͔ͨͬͨ͠
Apache2 SMTPαʔόͷߏ • ϋʔυΣΞߏ: 2(load balancing) • ֎෦ͱͷૹड৴SMTPαʔόɺطʹ ՔಇதͷผͷϋʔυΣΞेఔ
ͷΫϥελ͕͋Δ • ʮApache2 SMTPαʔόʯͷ෦Ͱɺ Post fi xʹड৴ͱૹ৴ͷॲཧΛґཔ...
Apache2 SMTPαʔόͷߏ •ҹSMTPͷྲྀΕ •αʔόͰ྆ͰPost fi xΛߏ͑ ͍ͤͯ͞ΔͷɺࡶͳΩϡʔ ͷཧΛল͖͍ͨࢥ͕͋Δ •Apache2
SMTP αʔό͕1ͭͷ Post fi x͔ΒݟͯผϙʔτͰಈ࡞ ͍ͯ͠ΔίϯςϯπϑΟϧλͷ Α͏ʹՔಇ͢Δ
mod_perl2Ͱ PerlProcessConnectionHandler • ʮίωΫγϣϯϋϯυϥʯΛॻ͘ • ࠓ·Ͱͷ$rͱҧ͍$c (Apache2::Connection) ΦϒδΣΫτΛୈҰҾʹड͚औΔ • sub
handler { my $c = shift; ... } • Apacheͷઃఆ • ࣮ࡍͷྫΛհ͠·͕͢ɺ͍ͷͰൈਮ
PerlProcessConnectionHandler Ͱॻ͍ͨSMTPαʔόͷৄࡉ Listen 10025 gm fi lter AcceptFilter gm fi
lter none <VirtualHost 127.0.0.1:10025> TransferLog /var/log/httpd/gm fi lter.log ErrorLog /var/log/httpd/gm fi lter_error.log PerlModule Encode::NV \ ARM::G4::Apache2::GMFilter \ Apache::DBI PerlProcessConnectionHandler \ ARM::G4::Apache2::GMFilter </VirtualHost>
PerlProcessConnectionHandler Ͱॻ͍ͨSMTPαʔόͷৄࡉ ࣾίʔυ ARM/G4/Apache2/GMFilter.pm ΑΓൈਮ1:಄෦
PerlProcessConnectionHandler Ͱॻ͍ͨSMTPαʔόͷৄࡉ • ϙΠϯτɿॏ͍ͨϞδϡʔϧΛେྔʹ useͯ͠େৎʂ • $cͷͨΊʹ use Apache2::Connection •
Socket I/OॲཧͷͨΊʹAPR::Socket, APR::Brigade, APR::Bucketuse͢Δ
PerlProcessConnectionHandler Ͱॻ͍ͨSMTPαʔόͷৄࡉ ࣾίʔυ ARM/G4/Apache2/GMFilter.pm ΑΓൈਮ2:handler෦
PerlProcessConnectionHandler Ͱॻ͍ͨSMTPαʔόͷৄࡉ • Socket I/Oͷѻ͍ํ͞·͟· • ͪͳΈʹPreforkͳͷͰchdir()ͯ͠OK
PerlProcessConnectionHandler Ͱॻ͍ͨSMTPαʔόͷৄࡉ • ͜͏ͯ͠ɺPost fi x pipeΛΘͣʹɺPerl ΛͬͯDBଓ͋Γɺֆจࣈม͋Γ ͷϝʔϦϯάϦεταʔϏεΛ࣮͢ Δ͜ͱ͕Ͱ͖ͨ
• αʔϏε໊: άϧʔϓϝʔϧ • ػձ͕͋ΕΑΖ͓͘͠ئ͍͠·͢ URL: http://rmail.jp/feature/4_5.html
IV. ଵଦͱԠ༻ qpsmtpd & nginx...
θϩ͔Βॻ͘ͷ໘ • Apache2 ConnectionϑΣʔζͰSMTPαʔ όΛ࣮Ͱ͖Δͷ͔ͬͨ • ͚ͩͲθϩ͔Β࣮͢ΔͳΜͯ໘ • ͬ͝ͱ •
ͦΜͳਓͷͨΊʹɺqpsmtpdͱ͍͏ Perl࣮ͷSMTPαʔό͕͋Γ·͢
qpsmtpd • http://smtpd.develooper.com/ • ։ൃ࣌ଘࡏΛฉ͖ٴΜͰ͍͕ͨɺ αʔόݎ࿚ੑΛ͏·͘ධՁͰ͖ͳ͔ͬ ͨͷͰ࠾༻Λݟૹͬͨ
qpsmtpd࣮ݎ͍ • Perlͷdaemonʹ͍͍ҹ͕ͳ͔ͬͨ (࣌ͷPOE) • qpsmtpdͷEngineతͳΈͰબΔ • ͔͠ϝχϡʔ๛
qpsmtpd࣮ݎ͍ • qpsmtpdͷࠜఈΛࢧ͑ΔEngine=Transport • pipe (CGI like) • fork-server •
prefork-server •Apache (Apache::Qpsmtpd) • async (Danga::Socket base?)
qpsmtpd࣮ݎ͍ • Apache::Qpsmtpdͱ͔ɺ͋Δ͠ʂ • ޙͰιʔείʔυݟͨΒɺฐࣾͰ࣮ફ ͨ͠άϧʔϓϝʔϧͷ࣮ͦͷͷ
qpsmtpd࣮ݎ͍ • Danga::Socketϕʔεݎͦ͏ͩ͠ɺ࣍ qpsmtpdͰͳ͍ͱࢥͬͨ • ݱࡏPost fi x pipeͰՔಇ͍ͯ͠Δɺฐࣾ ண৴௨ϓϩάϥϜΛqpsmtpdͰॻ͖͔
͍͑ͨͱࢥ͏΄Ͳɺࠓྑ͍ҹΛ ͍࣋ͬͯΔ
qpsmtpd·ͱΊ • ͳͷͰࠓճʮApacheͰಈ࡞͢ΔSMTP αʔόʯʹڵຯΛ࣋ͬͨํ qpsmtpd(Apache::Qpsmtpd)ʹ৮ΕΔͱ͍ ͍Ͱ͢ • ϓϥάΠϯϞμϯͳॻ͖ํͰྑ͍
nginx • http://nginx.org/ • ࠓͷΣϒαʔό • ࠓͷय़ʹstable͕ొͯ͠ීٴʹΈ • FastCGIͷಈ࡞ڥͱͯ͠ΘΕΔ
nginxͷ EmbeddedPerlModule ※ http://wiki.nginx.org/EmbeddedPerlModule ΑΓ
nginxͷ EmbeddedPerlModule ※ http://wiki.nginx.org/EmbeddedPerlModule ΑΓ
nginxͷ EmbeddedPerlModule • ͍͢͝mod_perl1ͬΆ͍ • ࣮ࡍɺେ෦ͷϝιουmod_perl1ͱ ͦͬ͘Γಉ͡ • গ͠ҧ͍͕͋ΔͷͰҙ͕ඞཁͳఔ
nginx EmbeddedPerlModule ҙ • worker(single threaded process)ͷಛੑ্ ͱ͋ΔϦΫΤετͰ࣌ؒI/OΛϒϩο Ωϯά͢Δͱαʔόશମ͕ࢭ·Γ·͢ •
(mod_perlʹൺͯ)ϊϋ͕গͳ͍
nginx EmbeddedPerlModule ·ͱΊ • ҙ͋Δ͕ັྗతɺ໘നͦ͏ • mod_perl1ษڧ͓͍ͯͯ͠ྑ͔ͬͨʂ • C10KͳͲաࠅͳʹཱ͔ͪ͏ ߹ɺੑೳʹ಄ଧͪײ͕͋Δ
Apache(mod_perl)ͷ༗ྗͳସͱͳΓ͏ Δ
·ͱΊ
·ͱΊ • ࠓͰmod_perlͷࣝΛ͓ͬͯ͘ͱɺ͍͟ͱ͍ ͏ͱ͖ྑ͍͜ͱ͕͋Δ(͔) • mod_perlͷจ๏ଞͷʹӨڹΛ༩͍͑ͯΔ • Apache2/mod_perl2Connectionॻ͚ͯɺHTTP Ҏ֎ͷҙͷ(Apacheͱಉఔͷ)ݎ࿚ͳαʔό͕ Perl(mod_perl)Ͱ࣮Մೳ
• ฐࣾͰ༷ʑͳܗଶͰmod_perlΛ׆༻͍ͯ͠·͢
ࠓճ৮ΕΒΕͳ͔͚ͬͨͲ ڵຯਂ͍τϐοΫ • Filter • mod_perl1 ٖࣅFilterؔ࿈ Apache::Filter, Apache::OutputChain •
mod_perl2 ωΠςΟϒFilterؔ࿈ Perl{Input,Output}FilterHandler
ࢀߟจݙ • ༸ॻʹͳΓ·͕͢ɺ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/)
ࢀߟจݙ • Apache C API(mod_*.c)ͷࢀߟॻ੶ • Apache֦ுΨΠυ(্ɾԼ) (Oreilly 2000; C
APIΛmod_perlʹԊͬͯղઆͨ͠ྑॻͰ͕ͨ͠ ݱࡏઈ൛ͩͦ͏Ͱ͢) • The Apache Modules Book (Prentice Hall 2007; ͪ͜ΒશʹC APIͷຊ)
ࢀߟจݙ • 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
͝ਗ਼ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠