Enviar pesquisa
Carregar
Concurrency & Ruby
•
4 gostaram
•
1,618 visualizações
R
rockyjaiswal
Seguir
Slides for my talk at RubyConf India 2013
Leia menos
Leia mais
Tecnologia
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 31
Baixar agora
Baixar para ler offline
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
Mais conteúdo relacionado
Mais procurados
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
Mais procurados
(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
Destaque
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
Destaque
(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
Semelhante 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
Semelhante 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
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
LoriGlavin3
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
Wes McKinney
A Framework for Development in the AI Age
A Framework for Development in the AI Age
Cprime
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
Skynet Technologies
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
Knoldus Inc.
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
DianaGray10
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
Nathaniel Shimoni
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
LoriGlavin3
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
Ingrid Airi González
How to write a Business Continuity Plan
How to write a Business Continuity Plan
Databarracks
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
panagenda
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
Inflectra
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
Alan Dix
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
ThousandEyes
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
IES VE
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
Lonnie McRorey
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
BookNet Canada
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
LoriGlavin3
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
MounikaPolabathina
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Mark Goldstein
Último
(20)
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
A Framework for Development in the AI Age
A Framework for Development in the AI Age
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
How to write a Business Continuity Plan
How to write a Business Continuity Plan
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
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.
Baixar agora