SlideShare a Scribd company logo
『Ficia』インフラと
 Perlにまつわる
   エトセトラ
    ひろせ まさあき
     id:hirose31
自己紹介

• ひろせ まさあき
 • id:hirose31
 • http://twitter.com/hirose31
• えとらぼ(株)
 • インフラの設計・構築・運用管理
http://ficia.com
アジェンダ
I. mod_perl 2 Tips & Tricks

 • メモリ関係のパラメータチューニング
 • Tips 3
II. 構成・運用支援ツールとPerl

 • MATRIXとその周辺
I
 mod_perl 2
Tips & Tricks

         Linux kernel 2.6.29.X
         Apache 2.2.X (Prefork)
         mod_perl 2.0.4
mod_perl 2 Tips & Tricks




           メモリ関係の
            パラメータ
           チューニング
推測するな
計測すべし
計  測
    ↓
パラメータの調整
メモリ使用量の計測
• ざっくりなら
 • ps, top
• fork(2) - Copy on Write
 • 書き込みがあるまで親プロセスと同
  じページをポイント

 • 親との共有領域と固有領域
CoW
  httpd                 httpd          httpd

 libperl               libperl        libperl
loaded                loaded         loaded
modules        fork   modules        modules
(startup.pl)          (startup.pl)   (startup.pl)

 variables                            variables
                       variables




   親                     子              子
CoW
  httpd                 httpd          httpd

 libperl               libperl        libperl
loaded                loaded         loaded
modules        fork   modules        modules
(startup.pl)          (startup.pl)   (startup.pl)

 variables                            variables
                       variables
                                     loaded
                                     modules
                                      variables




   親                     子              子
共有領域の計測

• /proc/PID/smaps (kernel >=2.6.14)
 • 共有領域 = Shared_Clean + Shared_Dirty
• shared_memory_size.pl $(pgrep httpd)
 • use Linux::Smaps
 • id:naoya♥♥
PID      VSZ     RSS   SHARED
20765   346040   59376    59064   (   99%)
20768   346040   59376    59064   (   99%)
20799   346040   59376    59064   (   99%)
20802   346040   59376    59064   (   99%)
PID      VSZ     RSS    SHARED
20765   346040   59376     59064   (   99%)
20768   346040   59376     59064   (   99%)
20799   346040   59376     59064   (   99%)
20802   346040   59376     59064   (   99%)


  PID      VSZ      RSS   SHARED
20765   433476   113716    45844   (   40%)
20768   433032   113432    46736   (   41%)
20799   434688   115000    45736   (   39%)
20802   435160   115548    45728   (   39%)
太る
  PID      VSZ     RSS    SHARED
20765   346040   59376     59064   (   99%)
20768   346040   59376     59064   (   99%)
20799   346040   59376     59064   (   99%)
20802   346040   59376     59064   (   99%)


  PID      VSZ      RSS   SHARED
20765   433476   113716    45844   (   40%)
20768   433032   113432    46736   (   41%)
20799   434688   115000    45736   (   39%)
20802   435160   115548    45728   (   39%)
太る#1 原因

• 子プロセスが、後でロードしたモジュー
 ルの分

• CoW故に
※子プロセス間ではメモリ共有はしない
太る#1 対策
• 使うモジュールは起動時に親プロセスでロード
 する

 • PerlPostConfigRequire startup.pl
• モジュールの一覧は?
 • PerlResponseHandler Apache2::Status
   • Loaded Modules で一覧を確認
☺ロード済みなので即戦力
太る#2 原因
• Perl内でのメモリアロケーション
 • メモリプール的な?
• もりもり太る例
 • slurp的な一気読み
 • File::Find - 再帰のせい?
• パフォーマンス、利便性との兼ね合い
太る#2 対策
• 太っているモジュールを探す
 • Apache2::Status + B::TerseSize
 • Memory Usage で一覧を確認
太る#2 対策
• メモリ食いのモジュールを:
 • 他のモジュールを使う
 • コードに手を入れる
 • スルー
計  測
    ↓
パラメータの調整
httpd.conf

StartServers
MinSpareServers
MaxSpareServers
MaxClients
MaxRequestsPerChild
httpd.conf
• {Start,{Min,Max}Spare}Servers,
 MacClient

 • smapsの結果と搭載メモリを鑑みて計算
 • 増減があるので、実際に変更して様子を
   見る

   • 「swapしたら負けかなと思ってる」
httpd.conf
• {Start,{Min,Max}Spare}Servers,
 MacClient

 • 全部同じ値にして、起動時に一気に
   fork(2)する

   • reqが来てはじめてよっこらせと
    fork(2)するのは時間がもったいない

   • 起動時にload avgが上がるのは運用で
    回避(Tipsで後述)
StartServers
         {Min,Max}Spare
#procs




               t
StartServers
         {Min,Max}Spare

                 fork!
#procs




             fork!

           fork!

         fork!



                         t
StartServers
         {Min,Max}Spare

                 fork!          fork!
#procs




             fork!
                               fork!
           fork!
                              fork!
         fork!
                             fork!



                         t
StartServers
         ={Min,Max}Spare
#procs




         idle




                t
StartServers
         ={Min,Max}Spare
fork!

fork!
#procs




fork!
         idle
fork!

fork!


                t
StartServers
         ={Min,Max}Spare
fork!

fork!           ♪∼
#procs




fork!
         idle
fork!

fork!


                     t
StartServers
         ={Min,Max}Spare
fork!

fork!           ♪∼       ♪∼
#procs




fork!
         idle
fork!

fork!


                     t
Apache Process
    Report
httpd.conf
• MaxRequestsPerChild
 • そこそこ小さい値に
 • 早期刈り取り
   • 肥大化
   • リーク
httpd.conf

StartServers          42
MinSpareServers       42
MaxSpareServers       42
MaxClients            42
MaxRequestsPerChild   64
httpd.conf

PerlOptions +Clone

PerlOptions +Parent
PerlOptions
• Clone
 • VirtualHostごとにインタプリタ
  プールを持つ (threadモードのとき
  のみ?)

• Parent
 • VHごとにインタプリタプールを持つ
  (=Clone)

 • VHごとに親インタプリタを持つ
+Parent

• VirtualHostごとに空間を分離できる
 • メモリ空間
 • 名前空間
• 反面、メモリ使用量が増える
 • multi Parent VS multi instance
mod_perl 2 Tips & Tricks




              Tips         3
#1 PerlSwitches
   とsymlink
• PerlSwitches
 • -I/path/to/mylibdir
 • -Mlib=/path/to/mylibdir
• 指定パスがsymlinkだと探しに行かない
 • failed to resolve handler...
#2 VirtualHostごとに
 ErrorLogを吐きたい
 • トップレベルのserverコンテキストの
     ErrorLogに出力されてしまう
warn "Test: warn";             #   warn
die "Test: die";               #   die
eval q[my $v2 = "3:" + 4;];    #   eval
my %h1 = qw(foo bar baz);      #   実行時エラー


print STDERR "Test: STDERRn"; # STDERR
my $v1 = "2:" + 3;             # use warnings
(undef) . "xxx";               # use warnings
#2 VirtualHostごとに
 ErrorLogを吐きたい
 • warn            #httpd.conf
                   PerlOptions ... +GlobalRequest
 • die
 • eval
                   #Handler
                   use Apache2::Log ();

 • 実行時エラー          $SIG{__WARN__} =
                     &Apache2::ServerRec::warn;




•   STDERR         *STDERRをtieしてprint STDERRを
                   Apache2::ServerRec::warnにする




•   use warnings            未解決 情報求む!
#3 init.d/httpd
• 問題点
• stop
 • stopしたのに新規リクエストが来ちゃう
 • ロードバランサのヘルスチェック間隔
• start
 • 起動直後にリクエストがきちゃう
 • fork(2)しまくって高負荷なのでちょっ
  と待ちたい
#3 init.d/httpd
• httpdが生きている状態でも、LBの
  VirtualServerGroup(VSG)から離脱できる
  ようにする

• LBのヘルスチェックURLを動的なものに
 • curl -H ‘Host: health’ http://svXXX/alive.php
 • フラグファイルによってres codeを変える
   •   touch -t '+1 hours' /tmp/stop-sv

 • now - mtime <= 5分 ? 503 : 200
#3 init.d/httpd
• stop
 • configtest
 • ロードバランサのVSGから離脱
 • apachectl -k graceful-stop
 • clear semaphore (ipcs -s, ipcrm)
• start
 • VSGに参加しないようにする
 • configtest
 • apachectl -k start
 • sleep 3 && VSGに復帰
続いて
II
構成・運用支援ツール
   とPerl
問題提起
• サーバがたくさんあると・・・
 • どのサーバがどの役割だっけ?
 • 1サーバで複数の役割を持ってるさらに混乱
 • 役割変更のたびにOSインストールと
   か・・・
• 管理情報がいろんなところにあって収集つか
  ない
解決案

• 構成管理情報の一元管理
• テキスト形式
 • 人が読めて編集できる
• 数十台ならこんな簡単な形式でもOK
svNNN
realname               MATRIX                    (XXX)
                                                  remark

              sv101:   <lv1>
              sv102:   <ll2>                       [TTNNN]
              sv103:   <lv2>                        Complex
              sv104:   <ll1>
<TTNNN>
 systemname   sv105:   <co1>     (core)
 Archetyp     sv106:   <co2>
              sv107:   <ap101>   ficia irori [mc101]
                                                           XXXXX
              sv108:   <ap102>   ficia *FREE*              assigned prj
              sv109:   <ht101>   ficia irori [qu101]
              sv110:   <ht101>   [qu102]
              sv111:   <db101>   (db100)
              sv112:   <db102>                     *XXX*
              sv113:   <st101>   (st100)            special state
              sv114:   <st102>
              sv115:   <ap103>   ficia *STOP*
Archetyp
          and
        Complex



sv101       sv102       sv103

        /           /           /
Archetyp
                and
              Complex


      core                    Web
                  Web         static
                  app
      sv101       sv102       sv103
Archetyp      /           /            /
Archetyp
                 and
               Complex
 Q4M
                                kumo
                   Q4M                        log
       core
                         kumo     Web
                    Web           static
                    app         mcd
       sv101        sv102             sv103
Archetyp       /            /                   /
Complex
MATRIXの反映

• activate-matrix (with Perl)
 • 3 steps
   1.ActivateMATRIX::Generate::*

   2.ActivateMATRIX::Execute::*

   3.ActivateMATRIX::Suggest::*
Generate

• as YAML
 • ganglia (PHP)
 • Archer (Perl)
• Nagios host.cfg
• OS起動時に読む用(役割切り替え)
 • shでハンドリングしやすい形式
Execute

• 起動時にMATRIXを読んで、あとは参照せず
 にループするdaemonの類いを再起動/再読
 み込み

• monitor-ping (AnyEvent::FastPing)
Suggest

• 残作業とかを表示
 • 自動でやるのはちと怖いのとか
• ロードバランサへの反映手順
 • generate config, copy , diff, apply
MATRIXと
         その周辺

edit!    MATRIX
        sv101:   <lv1>
        sv102:   <ll2>
        sv103:   <lv2>
        sv104:
        sv105:
        sv106:
                 <ll1>
                 <co1>
                 <co2>
                           (core)                           ...
        sv107:   <ap101>   ficia irori [mc101]
        sv108:   <ap102>   ficia *FREE*
        sv109:   <ht101>   ficia irori [qu101]
        sv110:
        sv111:
                 <ht101>
                 <db101>
                           [qu102]
                           (db100)               activate
        sv112:   <db102>
        sv113:
        sv114:
        sv115:
                 <st101>
                 <st102>
                 <ap103>
                           (st100)

                           ficia *STOP*
                                                  matrix    ...
まとめ
I. mod_perl 2 Tips & Tricks

 • メモリ関係のパラメータチューニング
 • Tips 3
II. 構成・運用支援ツールとPerl

 • MATRIXとその周辺
ご清聴ありがとう
 ございました

More Related Content

PDF
тупицын Ec2 Rootconf2009
Liudmila Li
 
PDF
за Ruby
Stefan Kanev
 
PDF
What Can Compilers Do for Us?
National Cheng Kung University
 
PDF
WindowsユーザのためのはじめてのPerlプログラミング
Yosuke HASEGAWA
 
PDF
Grails紹介
Uehara Junji
 
PDF
Postgre Sql 8 4
Liudmila Li
 
PPTX
vSphere Launch Business Keynote - Москва, 26 мая
Anton Antich
 
DOCX
Zurag
na_suugii
 
тупицын Ec2 Rootconf2009
Liudmila Li
 
за Ruby
Stefan Kanev
 
What Can Compilers Do for Us?
National Cheng Kung University
 
WindowsユーザのためのはじめてのPerlプログラミング
Yosuke HASEGAWA
 
Grails紹介
Uehara Junji
 
Postgre Sql 8 4
Liudmila Li
 
vSphere Launch Business Keynote - Москва, 26 мая
Anton Antich
 
Zurag
na_suugii
 

What's hot (15)

PDF
Hasql in practice (Russian)
Alexander Vershilov
 
PDF
Обеспечение безопасности web приложений
SQALab
 
PDF
Groovy Vs Perl
mayperl
 
PDF
колышкин Rootconf 2009 Openvz
Liudmila Li
 
DOCX
Doctype htmlcodigioooooo
ANDERSON FABIAN
 
PDF
spring_jiaocheng
Shilong Sang
 
PPTX
Ruby on Rails Tutorial Part I
Wei Jen Lu
 
PDF
Reloaded
Shunsaku Kudo
 
PDF
ブラウザでMap Reduce風味の並列分散処理
Shinya Miyazaki
 
PDF
【13-C-4】 「もう業務はとまらない!オフライン機能を使った業務アプリケーションの実例と最新 Curl 情報」
devsumi2009
 
PDF
Intro To RDBMS And SQL Server 2005 - Svetlin Nakov
Svetlin Nakov
 
PDF
20090410 Gree Opentech Main
Hideki Yamane
 
PDF
20090418 イケテルRails勉強会 第2部Air編
mochiko AsTech
 
PDF
Install Moodle
gueste8192c
 
PDF
数学物理漫谈
Xu jiakon
 
Hasql in practice (Russian)
Alexander Vershilov
 
Обеспечение безопасности web приложений
SQALab
 
Groovy Vs Perl
mayperl
 
колышкин Rootconf 2009 Openvz
Liudmila Li
 
Doctype htmlcodigioooooo
ANDERSON FABIAN
 
spring_jiaocheng
Shilong Sang
 
Ruby on Rails Tutorial Part I
Wei Jen Lu
 
Reloaded
Shunsaku Kudo
 
ブラウザでMap Reduce風味の並列分散処理
Shinya Miyazaki
 
【13-C-4】 「もう業務はとまらない!オフライン機能を使った業務アプリケーションの実例と最新 Curl 情報」
devsumi2009
 
Intro To RDBMS And SQL Server 2005 - Svetlin Nakov
Svetlin Nakov
 
20090410 Gree Opentech Main
Hideki Yamane
 
20090418 イケテルRails勉強会 第2部Air編
mochiko AsTech
 
Install Moodle
gueste8192c
 
数学物理漫谈
Xu jiakon
 
Ad

Viewers also liked (8)

PPT
How to debug a perl script using gdb
akirahiguchi
 
PDF
Shibuya.pm #9 My First XS
Masaaki HIROSE
 
PDF
Redunduncy of NAT instance on AWS/VPC
Masaaki HIROSE
 
PDF
How to inspect a RUNNING perl process
Masaaki HIROSE
 
PDF
Introduction of aws-cli
Masaaki HIROSE
 
PDF
JVM! JVM! JVM!
Masaaki HIROSE
 
PPTX
Steelcon 2014 - Process Injection with Python
infodox
 
How to debug a perl script using gdb
akirahiguchi
 
Shibuya.pm #9 My First XS
Masaaki HIROSE
 
Redunduncy of NAT instance on AWS/VPC
Masaaki HIROSE
 
How to inspect a RUNNING perl process
Masaaki HIROSE
 
Introduction of aws-cli
Masaaki HIROSE
 
JVM! JVM! JVM!
Masaaki HIROSE
 
Steelcon 2014 - Process Injection with Python
infodox
 
Ad

Similar to 『Ficia』インフラとPerlにまつわるエトセトラ (20)

PDF
CPAN 模組二三事
Lin Yo-An
 
PDF
Building apache modules
Marian Marinov
 
PDF
Apache2 BootCamp : Getting Started With Apache
Wildan Maulana
 
PDF
Linux 系統管理與安全:基本 Linux 系統知識
維泰 蔡
 
PPTX
Linux And perl
Sagar Kumar
 
KEY
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Masahiro Nagano
 
PDF
Download ebooks file Practical mod_perl 1st Edition Stas Bekman all chapters
cevadkulah
 
PDF
Download full ebook of Practical mod_perl First Edition Bekman instant downlo...
bjwkozngps344
 
PDF
Practical mod_perl 1st Edition Stas Bekman
khuphejavadi
 
PDF
Cli the other SAPI confoo11
Combell NV
 
KEY
Using Apache as an Application Server
Phil Windley
 
PDF
CLI, the other SAPI phpnw11
Combell NV
 
PDF
Practical Modperl First Edition Bekman Stas Cholet Eric
toyahwaierys
 
PDF
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
PDF
CLI, the other SAPI
Combell NV
 
PPT
Power point on linux commands,appache,php,mysql,html,css,web 2.0
venkatakrishnan k
 
PPT
Linux presentation
Ajaigururaj R
 
PDF
httpd — Apache Web Server
webhostingguy
 
PDF
Cli the other sapi pbc11
Combell NV
 
PDF
Building Reusable Puppet Modules
Puppet
 
CPAN 模組二三事
Lin Yo-An
 
Building apache modules
Marian Marinov
 
Apache2 BootCamp : Getting Started With Apache
Wildan Maulana
 
Linux 系統管理與安全:基本 Linux 系統知識
維泰 蔡
 
Linux And perl
Sagar Kumar
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Masahiro Nagano
 
Download ebooks file Practical mod_perl 1st Edition Stas Bekman all chapters
cevadkulah
 
Download full ebook of Practical mod_perl First Edition Bekman instant downlo...
bjwkozngps344
 
Practical mod_perl 1st Edition Stas Bekman
khuphejavadi
 
Cli the other SAPI confoo11
Combell NV
 
Using Apache as an Application Server
Phil Windley
 
CLI, the other SAPI phpnw11
Combell NV
 
Practical Modperl First Edition Bekman Stas Cholet Eric
toyahwaierys
 
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
CLI, the other SAPI
Combell NV
 
Power point on linux commands,appache,php,mysql,html,css,web 2.0
venkatakrishnan k
 
Linux presentation
Ajaigururaj R
 
httpd — Apache Web Server
webhostingguy
 
Cli the other sapi pbc11
Combell NV
 
Building Reusable Puppet Modules
Puppet
 

Recently uploaded (20)

PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
Doc9.....................................
SofiaCollazos
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
The Future of Artificial Intelligence (AI)
Mukul
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 

『Ficia』インフラとPerlにまつわるエトセトラ