Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Ractor’s speed


is not light-speed.
Satoshi Tagomori (@tagomoris)
Satoshi Tagomori (@tagomoris)


a.k.a. Moris (モリス)


Freelance technical consultant (Aug 2021 ~)
Ractor


A new experimental feature


of Ruby 3.0


to run Ruby code in parallel on CPUs
Talks about Ractor in this Kaigi
• “Parallel testing with Ractors: putting CPUs to work”




by Vinicius Stock at Day 1


...
Ractor’s Features
• Can run Ruby code of multiple Ractors in parallel on CPU cores


• by managing objects per Ractor


• ...
What does “shareable” mean?
• Should be marked by Ractor.make_shareable(obj)


• will be frozen (in most cases)


• Proc: ...
Isolated Proc (1)
Isolated Proc (2)
Ractor:


The Feature for Speed
Question: How fast is Ruby w/ Ractor?
• xN faster if the laptop has N cpu cores?


• 8 cores on M1


• Is it true for Web ...
Needs: Experimental App Server using Ractor
• Rack application server


• Rack: protocol between server and application


...
light speed
light speed
right_speed
https:/
/github.com/tagomoris/right_speed
https:/
/rubygems.org/gems/right_speed
$ rackup -s right_speed config.ru


-O Host=127.0.0.1


-O Port=8080


-O Workers=12
Default # of workers is equal to # of...
Demonstration


Running apps on right_speed


* Rack app


* Sinatra app


* Ruby on Rails app
https:/
/github.com/tagomor...
Demonstration


Traffic


* single client connection + thread


* multiple client connections + threads
Problems about WebApps on Ractor
• SEGV at closing connections(?)


• Module/class instance variable accesses


• Accessin...
SEGV at closing connections (?)
• SEGV caused when it handles 2 (or more) connections


• bugs#18024
Module/Class Instance Variable Accesses
• Reading module/class instance variables causes Ractor::IsolationError


• Many f...
Accessing Un-frozen/shareable Constants
• Constants can be accessible from Ractors, if deeply-frozen


• Use the magic com...
define_method (1)
• Methods can be called in Ractor, usually


• Methods de
fi
ned by de
fi
ne_method may cause errors


•...
define_method (2)
• Ractor-safe methods with shareable/isolated blocks


• Need shorthand!
Right Things to Be Done
• Applications: Check Ractor-safe or not


• Frameworks, libraries: Need many patches


• To make ...
Thank you!
Ractor's speed is not light-speed
You’ve finished this document.
Download and read it offline.
Upcoming SlideShare
What to Upload to SlideShare
Next
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

Share

Ractor's speed is not light-speed

Download to read offline

My talk session at RubyKaigi Takeout 2021, introducing Ractor and RightSpeed.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

Ractor's speed is not light-speed

  1. 1. Ractor’s speed is not light-speed. Satoshi Tagomori (@tagomoris)
  2. 2. Satoshi Tagomori (@tagomoris) a.k.a. Moris (モリス) Freelance technical consultant (Aug 2021 ~)
  3. 3. Ractor A new experimental feature of Ruby 3.0 to run Ruby code in parallel on CPUs
  4. 4. Talks about Ractor in this Kaigi • “Parallel testing with Ractors: putting CPUs to work” 
 
 by Vinicius Stock at Day 1 
 • “Ractor’s speed is not light-speed” (this talk) 
 
 by Satoshi Tagomori at Day 2 
 • “Ruby, Ractor, QUIC” 
 
 by Yusuke Nakamura at Day 3
  5. 5. Ractor’s Features • Can run Ruby code of multiple Ractors in parallel on CPU cores • by managing objects per Ractor • Can move objects between Ractors • Moved objects become invisible from the original Ractor • Can share “shareable” objects between Ractors • Modules, Classes • Application code (Proc) • De fi nitions (constants), Settings/Con fi gurations (frozen objects) • …
  6. 6. What does “shareable” mean? • Should be marked by Ractor.make_shareable(obj) • will be frozen (in most cases) • Proc: Ractor.make_shareable() makes Proc isolated • “Isolated” Proc is not frozen, but shareable • Proc#binding raises ArgumentError if it’s isolated • All referred values (from the Proc) should be shareable too
  7. 7. Isolated Proc (1)
  8. 8. Isolated Proc (2)
  9. 9. Ractor: The Feature for Speed
  10. 10. Question: How fast is Ruby w/ Ractor? • xN faster if the laptop has N cpu cores? • 8 cores on M1 • Is it true for Web applications? • Is that faster than N processes by fork? • Connection passing on memory (Ractor) vs RPC (fork) • Does my webapp run faster w/ Ractor than the current deployment?
  11. 11. Needs: Experimental App Server using Ractor • Rack application server • Rack: protocol between server and application • All servers are Rack server: webrick, unicorn, thin, puma, … • Processing workers on Ractor • Receive established connection, read request • Run your Rack application • Write response • Speed: Appropriate performance, less overhead
  12. 12. light speed
  13. 13. light speed
  14. 14. right_speed https:/ /github.com/tagomoris/right_speed https:/ /rubygems.org/gems/right_speed
  15. 15. $ rackup -s right_speed config.ru -O Host=127.0.0.1 -O Port=8080 -O Workers=12 Default # of workers is equal to # of CPUs
  16. 16. Demonstration Running apps on right_speed * Rack app * Sinatra app * Ruby on Rails app https:/ /github.com/tagomoris/demo-webapps
  17. 17. Demonstration Traffic * single client connection + thread * multiple client connections + threads
  18. 18. Problems about WebApps on Ractor • SEGV at closing connections(?) • Module/class instance variable accesses • Accessing un-frozen (un-shareable) constants • Dynamically de fi ned methods w/ un-shareable Proc
  19. 19. SEGV at closing connections (?) • SEGV caused when it handles 2 (or more) connections • bugs#18024
  20. 20. Module/Class Instance Variable Accesses • Reading module/class instance variables causes Ractor::IsolationError • Many frameworks (Rack, Sinatra, Rails) are heavily using it • @var in the context of class << self • for settings in many cases • Used for default instance or default options (e.g., JSON.dump) • Reading it will be allowed bugs#17592 • in the future (not fi xed yet)
  21. 21. Accessing Un-frozen/shareable Constants • Constants can be accessible from Ractors, if deeply-frozen • Use the magic comment always! 
 
 # frozen_string_literal: true • Want a variant for Hash/Array (in my idea) 
 
 # frozen_shareable_constant_literal: true
  22. 22. define_method (1) • Methods can be called in Ractor, usually • Methods de fi ned by de fi ne_method may cause errors • Blocks are unshareable! • Frameworks (RoR/Sinatra/…) do this everywhere
  23. 23. define_method (2) • Ractor-safe methods with shareable/isolated blocks • Need shorthand!
  24. 24. Right Things to Be Done • Applications: Check Ractor-safe or not 
 • Frameworks, libraries: Need many patches • To make it Ractor-safe 
 • Ruby runtime: Make Ractor production ready • More Ractor-safe core libraries • More Ractor features (e.g, bugs#18139, etc) • More features about productivity? (constant, proc, etc)
  25. 25. Thank you!

My talk session at RubyKaigi Takeout 2021, introducing Ractor and RightSpeed.

Views

Total views

2,190

On Slideshare

0

From embeds

0

Number of embeds

1,871

Actions

Downloads

3

Shares

0

Comments

0

Likes

0

×