Soumettre la recherche
Mettre en ligne
Concurrency & Ruby
•
4 j'aime
•
1,618 vues
R
rockyjaiswal
Suivre
Slides for my talk at RubyConf India 2013
Lire moins
Lire la suite
Technologie
Signaler
Partager
Signaler
Partager
1 sur 31
Télécharger maintenant
Télécharger pour lire hors ligne
Recommandé
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
Recommandé
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
Contenu connexe
Tendances
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
Tendances
(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
En vedette
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
En vedette
(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
Similaire à 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
Similaire à 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
Dernier
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
Ridwan Fadjar
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
Stephanie Beckett
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
ScyllaDB
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
UiPathCommunity
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
Fwdays
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
Fwdays
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
Rizwan Syed
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
Hervé Boutemy
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
Kalema Edgar
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
Fwdays
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
RankYa
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Safe Software
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
Mattias Andersson
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
Florian Wilhelm
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
Lorenzo Miniero
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
BookNet Canada
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
Enterprise Knowledge
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
Commit University
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
Addepto
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
Slibray Presentation
Dernier
(20)
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
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.
Télécharger maintenant