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
110
珈琲と僕
totzyuta
0
89
読んで理解するActiveRecordの設計とActiveSupport::Concern
totzyuta
4
1.5k
TDDとVimと
totzyuta
1
480
モテる!筋肉コンパイラ自作入門 - 草食男子からの卒業
totzyuta
0
420
Git/GitHub入門-GitHubでたのしいチーム開発
totzyuta
0
290
Vimmer幼稚園
totzyuta
2
110
たのしいたーみなる
totzyuta
0
40
Other Decks in Programming
See All in Programming
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
Haze - Real time background blurring
chrisbanes
1
510
103 Early Hints
sugi_0000
1
230
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
100
良いユニットテストを書こう
mototakatsu
7
2.2k
Jakarta EE meets AI
ivargrimstad
0
240
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
260
From Translations to Multi Dimension Entities
alexanderschranz
2
130
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
2
240
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Facilitating Awesome Meetings
lara
50
6.1k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Music & Morning Musume
bryan
46
6.2k
Designing for Performance
lara
604
68k
The Pragmatic Product Professional
lauravandoore
32
6.3k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Become a Pro
speakerdeck
PRO
26
5k
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)
ࠓֶͿ͜ͱ • ϓϩηεʹϦιʔεͷ੍ݶ͕͋Δ • ੍ݶͷݟ͚ͭํ • ιϑτϦϛοτͷҾ্͖͛ɺ੍ݶ • ϓϩηεʹڥ͕͋Δ •
ڥมͷࢀরͷํ