Enviar búsqueda
Cargar
Concurrency & Ruby
•
4 recomendaciones
•
1,618 vistas
R
rockyjaiswal
Seguir
Slides for my talk at RubyConf India 2013
Leer menos
Leer más
Tecnología
Denunciar
Compartir
Denunciar
Compartir
1 de 31
Descargar ahora
Descargar para leer sin conexión
Recomendados
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
Recomendados
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
Más contenido relacionado
La actualidad más candente
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
La actualidad más candente
(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
Destacado
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
Destacado
(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
Similar a 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
Similar a 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
Último
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
apidays
🐬 The future of MySQL is Postgres 🐘
🐬 The future of MySQL is Postgres 🐘
RTylerCroy
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Anna Loughnan Colquhoun
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
Khushali Kathiriya
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
lior mazor
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Remote DBA Services
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
MIND CTI
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Juan lago vázquez
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
The Digital Insurer
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Igalia
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
DianaGray10
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Khem
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
wesley chun
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
apidays
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Neo4j
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Roshan Dwivedi
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
apidays
Último
(20)
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
🐬 The future of MySQL is Postgres 🐘
🐬 The future of MySQL is Postgres 🐘
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
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.
Descargar ahora