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
Working with UNIX Process 6/7 Chapter
Search
Yuta Totz
March 05, 2016
Programming
1
60
Working with UNIX Process 6/7 Chapter
Yuta Totz
March 05, 2016
Tweet
Share
More Decks by Yuta Totz
See All by Yuta Totz
ウガンダでXcodeをアップデートする方法
totzyuta
0
100
珈琲と僕
totzyuta
0
83
読んで理解するActiveRecordの設計とActiveSupport::Concern
totzyuta
4
1.5k
TDDとVimと
totzyuta
1
470
モテる!筋肉コンパイラ自作入門 - 草食男子からの卒業
totzyuta
0
420
Git/GitHub入門-GitHubでたのしいチーム開発
totzyuta
0
290
Vimmer幼稚園
totzyuta
2
110
たのしいたーみなる
totzyuta
0
40
Other Decks in Programming
See All in Programming
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
3
400
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
macOS でできる リアルタイム動画像処理
biacco42
6
1.7k
Outline View in SwiftUI
1024jp
1
110
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
1
290
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
160
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
7
2.8k
Go言語でターミナルフレンドリーなAIコマンド、afaを作った/fukuokago20_afa
monochromegane
2
140
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
5
3.3k
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2.1k
WEBエンジニア向けAI活用入門
sutetotanuki
0
300
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Typedesign – Prime Four
hannesfritz
39
2.4k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Automating Front-end Workflow
addyosmani
1365
200k
Writing Fast Ruby
sferik
626
61k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Visualization
eitanlees
144
15k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Why Our Code Smells
bkeepers
PRO
334
57k
Transcript
Working with UNIX Process 6. Resource Limit / 7. Environment
of Processes
ࠓֶͿ͜ͱ • ϓϩηεʹϦιʔεͷ੍ݶ͕͋Δ • ੍ݶͷݟ͚ͭํ • ιϑτϦϛοτͷҾ্͖͛ɺ੍ݶ • ϓϩηεʹڥ͕͋Δ •
ڥมͷࢀরͷํ
6ষ ϓϩηεͷϦιʔε੍ݶ
ϓϩηεʹϦιʔεͷ੍ݶ͕ ͋Δ • Ϧιʔε͕ด͡ΒΕͳ͍ͱϑΝΠϧσΟεΫϦϓλ ͷ൪߸͕૿Ճ͠ଓ͚Δ • 1ϓϩηε͋ͨΓͲΕ͘Β͍ͷϑΝΠϧσΟεΫϦ ϓλΛ࣋ͯΔͷ͔ʁ • =>
ΧʔωϧʹΑͬͯ1ϓϩηε͝ͱʹϦιʔεͷ੍ ݶ͕ઃఆ͞Ε͍ͯΔʂ
੍ݶΛݟ͚ͭΔ • :NOFILEγϯϘϧΛҾʹ͢Δ (Φϓγϣϯతͳ) • [ϑΝΠϧσΟεΫϦϓλͷιϑτϦϛοτ, ~ͷϋʔυϦϛοτ] • http://rurema.clear-code.com/1.9.3/method/Process/m/ getrlimit.html
p Process.getrlimit(:NOFILE) => [256, 9223372036854775807]
ιϑτϦϛοτͱϋʔυϦϛο τ • ιϑτϦϛοτιϑτଆͰنఆ্ͨ͠ݶ • มߋͰ͖Δ • ࣮ମϋʔυϦϛοτͰɺͬͪ͜ͱΜͰͳ͘େ͖ͳ •
sysctl(8) • http://www.usupi.org/sysad/240.html
ιϑτϦϛοτΛҾ্͖͛Δ • ୈ̏ҾͰ৽͍͠ϋʔυϦϛοτࢦఆͰ͖ Δ Process.setrlimit(:NOFILE, 4096) p Process.getrlimit(:NOFILE) => [4096,
4096]
ιϑτϦϛοτΛҾ্͖͛Δ • ιϑτϦϛοτΛϋʔυϦϛοτͷ·ͰҾ ্͖͛Δ ɹProcess.setrlimit(:NOFILE, Process.getrlimit(:NOFILE)[1])
੍ݶΛ͑ͨͱ͖ • ιϑτϦϛοτΛ͑ͨ߹ʹErrno::EMFILEྫ֎Λൃੜ͢Δ # ΦʔϓϯͰ͖ΔϑΝΠϧͷ࠷େΛ3ʹઃఆ # ඪ४ετϦʔϜͰϑΝΠϧσΟεΫϦϓλΛ3ͭ͏ͨΊ # ͢Ͱʹ্ݶʹୡ͍ͯ͠Δঢ়ଶʹͳΔ Process.setrlimit(:NOFILE,
3) File.open(‘/dev/null’) Errno::EMFILE: Too many open files - /dev/null
ͦͷଞͷγεςϜϦιʔεͷ੍ݶͷ֬ೝɾมߋ • Process.getrlimitʹͤΔΦϓγϣϯͷϦετυΩϡϝϯτࢀরɹ • http://ruby-doc.org/core-1.9.3/Process.html#method-c-setrlimit # ϓϩηεͷϢʔβ͕࡞Ͱ͖Δ࠷େϓϩηε Process.getrlimit(:NPROC) # ϓϩηε͕࡞Ͱ͖ΔϑΝΠϧαΠζͷ࠷େ
Process.getrlimit(:FSIZE) # ϓϩηεελοΫͷ࠷େαΠζ Process.getrlimit(:STACK)
࣮༻ྫ • γεςϜϦιʔεͷ੍ݶͷมߋ͕ඞཁʹͳΔϓϩάϥϜ͋Μ·ͳ͍…ɻ͚Ͳಛ ผͳ༻్ͷπʔϧͰͱͯॏཁʹͳΔ • ex. ϓϩηε͕ಉ࣌ʹઍͷωοτϫʔΫίωΫγϣϯΛѻ͏ඞཁ͕͋Δ • httpύϑΥʔϚϯεπʔϧͷhttperf(1) •
httperf —hog —server www —num-conn 5000 • => ಉ࣌ʹ5000ͷίωΫγϣϯΛ࡞͠Α͏ͱ͢Δ • ιϑτϦϛοτ͕σϑΥϧτͩͱ໌Β͔ʹ·͍ͣͷͰɺhttperf(1)࣮ߦલʹࣗ ͷιϑτϦϛοτΛҾ্͖͛Δ
࣮༻ྫ (2) • ੍ݶ͢Δྫ • ୈࡾऀͷίʔυͷ࣮ߦ࣌ʹ੍Λ͚ͭΔ • ϓϩηεࣗʹڐ͞Ε͍ͯΔҎ্ͷϦιʔε ͑ͳ͘ͳΔ
6ষͷγεςϜίʔϧ • getrlimit(2) • Process.getrlimit • setr-limit(2) • Process.setrlimit
7ষ ϓϩηεͷڥ
ϓϩηεʹڥ͕͋Δ • ʮڥʯʹʮڥมʯ • keyͱvalueͷΈ߹Θͤ => ϓϩηεͰ͑ΔσʔλΛ อ࣋͢Δͷ • શͯͷࢠϓϩηεϓϩηε͔ΒڥมΛҾ͖ܧ͙
• ڥมϓϩηε͝ͱʹଘࡏ͠ɺͦΕͧΕͷϓϩηε ͰάϩʔόϧʹΞΫηεͰ͖Δ
example $ MESSAGE=‘wing it’ ruby -e “puts ENV[‘MESSAGE’]” ENV[‘MESSAGE’] =
‘wing it’ system “echo $MESSAGE”
͜Εͬͯϋογϡʁ • ϋογϡΦϒδΣΫτͰͳ͍ (merge͕ͳ͍ͱ ͔) => ϋογϡϥΠΫʹΞΫηεͰ͖ΔAPI͕༻ ҙ͞Ε͍ͯΔ Process.setrlimit(:NOFILE, 4096)
p Process.getrlimit(:NOFILE) => [4096, 4096] puts ENV[‘EDITOR’] => vim puts ENV.has_key?(‘PATH’) => true puts ENV.is_a?(Hash) => false
࣮༻ྫ • ίϚϯυϥΠϯπʔϧʹೖྗΛ͢ํ๏ͱͯ͠Α͘࠾༻͞ΕΔ • ͜ͷํ͕ίϚϯυϥΠϯ͔Β༩͑ΒΕͨΦϓγϣϯΛղੳ͢ ΔΑΓϥΫͱ͍͏ϝϦοτ͋Δ Process.setrlimit(:NOFILE, 4096) p Process.getrlimit(:NOFILE)
=> [4096, 4096] ENV.is $ RAILS_ENV=production rails server $ EDITOR=mate bundle open actionpack $ QUEUE=default rake resque:work
7ষͷγεςϜίʔϧ • setenv(3), getenv(3) • ڥมΛѻ͏Cݴޠͷؔ • environ(7)
ࠓֶͿ͜ͱ • ϓϩηεʹϦιʔεͷ੍ݶ͕͋Δ • ੍ݶͷݟ͚ͭํ • ιϑτϦϛοτͷҾ্͖͛ɺ੍ݶ • ϓϩηεʹڥ͕͋Δ •
ڥมͷࢀরͷํ