SlideShare a Scribd company logo
Concurrency in Ruby
Aleš Kotnik
source: Wikipedia
Source: Wikipedia
Every two years we will
● halve the size of transistors
● double the number of transistors per chip
● double the clock frequency
Transistors
are still
getting
smaller
source: http://cpudb.stanford.edu/
But clock
frequency is
not raising
any more
source: http://cpudb.stanford.edu/
CPU caches
help
source: http://cpudb.stanford.edu/
The speed of the RAM chips and
of the communication bus are
two other bottlenecks
How to speed up
programs?
● run them on many (logical) cores in parallel
with OS threads
● not an easy task to do
● you have to get the concurrency right first
Rob Pike's talk
from 2013
"If you looked at the
programming languages of
today you probably get this
idea that the world is
object-oriented. But it's not. It's
actually parallel."
http://bit.ly/pike2013
Concurrency is not
Parallelism
concurrency dealing with many things at the
same time
(it's about structure/design)
parallelism doing many things at the same time
But Ruby can't do
parallelism, right?
● MRI (Matz's C ruby)
● Jruby
● Rubinius
Benchmarks require 'benchmark'
n = 30_000_000
Benchmark.bm do |x|
t1 = Thread.new { x.report {for i in 1..n; a = "1"; end } }
t2 = Thread.new { x.report {n.times do ; a = "1"; end } }
t3 = Thread.new { x.report {1.upto(n) do ; a = "1"; end } }
t1.join # wait for thread 1 to finish
t2.join # wait for thread 2 to finish
t3.join # wait for thread 3 to finish
end
ruby
user system total real
6.420000 0.040000 6.460000 ( 6.816842)
6.440000 0.040000 6.480000 ( 6.837540)
6.250000 0.040000 6.290000 ( 6.577156)
jruby
user system total real
8.810000 0.150000 8.960000 ( 3.284740)
9.550000 0.160000 9.710000 ( 3.622296)
10.320000 0.180000 10.500000 ( 4.413089)
GIL
Global Interpreter Lock
Prevents more than one thread of ruby code to
run in parallel.
Protects internal consistency of the ruby's VM
state
It's not documented, not covered by public tests.
Another
interesting
benchmark
Let's download from
multiple URLS
MRI rocks
MRI performs great!
How is that?
I/O is blocking - GIL is
released.
Push to array
from multiple
threads
Push to array from
multiple threads
ruby: 5000
jruby: 4284
rubinius: 3231
array#push method is run by
array#<< is defined as: rb_ary_push
VALUE
rb_ary_push(VALUE ary, VALUE item)
{
long idx = RARRAY_LEN(ary);
VALUE target_ary = ary_ensure_room_for_push(ary, 1);
RARRAY_PTR_USE(ary, ptr, {
RB_OBJ_WRITE(target_ary, &ptr[idx], item);
});
ARY_SET_LEN(ary, idx + 1);
return ary;
}
So my code is thread-safe as long
as it is run on MRI, right?
Let's check
Let's put some threads to work
The sheep might get shorn multiple times in a row
> ruby sheep.rb
shearing...
shearing...
> jruby sheep.rb
shearing...
> xruby sheep.rb
shearing...
shearing...
Strategies to handle concurrency
● thread scheduler could interrupt the thread at any moment
● resources (memory, files, ...) may be shared among multiple threads
● we need atomic operations
The usual suspects
for synchronise resource sharing
● locks (inside process)
● mutex (between processes)
● semaphore (mutex for multiple number of threads)
Cons of
locks/mutex/semaphore
complex (deadlocks,
starvation, livelocks)
leaky (no abstractions)
no composability (Account
transfer)
Example: The transfer between two accounts
Simon Peyton Jones (suggests STM) Not always 1.000.000
Money can disappear in the
thin air (the same substance it
is usually created from).
Alternatives?
● Actor model (Erlang, Scala)
● CSP (Go, Ruby, Clojure, Kotlin)
● Software Transactional Memory (Haskell, Clojure, Ruby)
● Guilds (New Ruby Concurrency model for Ruby 3
proposed by Koichi Sasada)
Source: Wikipedia
Workers
Workers
Don't communicate by sharing.
Share by communicating.
What would you change
in Ruby if you could go
back in time?
"I would remove the thread and add actors or
some other more advanced concurrency
features"
Yukihiro "Matz" Matsumoto
Source: Wikipedia
The Take-away
get familiar with the alternative
concurrency handling strategies,
read Tony Hoare's CSP original paper,
forget everything from this talk and keep
writing the single threaded Ruby code
that mostly does I/O.

More Related Content

What's hot

JRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform FurtherJRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform Further
Charles Nutter
 
coala demo
coala democoala demo
coala demo
Rishav Kumar
 
Seminar on Parallel and Concurrent Programming
Seminar on Parallel and Concurrent ProgrammingSeminar on Parallel and Concurrent Programming
Seminar on Parallel and Concurrent Programming
Stefan Marr
 
The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015
rvagg
 
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
Igalia
 
Bigdata Presentation
Bigdata PresentationBigdata Presentation
Bigdata Presentation
Yonas Gidey
 
Realm
RealmRealm
Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014
Charles Nutter
 
Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder Ruby
Nick Sieger
 
Improving Performance of a WebKit Port MIPS Platform (ELC 2014)
Improving Performance of a WebKit Port MIPS Platform (ELC 2014)Improving Performance of a WebKit Port MIPS Platform (ELC 2014)
Improving Performance of a WebKit Port MIPS Platform (ELC 2014)
Igalia
 
Large scale nlp using python's nltk on azure
Large scale nlp using python's nltk on azureLarge scale nlp using python's nltk on azure
Large scale nlp using python's nltk on azure
cloudbeatsch
 
Engineering fast indexes (Deepdive)
Engineering fast indexes (Deepdive)Engineering fast indexes (Deepdive)
Engineering fast indexes (Deepdive)
Daniel Lemire
 
WTF is Twisted?
WTF is Twisted?WTF is Twisted?
WTF is Twisted?
hawkowl
 
Microsoft HPC - Kivanc Ozuolmez - Public Content
Microsoft HPC - Kivanc Ozuolmez - Public ContentMicrosoft HPC - Kivanc Ozuolmez - Public Content
Microsoft HPC - Kivanc Ozuolmez - Public Content
Kivanc Ozuolmez
 
Cryptocurrency && Ruby
Cryptocurrency && RubyCryptocurrency && Ruby
Cryptocurrency && Ruby
Dilum Navanjana
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
Nick Sieger
 
The impact of supercomputers on MSR
The impact of supercomputers on MSRThe impact of supercomputers on MSR
The impact of supercomputers on MSR
Yasutaka Kamei
 
Writing NetBSD Sound Drivers in Haskell
Writing NetBSD Sound Drivers in HaskellWriting NetBSD Sound Drivers in Haskell
Writing NetBSD Sound Drivers in Haskell
Kiwamu Okabe
 
Oktavia Search Engine - pyconjp2014
Oktavia Search Engine - pyconjp2014Oktavia Search Engine - pyconjp2014
Oktavia Search Engine - pyconjp2014
Yoshiki Shibukawa
 

What's hot (20)

JRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform FurtherJRuby: Pushing the Java Platform Further
JRuby: Pushing the Java Platform Further
 
coala demo
coala democoala demo
coala demo
 
Seminar on Parallel and Concurrent Programming
Seminar on Parallel and Concurrent ProgrammingSeminar on Parallel and Concurrent Programming
Seminar on Parallel and Concurrent Programming
 
The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015
 
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
 
Bigdata Presentation
Bigdata PresentationBigdata Presentation
Bigdata Presentation
 
Realm
RealmRealm
Realm
 
Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014
 
Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011Nick Sieger JRuby Concurrency EMRubyConf 2011
Nick Sieger JRuby Concurrency EMRubyConf 2011
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder Ruby
 
Improving Performance of a WebKit Port MIPS Platform (ELC 2014)
Improving Performance of a WebKit Port MIPS Platform (ELC 2014)Improving Performance of a WebKit Port MIPS Platform (ELC 2014)
Improving Performance of a WebKit Port MIPS Platform (ELC 2014)
 
Large scale nlp using python's nltk on azure
Large scale nlp using python's nltk on azureLarge scale nlp using python's nltk on azure
Large scale nlp using python's nltk on azure
 
Engineering fast indexes (Deepdive)
Engineering fast indexes (Deepdive)Engineering fast indexes (Deepdive)
Engineering fast indexes (Deepdive)
 
WTF is Twisted?
WTF is Twisted?WTF is Twisted?
WTF is Twisted?
 
Microsoft HPC - Kivanc Ozuolmez - Public Content
Microsoft HPC - Kivanc Ozuolmez - Public ContentMicrosoft HPC - Kivanc Ozuolmez - Public Content
Microsoft HPC - Kivanc Ozuolmez - Public Content
 
Cryptocurrency && Ruby
Cryptocurrency && RubyCryptocurrency && Ruby
Cryptocurrency && Ruby
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
The impact of supercomputers on MSR
The impact of supercomputers on MSRThe impact of supercomputers on MSR
The impact of supercomputers on MSR
 
Writing NetBSD Sound Drivers in Haskell
Writing NetBSD Sound Drivers in HaskellWriting NetBSD Sound Drivers in Haskell
Writing NetBSD Sound Drivers in Haskell
 
Oktavia Search Engine - pyconjp2014
Oktavia Search Engine - pyconjp2014Oktavia Search Engine - pyconjp2014
Oktavia Search Engine - pyconjp2014
 

Similar to Concurrecy in Ruby

Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
luccastera
 
Scientific computing on jruby
Scientific computing on jrubyScientific computing on jruby
Scientific computing on jruby
Prasun Anand
 
Ruby - The Hard Bits
Ruby - The Hard BitsRuby - The Hard Bits
Ruby - The Hard Bits
Paul Gallagher
 
IJTC%202009%20JRuby
IJTC%202009%20JRubyIJTC%202009%20JRuby
IJTC%202009%20JRuby
tutorialsruby
 
IJTC%202009%20JRuby
IJTC%202009%20JRubyIJTC%202009%20JRuby
IJTC%202009%20JRuby
tutorialsruby
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
Barry Jones
 
Katello on TorqueBox
Katello on TorqueBoxKatello on TorqueBox
Katello on TorqueBox
lzap
 
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attacDefcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Priyanka Aash
 
Javascript on Arduino
Javascript on ArduinoJavascript on Arduino
Javascript on Arduino
Keith Bloomfield
 
Ruby Throwdown Hosted by Engine Yard
Ruby Throwdown Hosted by Engine YardRuby Throwdown Hosted by Engine Yard
Ruby Throwdown Hosted by Engine Yard
Jacob Lehrbaum
 
Multi-threaded web crawler in Ruby
Multi-threaded web crawler in RubyMulti-threaded web crawler in Ruby
Multi-threaded web crawler in Ruby
Polcode
 
Concurrency in ruby
Concurrency in rubyConcurrency in ruby
Concurrency in ruby
Marco Borromeo
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
Takayuki Muranushi
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
Skills Matter
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails Final
Robert Postill
 
Nibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL storeNibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL store
Edward Capriolo
 
Nibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL storeNibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL store
Edward Capriolo
 
Building your own NSQL store
Building your own NSQL storeBuilding your own NSQL store
Building your own NSQL store
Edward Capriolo
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
Tom Croucher
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
Hiroshi SHIBATA
 

Similar to Concurrecy in Ruby (20)

Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
 
Scientific computing on jruby
Scientific computing on jrubyScientific computing on jruby
Scientific computing on jruby
 
Ruby - The Hard Bits
Ruby - The Hard BitsRuby - The Hard Bits
Ruby - The Hard Bits
 
IJTC%202009%20JRuby
IJTC%202009%20JRubyIJTC%202009%20JRuby
IJTC%202009%20JRuby
 
IJTC%202009%20JRuby
IJTC%202009%20JRubyIJTC%202009%20JRuby
IJTC%202009%20JRuby
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Katello on TorqueBox
Katello on TorqueBoxKatello on TorqueBox
Katello on TorqueBox
 
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attacDefcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
 
Javascript on Arduino
Javascript on ArduinoJavascript on Arduino
Javascript on Arduino
 
Ruby Throwdown Hosted by Engine Yard
Ruby Throwdown Hosted by Engine YardRuby Throwdown Hosted by Engine Yard
Ruby Throwdown Hosted by Engine Yard
 
Multi-threaded web crawler in Ruby
Multi-threaded web crawler in RubyMulti-threaded web crawler in Ruby
Multi-threaded web crawler in Ruby
 
Concurrency in ruby
Concurrency in rubyConcurrency in ruby
Concurrency in ruby
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails Final
 
Nibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL storeNibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL store
 
Nibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL storeNibiru: Building your own NoSQL store
Nibiru: Building your own NoSQL store
 
Building your own NSQL store
Building your own NSQL storeBuilding your own NSQL store
Building your own NSQL store
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
 

Recently uploaded

Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 

Recently uploaded (20)

Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 

Concurrecy in Ruby

  • 3. Every two years we will ● halve the size of transistors ● double the number of transistors per chip ● double the clock frequency
  • 5. But clock frequency is not raising any more source: http://cpudb.stanford.edu/
  • 6. CPU caches help source: http://cpudb.stanford.edu/ The speed of the RAM chips and of the communication bus are two other bottlenecks
  • 7. How to speed up programs? ● run them on many (logical) cores in parallel with OS threads ● not an easy task to do ● you have to get the concurrency right first
  • 8. Rob Pike's talk from 2013 "If you looked at the programming languages of today you probably get this idea that the world is object-oriented. But it's not. It's actually parallel." http://bit.ly/pike2013
  • 9. Concurrency is not Parallelism concurrency dealing with many things at the same time (it's about structure/design) parallelism doing many things at the same time
  • 10. But Ruby can't do parallelism, right? ● MRI (Matz's C ruby) ● Jruby ● Rubinius
  • 11. Benchmarks require 'benchmark' n = 30_000_000 Benchmark.bm do |x| t1 = Thread.new { x.report {for i in 1..n; a = "1"; end } } t2 = Thread.new { x.report {n.times do ; a = "1"; end } } t3 = Thread.new { x.report {1.upto(n) do ; a = "1"; end } } t1.join # wait for thread 1 to finish t2.join # wait for thread 2 to finish t3.join # wait for thread 3 to finish end
  • 12. ruby user system total real 6.420000 0.040000 6.460000 ( 6.816842) 6.440000 0.040000 6.480000 ( 6.837540) 6.250000 0.040000 6.290000 ( 6.577156) jruby user system total real 8.810000 0.150000 8.960000 ( 3.284740) 9.550000 0.160000 9.710000 ( 3.622296) 10.320000 0.180000 10.500000 ( 4.413089)
  • 13. GIL Global Interpreter Lock Prevents more than one thread of ruby code to run in parallel. Protects internal consistency of the ruby's VM state It's not documented, not covered by public tests.
  • 15. MRI rocks MRI performs great! How is that? I/O is blocking - GIL is released.
  • 16. Push to array from multiple threads
  • 17. Push to array from multiple threads ruby: 5000 jruby: 4284 rubinius: 3231
  • 18. array#push method is run by array#<< is defined as: rb_ary_push VALUE rb_ary_push(VALUE ary, VALUE item) { long idx = RARRAY_LEN(ary); VALUE target_ary = ary_ensure_room_for_push(ary, 1); RARRAY_PTR_USE(ary, ptr, { RB_OBJ_WRITE(target_ary, &ptr[idx], item); }); ARY_SET_LEN(ary, idx + 1); return ary; }
  • 19. So my code is thread-safe as long as it is run on MRI, right? Let's check
  • 20. Let's put some threads to work
  • 21. The sheep might get shorn multiple times in a row > ruby sheep.rb shearing... shearing... > jruby sheep.rb shearing... > xruby sheep.rb shearing... shearing...
  • 22. Strategies to handle concurrency ● thread scheduler could interrupt the thread at any moment ● resources (memory, files, ...) may be shared among multiple threads ● we need atomic operations
  • 23. The usual suspects for synchronise resource sharing ● locks (inside process) ● mutex (between processes) ● semaphore (mutex for multiple number of threads)
  • 24. Cons of locks/mutex/semaphore complex (deadlocks, starvation, livelocks) leaky (no abstractions) no composability (Account transfer)
  • 25. Example: The transfer between two accounts Simon Peyton Jones (suggests STM) Not always 1.000.000 Money can disappear in the thin air (the same substance it is usually created from).
  • 26. Alternatives? ● Actor model (Erlang, Scala) ● CSP (Go, Ruby, Clojure, Kotlin) ● Software Transactional Memory (Haskell, Clojure, Ruby) ● Guilds (New Ruby Concurrency model for Ruby 3 proposed by Koichi Sasada)
  • 30. Don't communicate by sharing. Share by communicating.
  • 31. What would you change in Ruby if you could go back in time? "I would remove the thread and add actors or some other more advanced concurrency features" Yukihiro "Matz" Matsumoto Source: Wikipedia
  • 32. The Take-away get familiar with the alternative concurrency handling strategies, read Tony Hoare's CSP original paper, forget everything from this talk and keep writing the single threaded Ruby code that mostly does I/O.