Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Working with UNIX Process 6/7 Chapter
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yuta Totz
March 05, 2016
Programming
84
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Working with UNIX Process 6/7 Chapter
Yuta Totz
March 05, 2016
More Decks by Yuta Totz
See All by Yuta Totz
ウガンダでXcodeをアップデートする方法
totzyuta
0
150
珈琲と僕
totzyuta
0
120
読んで理解するActiveRecordの設計とActiveSupport::Concern
totzyuta
4
1.7k
TDDとVimと
totzyuta
1
560
モテる!筋肉コンパイラ自作入門 - 草食男子からの卒業
totzyuta
0
470
Git/GitHub入門-GitHubでたのしいチーム開発
totzyuta
0
330
Vimmer幼稚園
totzyuta
2
130
たのしいたーみなる
totzyuta
0
62
Other Decks in Programming
See All in Programming
Domain-Driven Transformation
hschwentner
2
2.3k
Heart of Swift Concurrency
koher
0
1.2k
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
370
Androidだけじゃない、DroidKaigiで広がった私の技術スタック
akkeylab
0
120
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
350
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
390
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
34
15k
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
130
Are APIs Still Relevant in the AI Era?
soyuka
0
430
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
470
AWSに止められる覚悟してますか?
morizo_1984
2
520
Rでドレミ/Do-Re-Mi_with_R
florets1
0
120
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
How to train your dragon (web standard)
notwaldorf
96
6.9k
Evolving SEO for Evolving Search Engines
ryanjones
0
310
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
So, you think you're a good person
axbom
PRO
2
2.2k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
300
For a Future-Friendly Web
brad_frost
183
10k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
58k
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)
ࠓֶͿ͜ͱ • ϓϩηεʹϦιʔεͷ੍ݶ͕͋Δ • ੍ݶͷݟ͚ͭํ • ιϑτϦϛοτͷҾ্͖͛ɺ੍ݶ • ϓϩηεʹڥ͕͋Δ •
ڥมͷࢀরͷํ