Suche senden
Hochladen
Concurrency & Ruby
•
4 gefällt mir
•
1,618 views
R
rockyjaiswal
Folgen
Slides for my talk at RubyConf India 2013
Weniger lesen
Mehr lesen
Technologie
Melden
Teilen
Melden
Teilen
1 von 31
Jetzt herunterladen
Downloaden Sie, um offline zu lesen
Empfohlen
Ruby On Google App Engine 2nd Athens Ruby Me
Ruby On Google App Engine 2nd Athens Ruby Me
Panagiotis Papadopoulos
Introduction to Ruby on Rails
Introduction to Ruby on Rails
mithunsasidharan
Ruby an overall approach
Ruby an overall approach
Felipe Schmitt
Ruby On Rails Ecosystem
Ruby On Rails Ecosystem
Andrew Chalkley
ConfigMgmtCamp 2015: Puppet Master to Puppet Server
ConfigMgmtCamp 2015: Puppet Master to Puppet Server
Puppet
An introduction to the ruby ecosystem
An introduction to the ruby ecosystem
Geison Goes
Initiation à Ruby on Rails
Initiation à Ruby on Rails
Microsoft Technet France
Speeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using Starling
Erik Osterman
Empfohlen
Ruby On Google App Engine 2nd Athens Ruby Me
Ruby On Google App Engine 2nd Athens Ruby Me
Panagiotis Papadopoulos
Introduction to Ruby on Rails
Introduction to Ruby on Rails
mithunsasidharan
Ruby an overall approach
Ruby an overall approach
Felipe Schmitt
Ruby On Rails Ecosystem
Ruby On Rails Ecosystem
Andrew Chalkley
ConfigMgmtCamp 2015: Puppet Master to Puppet Server
ConfigMgmtCamp 2015: Puppet Master to Puppet Server
Puppet
An introduction to the ruby ecosystem
An introduction to the ruby ecosystem
Geison Goes
Initiation à Ruby on Rails
Initiation à Ruby on Rails
Microsoft Technet France
Speeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using Starling
Erik Osterman
Rubyhosting
Rubyhosting
Artit Rubybox
JRuby - Everything in a single process
JRuby - Everything in a single process
ocher
AWS Lambdas are cool - Cheminfo Stories Day 1
AWS Lambdas are cool - Cheminfo Stories Day 1
ChemAxon
Introduction To Rails
Introduction To Rails
Eric Gruber
My S Q L Replication Getting The Most From Slaves
My S Q L Replication Getting The Most From Slaves
PerconaPerformance
kranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High load
Krivoy Rog IT Community
Ruby on Rails : First Mile
Ruby on Rails : First Mile
Gourab Mitra
Scaling a Web Service
Scaling a Web Service
Leon Ho
What lies beneath the beautiful code?
What lies beneath the beautiful code?
Niranjan Sarade
Testing smells
Testing smells
Sidu Ponnappa
Lightning Talk - Contribute to Open Source
Lightning Talk - Contribute to Open Source
Sidu Ponnappa
Everything ruby
Everything ruby
ajeygore
Ruby Internals
Ruby Internals
Burke Libbey
Aspen ideas Festival Talk on Gov20
Aspen ideas Festival Talk on Gov20
Tim O'Reilly
clearScienceStrataRx2012
clearScienceStrataRx2012
OReillyStrata
Awakening India - Jago Party
Awakening India - Jago Party
Kapil Mohan
Open Data: From the Information Age to the Action Age (Keynote File)
Open Data: From the Information Age to the Action Age (Keynote File)
Tim O'Reilly
Creating actionable marketo reports july, 2013
Creating actionable marketo reports july, 2013
Inga Romanoff
Larry's Free Culture
Larry's Free Culture
Kapil Mohan
Parzania Movie Preview
Parzania Movie Preview
Kapil Mohan
What we can take for granted in online communities
What we can take for granted in online communities
Chris Messina
BodyTrack: Open Source Tools for Health Empowerment through Self-Tracking
BodyTrack: Open Source Tools for Health Empowerment through Self-Tracking
OSCON Byrum
Weitere ähnliche Inhalte
Was ist angesagt?
Rubyhosting
Rubyhosting
Artit Rubybox
JRuby - Everything in a single process
JRuby - Everything in a single process
ocher
AWS Lambdas are cool - Cheminfo Stories Day 1
AWS Lambdas are cool - Cheminfo Stories Day 1
ChemAxon
Introduction To Rails
Introduction To Rails
Eric Gruber
My S Q L Replication Getting The Most From Slaves
My S Q L Replication Getting The Most From Slaves
PerconaPerformance
kranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High load
Krivoy Rog IT Community
Ruby on Rails : First Mile
Ruby on Rails : First Mile
Gourab Mitra
Scaling a Web Service
Scaling a Web Service
Leon Ho
Was ist angesagt?
(8)
Rubyhosting
Rubyhosting
JRuby - Everything in a single process
JRuby - Everything in a single process
AWS Lambdas are cool - Cheminfo Stories Day 1
AWS Lambdas are cool - Cheminfo Stories Day 1
Introduction To Rails
Introduction To Rails
My S Q L Replication Getting The Most From Slaves
My S Q L Replication Getting The Most From Slaves
kranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High load
Ruby on Rails : First Mile
Ruby on Rails : First Mile
Scaling a Web Service
Scaling a Web Service
Andere mochten auch
What lies beneath the beautiful code?
What lies beneath the beautiful code?
Niranjan Sarade
Testing smells
Testing smells
Sidu Ponnappa
Lightning Talk - Contribute to Open Source
Lightning Talk - Contribute to Open Source
Sidu Ponnappa
Everything ruby
Everything ruby
ajeygore
Ruby Internals
Ruby Internals
Burke Libbey
Aspen ideas Festival Talk on Gov20
Aspen ideas Festival Talk on Gov20
Tim O'Reilly
clearScienceStrataRx2012
clearScienceStrataRx2012
OReillyStrata
Awakening India - Jago Party
Awakening India - Jago Party
Kapil Mohan
Open Data: From the Information Age to the Action Age (Keynote File)
Open Data: From the Information Age to the Action Age (Keynote File)
Tim O'Reilly
Creating actionable marketo reports july, 2013
Creating actionable marketo reports july, 2013
Inga Romanoff
Larry's Free Culture
Larry's Free Culture
Kapil Mohan
Parzania Movie Preview
Parzania Movie Preview
Kapil Mohan
What we can take for granted in online communities
What we can take for granted in online communities
Chris Messina
BodyTrack: Open Source Tools for Health Empowerment through Self-Tracking
BodyTrack: Open Source Tools for Health Empowerment through Self-Tracking
OSCON Byrum
A New Business World Within A Blockchain
A New Business World Within A Blockchain
Alex Chepurnoy
Pinterest for Business 101
Pinterest for Business 101
Nick Armstrong
Visual Conversations on Urban Futures - DRS 2016
Visual Conversations on Urban Futures - DRS 2016
serena pollastri
A GeoSocial Intelligence Framework for Studying & Promoting Resilience to Sea...
A GeoSocial Intelligence Framework for Studying & Promoting Resilience to Sea...
SMART Infrastructure Facility
Cio Exchange08
Cio Exchange08
Tim O'Reilly
Government 2.0
Government 2.0
Tim O'Reilly
Andere mochten auch
(20)
What lies beneath the beautiful code?
What lies beneath the beautiful code?
Testing smells
Testing smells
Lightning Talk - Contribute to Open Source
Lightning Talk - Contribute to Open Source
Everything ruby
Everything ruby
Ruby Internals
Ruby Internals
Aspen ideas Festival Talk on Gov20
Aspen ideas Festival Talk on Gov20
clearScienceStrataRx2012
clearScienceStrataRx2012
Awakening India - Jago Party
Awakening India - Jago Party
Open Data: From the Information Age to the Action Age (Keynote File)
Open Data: From the Information Age to the Action Age (Keynote File)
Creating actionable marketo reports july, 2013
Creating actionable marketo reports july, 2013
Larry's Free Culture
Larry's Free Culture
Parzania Movie Preview
Parzania Movie Preview
What we can take for granted in online communities
What we can take for granted in online communities
BodyTrack: Open Source Tools for Health Empowerment through Self-Tracking
BodyTrack: Open Source Tools for Health Empowerment through Self-Tracking
A New Business World Within A Blockchain
A New Business World Within A Blockchain
Pinterest for Business 101
Pinterest for Business 101
Visual Conversations on Urban Futures - DRS 2016
Visual Conversations on Urban Futures - DRS 2016
A GeoSocial Intelligence Framework for Studying & Promoting Resilience to Sea...
A GeoSocial Intelligence Framework for Studying & Promoting Resilience to Sea...
Cio Exchange08
Cio Exchange08
Government 2.0
Government 2.0
Ähnlich wie Concurrency & Ruby
JRuby and Google App Engine
JRuby and Google App Engine
joshsmoore
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
Barry Jones
Concurrency in ruby
Concurrency in ruby
Marco Borromeo
Parallel js
Parallel js
Shams Nahid
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
luccastera
Message Queues in Ruby - An Overview
Message Queues in Ruby - An Overview
Pradeep Elankumaran
re7olabini
re7olabini
guest6850dd
Day 8 - jRuby
Day 8 - jRuby
Barry Jones
NodeJS or Apache: Unveiling the Differences in Performance, Use Cases, and Se...
NodeJS or Apache: Unveiling the Differences in Performance, Use Cases, and Se...
Tien Nguyen
What's the "right" PHP Framework?
What's the "right" PHP Framework?
Barry Jones
Feels Like Ruby - Ruby Kaigi 2010
Feels Like Ruby - Ruby Kaigi 2010
Sarah Mei
Ruby/Rails Performance Tips
Ruby/Rails Performance Tips
PatrickMcSweeny
Node.JS Expreee.JS scale webapp on Google cloud
Node.JS Expreee.JS scale webapp on Google cloud
Jimish Parekh
performance_tuning.pdf
performance_tuning.pdf
Alexadiaz52
performance_tuning.pdf
performance_tuning.pdf
Alexadiaz52
Gluecon 2014 - Bringing Node.js to the JVM
Gluecon 2014 - Bringing Node.js to the JVM
Jeremy Whitlock
Concurrency in java
Concurrency in java
Saquib Sajid
Languages used by web app development services remotestac x
Languages used by web app development services remotestac x
Remote Stacx
DiUS Computing Lca Rails Final
DiUS Computing Lca Rails Final
Robert Postill
Rails Concept
Rails Concept
Javed Hussain
Ähnlich wie Concurrency & Ruby
(20)
JRuby and Google App Engine
JRuby and Google App Engine
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
Concurrency in ruby
Concurrency in ruby
Parallel js
Parallel js
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
Message Queues in Ruby - An Overview
Message Queues in Ruby - An Overview
re7olabini
re7olabini
Day 8 - jRuby
Day 8 - jRuby
NodeJS or Apache: Unveiling the Differences in Performance, Use Cases, and Se...
NodeJS or Apache: Unveiling the Differences in Performance, Use Cases, and Se...
What's the "right" PHP Framework?
What's the "right" PHP Framework?
Feels Like Ruby - Ruby Kaigi 2010
Feels Like Ruby - Ruby Kaigi 2010
Ruby/Rails Performance Tips
Ruby/Rails Performance Tips
Node.JS Expreee.JS scale webapp on Google cloud
Node.JS Expreee.JS scale webapp on Google cloud
performance_tuning.pdf
performance_tuning.pdf
performance_tuning.pdf
performance_tuning.pdf
Gluecon 2014 - Bringing Node.js to the JVM
Gluecon 2014 - Bringing Node.js to the JVM
Concurrency in java
Concurrency in java
Languages used by web app development services remotestac x
Languages used by web app development services remotestac x
DiUS Computing Lca Rails Final
DiUS Computing Lca Rails Final
Rails Concept
Rails Concept
Kürzlich hochgeladen
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Scott Keck-Warren
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
Enterprise Knowledge
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Miguel Araújo
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
Pixlogix Infotech
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
Sujit Pal
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
Delhi Call girls
Slack Application Development 101 Slides
Slack Application Development 101 Slides
praypatel2
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
Delhi Call girls
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
ThousandEyes
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
BookNet Canada
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Delhi Call girls
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
Pooja Nehwal
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Safe Software
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
Puma Security, LLC
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
Results
🐬 The future of MySQL is Postgres 🐘
🐬 The future of MySQL is Postgres 🐘
RTylerCroy
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
Paola De la Torre
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Delhi Call girls
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
shyamraj55
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Sinan KOZAK
Kürzlich hochgeladen
(20)
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
Slack Application Development 101 Slides
Slack Application Development 101 Slides
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
🐬 The future of MySQL is Postgres 🐘
🐬 The future of MySQL is Postgres 🐘
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Concurrency & Ruby
1.
CONCURRENCY & RUBY Rocky Jaiswal RubyConf India 2013
2.
WHY CONCURRENCY?
3.
ABOUT ME Learning programming for the last 11 years Did Java for around 8 years Started learning Ruby ~3 years back ♥ Ruby ♥ the Ruby community Also learning some CoffeeScript and Scala http://rockyj.in @whatsuprocky
4.
CONCURRENCY? Concurrency is when two tasks can start, run, and complete in overlapping time periods Concurrency can be implemented even in single processing units to speed things up Concurrency is non-deterministic Whereas a parallel program is one that merely runs on multiple processors, with the goal of hopefully running faster than it would on a single CPU
5.
THREADS VS PROCESSESS Threads are light weight processes that run in the same memory context Ruby has Green Threads which are managed by the Ruby process JRuby has real OS thread that run parallel to the parent thread
6.
THREADS IN RUBY
7.
SAMPLE UNICORN SETUP 15 Unicorns = 15 Processes 1 Unicorn Process ~= 150 MB 15 Processes ~= 2 GB RAM* Scaling this means more processes = more memory = more money Also, If you are CPU bound you want to use no more unicorn processes than you have cores, otherwise you overload the system and slow down the scheduler.
8.
CONCURRENCY IS GOOD JRuby + Puma / Torquebox High-Scalability with less memory Resque / Sidekiq More workers and faster processing with less memory
9.
SO IS IT ALL DOOM AND GLOOM? No! Most Rails applications are IO bound With MRI you are always thread safe MRI is getting faster and GC is getting better Processes management is optimized Passenger is using a hybrid - evented + threaded / process architecture
10.
THREAD-SAFETY LET ME GIVE YOU A DEMO Appending to Arrays: MRI Version vs JRuby Version DEMO
11.
RUN CODE ON MRI & JRUBY array = [] 5.times.map do Thread.new do #Init 5 threads 1000.times do array << nil #In each thread add 1000 elements to the Ar end end end.each(&:join) puts array.size
12.
EVEN APPENDING TO ARRAYS IS NOT THREAD SAFE!
13.
WHAT ABOUT RAILS config.threadsafe! def threadsafe! @preload_frameworks = true @cache_classes = true @dependency_loading = false @allow_concurrency = true self end
14.
JRUBY ON RAILS DEMO
15.
BAD COUNTER CODE class PagesController < ApplicationController @counter = 0 class << self attr_accessor :counter end #Classic read-modify-write problem def index counter = self.class.counter # read sleep(0.1) counter += 1 #update sleep(0.1) self.class.counter = counter # write users = User.all puts "-----------" + self.class.counter.to_s + "------------" end end
16.
UGLY SYNCHRONIZED CODE class PagesController < ApplicationController @counter = 0 @semaphore = Mutex.new class << self attr_accessor :counter attr_accessor :semaphore end def index #counter = self.class.counter # read sleep(0.1) self.class.semaphore.synchronize { self.class.counter += 1 #update } sleep(0.1) #self.class.counter = counter # write users = User.all puts "-----------" + self.class.counter.to_s + "------------" end end
17.
RAILS 4 IS CONCURRENCY ENABLED BY DEFAULT
18.
CONCURRENCY INTRODUCES Race Conditions Deadlocks Starvation etc. BUT GIVES YOU Speed Less Memory Usage
19.
SAFE CONCURRENCY Don't do it. If you must do it, don't share data across threads. If you must share data across threads, don't share mutable data. If you must share mutable data across threads, synchronize access to that data.
20.
THREAD SAFETY IN JRUBY LOCKS ATOMICITY IMMUTABILITY
21.
ATOMIC COUNTER java_import 'java.util.concurrent.atomic.AtomicInteger' class PagesController < ApplicationController @counter = AtomicInteger.new(1) class << self attr_accessor :counter end def index sleep(0.1) counter = self.class.counter.getAndIncrement() #update sleep(0.1) users = User.all puts "-----------------" + counter.to_s + "-----------------" end end
22.
ALL THIS SUCKS! 95% of syncronized code is broken. The other 5% is written by Brian Goetz. - Venkat Subramaniam
23.
ENTER ACTOR
24.
THE ACTOR MODEL Introduced by Carl Hewitt in 1973 Contributions by a lot of scholars and universities Popularized by Erlang, now in Scala Simple and high-level abstractions for concurrency and parallelism Objects are Actors each with their own state which is never shared Communication happens through messages Very lightweight event-driven processes (approximately 2.7 million actors per GB RAM [Akka])
25.
THE ACTOR MODEL -2 Easier to deal with humans than with threads Like humans, Actors communicate via messages No state sharing, communicate via immutable messages
26.
IMPLEMENTATIONS
27.
PRODUCER CONSUMER PROBLEM Demo with JRuby + Locks Demo with JRuby + Celluloid
28.
PRODUCER CONSUMER with locks HTTPS://GIST.GITHUB.COM/ROCKY- JAISWAL/5847810
29.
PRODUCER CONSUMER with actors HTTPS://GIST.GITHUB.COM/ROCKY- JAISWAL/5847814
30.
SUMMARY Concurrency is the need of the hour MRI is thread safe by default due to GIL / GVL JRuby gives you real concurrency (RBX as well) With power comes responsibility Don't worry, concurrency can be easy if you follow the ground rules If you want to write concurrent code yourself, use Actors * I did not cover STM (provided by Clojure)
31.
THANK YOU! QUESTIONS #A lot of this content has been taken from blogs, wikis and books. I do not claim it is my own and I wholeheartedly thank everyone who helped me with this presentation.
Jetzt herunterladen