Ruby's concurrency management supports processes, threads, and fibers. Guild is a proposed new abstraction for Ruby 3 that aims to allow parallel execution while prohibiting sharing of mutable objects between threads. Guilds group threads so that threads within a guild cannot run in parallel due to the Giant Guild Lock, but threads across guilds can run in parallel. Objects have membership to a single guild, and inter-guild communication uses channels that can copy or transfer membership of objects.
At the NATS June Meetup in Boulder, CO, Steven Osborne and Charlie Strawn of Workiva present the Actor Model concept their team are using, and some of the work they are doing to connect NATS and Akka.
You can learn more about NATS at http://www.nats.io
Ruby developers need to stop using EventMachine. It's the wrong direction.
Lost in the "Threads vs Event Driven vs Process Spawning" debate is that you can combine them! Learn how Celluloid is improving thread programming by abstracting them using a higher level framework called Celluloid, how you can use Celluloid::IO to throw a reactor pattern into a thread. Using this approach, you can take advantage of threading and use all CPU power on a machine with JRuby or Rubinius. I also discuss the future of distributed objects and computing, and where I think things are going.
At the NATS June Meetup in Boulder, CO, Steven Osborne and Charlie Strawn of Workiva present the Actor Model concept their team are using, and some of the work they are doing to connect NATS and Akka.
You can learn more about NATS at http://www.nats.io
Ruby developers need to stop using EventMachine. It's the wrong direction.
Lost in the "Threads vs Event Driven vs Process Spawning" debate is that you can combine them! Learn how Celluloid is improving thread programming by abstracting them using a higher level framework called Celluloid, how you can use Celluloid::IO to throw a reactor pattern into a thread. Using this approach, you can take advantage of threading and use all CPU power on a machine with JRuby or Rubinius. I also discuss the future of distributed objects and computing, and where I think things are going.
Lock-free algorithms for Kotlin CoroutinesRoman Elizarov
Presentation for SPTCC 2017 - http://neerc.ifmo.ru/sptcc/
Video (part 1): https://www.youtube.com/watch?v=W2dOOBN1OQI
Video (part 2): https://www.youtube.com/watch?v=iQsN_IDUTSc
JavaScript and popular programming paradigms (OOP, AOP, FP, DSL). Overview of the language to see what tools we can leverage to reduce complexity of our projects.
This part goes over more language features and looks at FP, and DSLs with JavaScript.
The presentation was delivered at ClubAJAX on 3/2/2010.
Blog post: http://lazutkin.com/blog/2010/mar/4/exciting-js-2/
Beginning is Part I: http://www.slideshare.net/elazutkin/exciting-javascript-part-i
Look past the square braces and the damned header files and Objective-C -- the essential language of iOS development -- really isn't that different from other object-oriented languages. Classes, single-inheritance, polymorphism, implementation hiding... check, check, check, and check. So it's really not that difficult for old Java / Python / Ruby / C++ dogs to learn new tricks once they install Xcode, right?
To be a competent Obj-C programmer, not that hard.
To be a great Obj-C programmer... now that's another story.
In this session, we will look at traits that are unique to Objective-C, the tricks that bring out the expressiveness and power of the language. We'll also look at how to write idiomatic code that will be easily understood and maintained by other Objective-C developers. We'll look at how Automatic Reference Counting resembles but is really nothing like Garbage Collection, how properties put plain old instance variables to shame, how we loosely couple classes with delegates and notification, how blocks help us un-block our code by simplifying asynchronicity, and more.
A short introduction to the more advanced python and programming in general. Intended for users that has already learned the basic coding skills but want to have a rapid tour of more in-depth capacities offered by Python and some general programming background.
Execrices are available at: https://github.com/chiffa/Intermediate_Python_programming
This is a presentation for International Lisp Conference 2012 which was held in Kyoto, Japan.
Clack is a web application environment for Common Lisp to make your web applications be portable and reusable by abstracting HTTP into a simple API.
In this paper, I describe what are problems in web development and how Clack solves them.
Developing high-performance network servers in LispVladimir Sedach
Overview of current high-performance Common Lisp web servers and implementation techniques, and description of a new hybrid approach to asynchronous I/O based on separate racing accept() and epoll() thread pools.
Many companies and individuals these days release parts of their work as open source software. This benefits the entire software development community and brings are new set of challenges. Maintaining open source well takes time and effort. Abandoning a project can be very problematic for your users. How does one find a balance?
In this talk we’ll discuss how we did the impossible: make the users of more than 30 ClojureWerkz projects happy and still have a life.
JavaScript is arguably the most popular language in the world. It runs in the browser, on the server, on mobile devices, and even powers the Internet of things. In spite of being completely ubiquitous, JavaScript is also the most hated language on the planet.
Unlike other programming languages, JavaScript straddles the line between imperative, object-oriented languages and functional ones. It was originally designed to be a version of the Scheme language for the browser. Which begs the questions, what if we programmed JavaScript functionally?
In this session, we will take a well-known programming problem and first implemented imperatively, then progressively make it more functional. Along the way, we will discuss what makes a language functional.
Best of all we will just use the latest version of JavaScript, ES-2015. No need for any additional libraries. So if you are looking for a different way to code JS, or only curious to learn a bit more about FP, please join us.
Lock-free algorithms for Kotlin CoroutinesRoman Elizarov
Presentation for SPTCC 2017 - http://neerc.ifmo.ru/sptcc/
Video (part 1): https://www.youtube.com/watch?v=W2dOOBN1OQI
Video (part 2): https://www.youtube.com/watch?v=iQsN_IDUTSc
JavaScript and popular programming paradigms (OOP, AOP, FP, DSL). Overview of the language to see what tools we can leverage to reduce complexity of our projects.
This part goes over more language features and looks at FP, and DSLs with JavaScript.
The presentation was delivered at ClubAJAX on 3/2/2010.
Blog post: http://lazutkin.com/blog/2010/mar/4/exciting-js-2/
Beginning is Part I: http://www.slideshare.net/elazutkin/exciting-javascript-part-i
Look past the square braces and the damned header files and Objective-C -- the essential language of iOS development -- really isn't that different from other object-oriented languages. Classes, single-inheritance, polymorphism, implementation hiding... check, check, check, and check. So it's really not that difficult for old Java / Python / Ruby / C++ dogs to learn new tricks once they install Xcode, right?
To be a competent Obj-C programmer, not that hard.
To be a great Obj-C programmer... now that's another story.
In this session, we will look at traits that are unique to Objective-C, the tricks that bring out the expressiveness and power of the language. We'll also look at how to write idiomatic code that will be easily understood and maintained by other Objective-C developers. We'll look at how Automatic Reference Counting resembles but is really nothing like Garbage Collection, how properties put plain old instance variables to shame, how we loosely couple classes with delegates and notification, how blocks help us un-block our code by simplifying asynchronicity, and more.
A short introduction to the more advanced python and programming in general. Intended for users that has already learned the basic coding skills but want to have a rapid tour of more in-depth capacities offered by Python and some general programming background.
Execrices are available at: https://github.com/chiffa/Intermediate_Python_programming
This is a presentation for International Lisp Conference 2012 which was held in Kyoto, Japan.
Clack is a web application environment for Common Lisp to make your web applications be portable and reusable by abstracting HTTP into a simple API.
In this paper, I describe what are problems in web development and how Clack solves them.
Developing high-performance network servers in LispVladimir Sedach
Overview of current high-performance Common Lisp web servers and implementation techniques, and description of a new hybrid approach to asynchronous I/O based on separate racing accept() and epoll() thread pools.
Many companies and individuals these days release parts of their work as open source software. This benefits the entire software development community and brings are new set of challenges. Maintaining open source well takes time and effort. Abandoning a project can be very problematic for your users. How does one find a balance?
In this talk we’ll discuss how we did the impossible: make the users of more than 30 ClojureWerkz projects happy and still have a life.
JavaScript is arguably the most popular language in the world. It runs in the browser, on the server, on mobile devices, and even powers the Internet of things. In spite of being completely ubiquitous, JavaScript is also the most hated language on the planet.
Unlike other programming languages, JavaScript straddles the line between imperative, object-oriented languages and functional ones. It was originally designed to be a version of the Scheme language for the browser. Which begs the questions, what if we programmed JavaScript functionally?
In this session, we will take a well-known programming problem and first implemented imperatively, then progressively make it more functional. Along the way, we will discuss what makes a language functional.
Best of all we will just use the latest version of JavaScript, ES-2015. No need for any additional libraries. So if you are looking for a different way to code JS, or only curious to learn a bit more about FP, please join us.
Looming Marvelous - Virtual Threads in Java Javaland.pdfjexp
Nowadays we have 2 options for concurrency in Java:
* simple, synchronous, blocking code with limited scalability that tracks well linearly at runtime, or.
* complex, asynchronous libraries with high scalability that are harder to handle.
Project Loom aims to bring together the best aspects of these two approaches and make them available to developers.
In the talk, I'll briefly cover the history and challenges of concurrency in Java before we dive into Loom's approaches and do some behind-the-scenes implementation. To manage so many threads reasonably needs some structure - for this there are proposals for "Structured Concurrency" which we will also look at. Some examples and comparisons to test Loom will round up the talk.
Project Loom is included in Java 19 and 20 as a preview feature, it can already be tested how well it works with our applications and libraries.
Spoiler: Pretty good.
Go After 4 Years in Production - QCon 2015Travis Reeder
Being one of the first companies (Iron.io) to use Go in production, the first to publicly hire Go developers and organizers of the largest Go meetup in the world, Travis has a unique perspective on the language and the community around it. Since we started using it, it has become one of the fastest growing languages and is being used in almost all startups (and non-startups) in some way or another. After making the switch from Ruby to Go - there’s plenty to be said after 4 years. A discussion on performance, memory, concurrency, reliability, and deployment are key to exploring Go and it’s value in Production. See how it’s worked for Iron.io, strategies for finding talent and explore the community.
Repeating History...On Purpose...with ElixirBarry Jones
A dive into the highlights of Elixir that make it the ideal platform for the web...and how all these questions were answered figured out 30 years ago. Presented to Upstate Elixir in Greenville, SC on Nov 16.
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)Tech in Asia ID
Hengki Sihombing is the Co-Founder and CTO Urbanhire, a technology company who provides Software as a Service (SaaS) for Hiring and Recruitment and also Job search agregator for jobseeker.
Before founding Urbanhire, Hengki had over 10 years of professional experience in software development in companies like: OLX, Wego, Merah Putih Inc, GushCloud. Hengki also actively participates in various Technology communities. He founded and leads the JakartaJS Community with more than 1900 Members.
***
This slide was shared at Tech in Asia Product Development Conference 2017 (PDC'17) on 9-10 August 2017.
Get more insightful updates from TIA by subscribing techin.asia/updateselalu
Concurrency and Multithreading Demistified - Reversim Summit 2014Haim Yadid
Life as a software engineer is so exciting! Computing power continue to rise exponentially, software demands continue to rise exponentially as well, so far so good. The bad news are that in the last decade the computing power of single threaded application remains almost flat.
If you decide to continue ignoring concurrency and multi-threading the gap between the problems you are able to solve and your hardware capabilities will continue to rise. In this session we will discuss different approaches for taming the concurrency beast, such as shared mutability,shared immutability and isolated mutability actors, STM, etc we will discuss the shortcomings and the dangers of each approach and we will compare different programming languages and how they choose to tackle/ignore concurrency.
this is the PPt which having modern java8 multi threading
whci handles
coplete threading concepts in java
like
straem parallelization
computable feature
excuter fmaework
fork join
java 8 parallel stream
this is helpful for experince java developer
This slides explains why ConfigureAwait(false) needs to be called when we use async await. This slides is based on the following blog by Microsoft.
https://devblogs.microsoft.com/dotnet/configureawait-faq/
Netflix’s Big Data Platform team manages data warehouse in Amazon S3 with over 60 petabytes of data and writes hundreds of terabytes of data every day. At this scale, output committers that create extra copies or can’t handle task failures are no longer practical. This talk will explain the problems that are caused by the available committers when writing to S3, and show how Netflix solved the committer problem.
In this session, you’ll learn:
– Some background about Spark at Netflix
– About output committers, and how both Spark and Hadoop handle failures
– How HDFS and S3 differ, and why HDFS committers don’t work well
– A new output committer that uses the S3 multi-part upload API
– How you can use this new committer in your Spark applications to avoid duplicating data
Typesafe trainer and consultant Will Sargent describes just how Play Framework is so "fast" for Java and Scala production apps.
More Play, Akka, Scala and Apache Spark webinars, presentations, and videos:
http://typesafe.com/resources/videos
Similar to Ruby's Concurrency Management: Now and Future (20)
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
3. Today’s talk
Process Guild Thread Auto-Fiber Fiber
Available Yes No Yes No Yes
Switch on time Yes Yes Yes No No
Switch on I/O Auto Auto Auto Auto No
Next target Auto Auto Auto Auto Specify
Parallel run Yes Yes No (on MRI) No No
Shared data N/A (mostly) N/A Everything Everything Everything
Comm. Hard Maybe Easy Easy Easy Easy
Programming
difficulty
Hard Easy Difficult Easy Easy
Debugging
difficulty
Easy? Maybe Easy Hard Maybe hard Easy
5. Ruby interpreter
Ruby (Rails) app
RubyGems/Bundler
So many gems
such as Rails, pry, thin, … and so on.
Normal Ruby developer’s view
i gigantum umeris insidentes
Standing on the shoulders of giants
6. Interpret on RubyVM
Normal MRI developer’s view
6
Ruby
script
Parse
Compile
(codegen)
Ruby
Bytecode
Object management
Garbage collectorThreading
Embedded
classes and methods
Bundled
Libraries
Evaluator
Gem
Libraries
AST
Abstract Syntax Tree
7. Ruby interpreter
Ruby (Rails) app
RubyGems/Bundler
So many gems
such as Rails, pry, thin, … and so on.
Koichi’s job
Koichi
8. Ruby3: Ruby3 has 3 goals
•Static type checking
•Just-in-Time (JIT) compilation
•Parallel execution w/ highly
abstract concurrent model
10. Concurrency
“In computer science, concurrency is the decomposability
property of a program, algorithm, or problem into order-
independent or partially-ordered components or units.[1] This
means that even if the concurrent units of the program,
algorithm, or problem are executed out-of-order or in partial
order, the final outcome will remain the same. This allows for
parallel execution of the concurrent units, which can
significantly improve overall speed of the execution in multi-
processor and multi-core systems.”
https://en.wikipedia.org/wiki/Concurrency_(computer_science)
11. Concurrent and Parallel execution
Concurrent
execution
Logical concept
Parallel
(and concurrent)
execution
Physical concept
Ruby (MRI) support only concurrency
Task A
Task B
Task A
Task B
12. Concurrency
Why needed?
•Easy to write some kind of programs
•Download files simultaneously
•Process web requests simultaneously
•Agent simulation (assume computer games)
•Each agent has its own logics
•Run agents simultaneously
13. Concurrency
Example: Downloader
Download A
Download B
Download C
wait for receving
wait for receving
wait for receving
post process
post process
post process
We can write this kind of program w/o concurrency support,
but not simple, not easy
14. Downloader example
With concurrency support (Thread)
ts = URLs.map do |url|
Thread.new(url) do |u|
data = download(u)
File.write(u.to_fname, data)
end
end.each{|th| th.join} # wait
17. Downloader example
Without concurrency support
# Use select. Not so SIMPLE!!
fds = URLs.map do |u|
download_fd(u)
end
while ready_fds = select(fds)
ready_fds.each{|fd|
File.write(…, read(fd))}
end
21. Process
•Use OS multi-process
• Use fork on Unix-like systems
•Shared-nothing
• Communicate with IPC (pipe, etc) such as IO.pipe
•Programming
• Difficult to manage processes and IPC
•Debugging
• Easy because a few synchronization bugs
23. Inter-process communication
Example code
# Traditional multi-process example
r, w = IO.pipe
fork do
result_str = work_something.to_s
w.write result_str
w.close
end
puts r.read # wait for a result
24. Sophisticated libraries/frameworks for
process programming
•dRuby: Distributed object for Ruby
•parallel gem: Parallel programming with
processes
•unicorn: Process based web application
server (master – worker model w/ processes)
26. Thread
•Use Ruby managed threads
• Thread.new do … end
•Shared-everything
• Communication is very easy
•Programming
• Easy to make, easy to communicate (at a glance)
• Difficult to make completely safe program
•Debugging
• Hard because of synchronization
27. MRI: Thread with Giant Lock (GIL)
•Only a thread keeping the GIL can run (can’t
run in parallel)
Thread 1
Thread 2
Thread 1
CPU 1
CPU 2
IDLE
OS Thread 1
OS Thread 2
Lock
Lock
28. Inter-thread communication
Easy to share objects
Ruby process
objThread Thread
We can share objects directly
between threads very easily
30. Thread programming
Synchronization is required
•Reading/writing data simultaneously w/o
synchronization will cause serious problem
•Race condition
•Data race
31. Mutate shared objects
Lucky case
Ruby process
Thread
A
Thread
B
SpeakerObject
@name = ‘ko1’
@gender = ‘male’
(1) Thread A tries to change the Speaker
to “Yuki” (female)
Note: Yuki is my wife.
32. Mutate shared objects
Lucky case
Ruby process
Thread
A
Thread
B
SpeakerObject
@name = ‘Yuki’
@gender = ‘male’
(2) A changes the name to “Yuki”
write
33. Mutate shared objects
Lucky case
Ruby process
Thread
A
Thread
B
SpeakerObject
@name = ‘Yuki’
@gender = ‘female’
(3) A changes the gender to “female”
write
34. Mutate shared objects
Lucky case
Ruby process
Thread
A
Thread
B
SpeakerObject
@name = ‘Yuki’
@gender = ‘female’
(4) Complete.
A and B can read correct speaker.
read read
35. Mutate shared objects
Problematic case
Ruby process
Thread
A
Thread
B
SpeakerObject
@name = ‘ko1’
@gender = ‘male’
(1) Thread A tries to change the Speaker
to “Yuki” (female)
36. Mutate shared objects
Problematic case
Ruby process
Thread
A
Thread
B
SpeakerObject
@name = ‘Yuki’
@gender = ‘male’
(2) A changes the name to “Yuki”
write
37. Mutate shared objects
Problematic case
Ruby process
Thread
A
Thread
B
SpeakerObject
@name = ‘Yuki’
@gender = ‘male’
(3) Before the changing,
B read incorrect data!!
Note: Yuki should be female.
read
39. Mutate shared objects
With lock
Ruby process
Thread
A
Thread
B
SpeakerObject
@name = ‘ko1’
@gender = ‘male’
(1) Thread A tries to change the Speaker
to “Yuki” (female). Lock an obj.
Locked by A
40. Mutate shared objects
With lock
Ruby process
Thread
A
Thread
B
SpeakerObject
@name = ‘Yuki’
@gender = ‘male’
(2) A changes the name to “Yuki”
Locked by A
41. Mutate shared objects
With lock
Ruby process
Thread
A
Thread
B
SpeakerObject
@name = ‘Yuki’
@gender = ‘male’
(3) Before complete the changing,
B tries to read, but prohibited by a lock
Locked by A
read
42. Thread programming
Easy to share data: Good and Bad
•Good: Easy to communicate with threads
•Bad: Too easy. Difficult to manage all of
them
•Mutation for shared data requires correct
synchronization
•Sometimes objects are shared implicitly
•Otherwise, it causes serious problems
43. “Why Threads Are A Bad Idea
(for most purposes)”
• Quoted from John Ousterhout, 1995 (about 20 years ago ☺)
44. Compare Process with Thread
Process Thread
Available Yes Yes
Switch on time Yes Yes
Switch on I/O Auto Auto
Next target Auto Auto
Parallel run Yes No (on MRI)
Shared data N/A Everything
Communication Hard (high-overhead) Easy (lightweight)
Programming difficulty Hard Difficult
Debugging difficulty Easy? Hard
47. Fiber example
Infinite generator
fib = Fiber.new do
Fiber.yield a = b = 1
loop{ a, b = b, a+b
Fiber.yield a }
end
10.times{ p fib.resume }
1. Fiber creation
2. Resume Fiber
3. Return to the
parent fiber
4. Resume fiber
(again)
5. Return to the
parent fiber
6. Resume fiber
(again2)
48. Fiber example
Infinite generator
fib = Fiber.new do
Fiber.yield a = b = 1
loop{ a, b = b, a+b
Fiber.yield a }
end
10.times{ p fib.resume }
1. Fiber creation
2. Resume Fiber
3. Return to the
parent fiber
4. Resume fiber
(again)
5. Return to the
parent fiber
6. Resume fiber
(again2)
49. Not a Proc?
a = 0; b = 1
fib = Proc.new{
a, b = b, a+b
a
}
p fib.call #=> 1
p fib.call #=> 1
p fib.call #=> 2
p fib.call #=> 3
p fib.call #=> 5
Proc can’t restart from
the middle of block
51. Fiber example
Inner iterator to external iterator
f1 = Fiber.new do
2.times{|i| Fiber.yield i}
end
p f1.resume #=> 0
p f1.resume #=> 1
p f1.resume #=> 2 # return value of #times
p f1.resume #=> dead fiber called
(FiberError)
52. Fiber example
Inner iterator to external iterator
etc_passwd_ex_iter = Fiber.new do
open('/etc/passwd').each_line{|line|
Fiber.yield line
}
end
p etc_passwd_ex_iter.resume #=> 1st line
p etc_passwd_ex_iter.resume #=> 2nd line
…
53. Fiber example
Inner iterator to external iterator
# make Enumerator
iter = open('/etc/passwd').each_line
# Enumerator#next use Fiber implicitly
p iter.next #=> 1st line
p iter.next #=> 2nd line
…
55. Fiber example
Agent simulation
characters << Fiber.new{
# you can specify complex rule for chars
loop{
cow.move_up; Fiber.yield
cow.move_right; Fiber.yield
cow.move_down; Fiber.yield
cow.move_left; Fiber.yield
}
}
56. Fiber example
Non-blocking IO scheduler
Wait multiple IO ops with
traditional “select” or
modern “poll”, “epoll” interface
57. Fiber
Programming difficulty
•Good
•Synchronization for shared data is not required
because of no unexpected switching
•Lightweight than Processes and Threads
•Bad
•We need to switch explicitly. For example,
“Blocking operations” (I/O blocking, etc) stop all
fibers
58. Comparison of existing supports
Process Thread Fiber
Available Yes Yes Yes
Switch on time Yes Yes No
Switch on I/O Auto Auto No
Next target Auto Auto Specify
Parallel run Yes No (on MRI) No
Shared data N/A Everything Everything
Comm. Hard Easy Easy
Programming difficulty Hard Difficult Easy
Debugging difficulty Easy? Hard Easy
59. Fiber: Brief history
•2007/05/23 cont.c (for callcc)
•2007/05/25 Fiber impl. [ruby-dev:30827]
•2007/05/28 Fiber introduced into cont.c
•2007/08/25 Fix Fiber spec
•2017 is 10th anniversary I introduced ☺
62. Key idea
Problem of multi-thread programming:
Easy to share mutable objects
Idea:
Prohibit sharing mutable objects
63. Our goal for Ruby 3
•We need to keep compatibility with Ruby 2.
•We can make parallel program.
•We shouldn’t consider locks any more.
•We can share objects with copy, but copy
operation should be fast.
•We should share immutable objects if we can.
•We can provide special objects to share
mutable objects like Clojure if we really need
speed.
64. Guild: New concurrency abstraction
•Guild has at least one thread (and a thread
has at least one fiber)
Guild
Thread
Fiber
Guild
Thread
Fiber
Guild
Thread
Fiber
Fiber
Thread
Fiber
65. Threads in different guilds can run in
Parallel
•Threads in different guilds can run in parallel
•Threads in a same guild can not run in parallel
because of GVL (or GGL: Giant Guild Lock)
G1:T1
G1:T2
G2:T3
Acquire GGL
Acquire GGL
66. Important rule:
Mutable Objects have a membership
•All of mutable objects should belong to only
one Guild exclusively
•Guild can not touch objects belong to other
guildsGuild 1 Guild 2
obj
obj
obj
obj
obj
Can’t access
(read/write)
NG!!
67. Object membership
Only one guild can access mutable object
→ We don’t need to consider locks
(if Guild has only one thread)
71. Move using Channel
Guild1 Guild2
channel
o2
o3
o1
MOVE
channel.transfer_membership(o1) o1 = channel.receive
O2:Data
O3:Data
-
-
-
From Guild1 perspective,
transferred objects are invalidated
72. Sharing immutable objects
We can share reference to immutable objects
Guild1 Guild2
o2
o3
o1
channel
channel.transfer(o1) o1 = channel.receive
O2:Data O3:Data
Ref to
o1
If o1 is immutable, any Guild can read o1
read
Ref to
o1
read
73. Use-case 1: master – worker type
def fib(n) ... end
g_fib = Guild.new(script: %q{
ch = Guild.default_channel
while n, return_ch = ch.receive
return_ch.transfer fib(n)
end
})
ch = Guild::Channel.new
g_fib.transfer([3, ch])
p ch.receive
Main
Guild
Fibonacci
Guild
ch
return_ch
n, return_ch
Answer of fib(n)
NOTE: Making other Fibonacci guilds,
you can compute fib(n) in parallel
74. Use-case 2: pipeline
result_ch = Guild::Channel.new
g_pipe3 = Guild.new(script: %q{
while obj = Guild.default_channel.receive
obj = modify_obj3(obj)
Guild.argv[0].transfer_membership(obj)
end
}, argv: [result_ch])
g_pipe2 = Guild.new(script: %q{
while obj = Guild.default_channel.receive
obj = modify_obj2(obj)
Guild.argv[0].transfer_membership(obj)
end
}, argv: [g_pipe3])
g_pipe1 = Guild.new(script: %q{
while obj = Guild.default_channel.receive
obj = modify_obj1(obj)
Guild.argv[0].transfer_membership(obj)
end
}, argv: [g_pipe2])
obj = SomeClass.new
g_pipe1.transfer_membership(obj)
obj = result_ch.receive
Main
Guild
Pipe 1
Guild
obj
Obj’
Move
and modify
Pipe 2
Guild
Obj’’
Move
and modify
Pipe 3
Guild
Obj’’’
Obj’’’
Move
and modify
Move
75. Compare with Process, Guild, Thread
Process Guild Thread
Available Yes No Yes
Switch on time Yes Yes Yes
Switch on I/O Auto Auto Auto
Next target Auto Auto Auto
Parallel run Yes Yes No (on MRI)
Shared data N/A (mostly) N/A Everything
Comm. Hard Maybe Easy Easy
Programming difficulty Hard Easy Difficult
Debugging difficulty Easy? Maybe Easy Hard
77. Problem of Fiber
Requires explicit switching
•“Fiber” enables writing scheduler by
programmer
→ Programmers need to write own scheduler
•We need to manage blocking operations like
I/O blocking
79. Auto Fiber proposal
Automatic schedule on I/O blocking
•Support Fiber scheduler
natively
• Don’t need to return
scheduler
•Switch Fibers on all blocking
I/O (and other ops)
• No need to change existing
programs
80. Advantage and Disadvantage
•Advantage
•Don’t need to modify existing programs
•Lightweight as a Fiber
•Safer than Threads (no preemption)
•Disadvantage
•Introduce “non-deterministic” dangers same as
Thread programs
• Non atomic operations can intercept accidentally.
Change the name…?
81. Compare w/ Thread and (auto-)Fiber
Thread Auto-Fiber Fiber
Available Yes No Yes
Switch on time Yes No No
Switch on I/O Auto Auto No
Next target Auto Auto Specify
Parallel run No (on MRI) No No
Shared data Everything Everything Everything
Comm. Easy Easy Easy
Programming difficulty Difficult Easy Easy
Debugging difficulty Hard Maybe hard Easy
83. Today’s talk
Process Guild Thread Auto-Fiber Fiber
Available Yes No Yes No Yes
Switch on time Yes Yes Yes No No
Switch on I/O Auto Auto Auto Auto No
Next target Auto Auto Auto Auto Specify
Parallel run Yes Yes No (on MRI) No No
Shared data N/A (mostly) N/A Everything Everything Everything
Comm. Hard Maybe Easy Easy Easy Easy
Programming
difficulty
Hard Easy Difficult Easy Easy
Debugging
difficulty
Easy? Maybe Easy Hard Maybe hard Easy