Summarized using AI

Ractor on Ruby 3.4

Koichi Sasada • November 13, 2024 • Chicago, IL • Talk

Summary of Ractor on Ruby 3.4 Presentation

Koichi Sasada, an experienced Ruby interpreter developer, presented insights into the Ractor feature on Ruby during RubyConf 2024. Ractor, introduced in Ruby 3.0, facilitates parallel programming, enabling developers to create more efficient applications by allowing multiple threads to run concurrently. However, the presentation highlighted existing performance issues and compatibility challenges with the Ractor implementation.

Key Points Discussed:

  • Introduction to Ractor:

    • Ractor allows for parallel computing in Ruby, aiming to improve performance, especially on multicore systems.
    • There is a discussion about the Global VM Lock (GVL) in Ruby, which restricts threads from running simultaneously, thus, introducing Ractor addresses this limitation by running Ractors in parallel.
  • Philosophy Behind Parallel Programming:

    • Sasada elaborated on the challenges of parallel programming, such as synchronization of shared data between threads, emphasizing that it is a complex task prone to errors.
    • He argued for isolating object spaces to reduce complexity and improve safety when sharing state.
  • Challenges with Current Ractor Implementation:

    • The performance is hindered by the lack of support in certain libraries, such as Ractor not working seamlessly with many existing Ruby libraries.
    • The garbage collector (GC) implementations slow down performance when using Ractor, indicating that current GC mechanisms are not optimized for Ractor's architecture.
  • Future of Ractors in Ruby 3.4 and Beyond:

    • Ruby 3.4 is expected to introduce various feature enhancements that will improve Ractor’s performance and broaden its compatibility.
    • Sasada also mentioned ongoing efforts to create parallel garbage collection that aligns with Ractor's structure.

Significant Examples:

  • He discussed how Ractor enables applications to run tasks significantly faster, with references to performance benchmarks demonstrating improvements.
  • Mentioned challenges with specific programming constructs and libraries, illustrating real-world issues developers face while adopting Ractor.

Conclusions and Takeaways:

  • Ractor is a powerful addition to Ruby that promotes parallel programming; however, several hurdles need addressing to harness its full potential effectively.
  • Ongoing development and new features in Ruby 3.4 will be crucial for enhancing Ractor’s usability and performance.
  • Encouragement for developers to engage with the Ruby community to contribute to improving Ractor and Ruby as a language.

This presentation effectively provided a rounded view of the benefits and limitations of Ractor, setting an optimistic yet cautionary tone about its future in Ruby.

Ractor on Ruby 3.4
Koichi Sasada • November 13, 2024 • Chicago, IL • Talk

Ractor enables parallel programming on Ruby and has been introduced since Ruby 3.0. However, Ractor has many issues regarding performance and compatibility with the existing code base. In order to solve the current situation, Ruby 3.4 will introduce a number of features and performance improvements.

This presentation will show the advantages and limitations of
of current Ractor programming, and the future perspective of Ractor in Ruby 3.4 and beyond.

RubyConf 2024

00:00:16.480 uh thank you for uh giving me an
00:00:18.920 introduction introduce myself
00:00:22.519 so in fluent English so unfortunately my
00:00:26.800 English is not fluent so uh I I wrote
00:00:32.759 everything I want to say into the slide
00:00:36.960 but unfortunately the screen is not so
00:00:41.120 big so it is difficult to read uh small
00:00:44.360 characters so you can download my slide
00:00:48.079 PDF from this QR code so if you have a
00:00:51.600 laptop uh so you can download here from
00:00:57.079 here oh so many people takes a
00:01:09.000 picture is it
00:01:11.280 okay
00:01:13.720 yeah so continue the presentation so I
00:01:19.400 want to talk about the about
00:01:22.560 loor
00:01:24.360 so the prev at the previous eyeballs
00:01:28.520 talk so he introduce many things I want
00:01:32.479 to talk
00:01:34.040 so I can eliminate many things but I
00:01:37.880 want to talk about the uh what is loer
00:01:40.960 and why we need to introduce loer and
00:01:44.680 the uh the what the station with kind
00:01:48.520 rure and the what's new in Ruby
00:01:53.960 3.4 and the
00:01:57.240 uh in the future what today I want to
00:02:02.439 so at first I want to apologize that so
00:02:05.920 this year I was UN well for a long time
00:02:09.000 so I didn't achieve much contribution
00:02:12.360 for the lecture so in this presentation
00:02:16.360 I show you the many background and
00:02:19.440 philosophy and the the current
00:02:23.599 problems so maybe you so someone you
00:02:28.080 listen my uh previous talks so then you
00:02:31.680 you feel that oh it is same things but
00:02:34.599 please listen to my talk as a
00:02:39.239 refresher anyway uh I'm uh uh uh Luby
00:02:44.440 interpreter developer from
00:02:47.120 2004 so 20 years I continue the
00:02:51.840 developing the Ruby interpreter and do
00:02:55.640 uh did some uh achievements so that was
00:03:00.400 introduced by uh mat today's Keynotes
00:03:04.040 and also uh I so this is advertisement
00:03:09.440 but uh I will organize a ruby HCK
00:03:13.680 challenge Workshop tomorrow so if you
00:03:16.920 have any uh feature request if you have
00:03:20.879 any questions in internal of The lby
00:03:23.360 Interpreter or something you want to hug
00:03:26.000 the LI interpreter please please join us
00:03:30.040 and also so in the Luby hug challenge
00:03:33.360 session so at the 12
00:03:36.920 to we get we have ask the Luby committer
00:03:40.920 session so please come
00:03:43.760 join anyway and another uh introduction
00:03:47.760 is I'm maybe the shortest
00:03:50.799 discription uh writer in the GitHub
00:03:55.239 sponsor anyway now do you do you need to
00:04:00.079 check
00:04:01.400 this anyway no no problem anyway so what
00:04:05.720 is what and why we need to introduce
00:04:09.799 loer so loer was introduced from Ruby
00:04:13.760 3.0 and so it's Achi it enables the uh
00:04:19.680 par Computing on Ruby for more
00:04:22.600 performance on mul
00:04:24.320 course so it can make a faster
00:04:28.320 application and also Al laughter achiev
00:04:32.280 the lust concurrent
00:04:34.560 programs no BS because the object
00:04:38.520 sharing is highly
00:04:41.520 limited so this is a uh
00:04:45.039 some idea about
00:04:53.479 luure but today I want to show more more
00:04:58.160 and more background
00:05:00.759 so the previous eyeballs
00:05:05.800 talk uh introduced the GBL so GBL is a
00:05:10.960 so on the sh so threads cannot run in
00:05:15.440 par because of the
00:05:17.919 GBL even if the computer CPU has much
00:05:23.960 C so for example if we have three sleds
00:05:28.400 then we cannot
00:05:30.400 Le only one threat in the same time for
00:05:36.120 example
00:05:39.520 uh so at this time so the threat B only
00:05:45.039 only threat B can run because only one
00:05:47.840 threat can run in the same physical
00:05:53.680 time with luctus so luctus has a each
00:05:59.960 VOR has GB GBL so in this case
00:06:06.599 so this timing the threat B and threat D
00:06:11.560 on the different RoR can Le in
00:06:15.720 parallel so this is
00:06:18.199 rure and this is why we want to
00:06:21.280 introduce Loa into
00:06:24.319 Luby so with the uh Lor so we can so we
00:06:30.759 can Lear four Computing intensive tasks
00:06:35.479 with lectures so we can Lear the 3.7
00:06:39.639 times faster so very big
00:06:42.440 win
00:06:44.360 so con so you you can write write the
00:06:49.160 this kind of recursive program in
00:06:52.960 Ruby but the unfortun the bad news is
00:06:56.599 nobody like that
00:07:00.360 so by the way the name of gbriel
00:07:03.720 so this is the same same content about
00:07:08.280 the previous IA slid with there so the J
00:07:13.360 has mean Global or giant virtu machine
00:07:17.039 rocks per virtual
00:07:19.960 machine so virtual machine is similar to
00:07:23.360 the uh the process the unique process so
00:07:28.759 and the G uh so in Python they say the g
00:07:34.199 and it is more familiar we use this time
00:07:38.280 ter virtual machine because we tried to
00:07:42.520 introduce multiple virtual machines in
00:07:44.680 one process and and we choose a vir
00:07:49.120 machine on this
00:07:51.319 context but this uh trial was so I we
00:07:57.039 wrote some academic paper about the mle
00:07:59.680 machines better that this trial was
00:08:03.000 failed so if you you have interest why
00:08:06.199 this trial was failed then please ask me
00:08:09.680 later
00:08:13.759 anyway
00:08:15.400 so with L so G is GBL is not a
00:08:21.479 global this is kind of giant that's a
00:08:24.960 not so giant so maybe middle big problem
00:08:30.000 uh
00:08:31.560 locking so each doctor has J GBL and the
00:08:37.919 Ruby B machine has many G now day so
00:08:42.800 great or good variable look or anything
00:08:46.680 so if you have any good uh words so
00:08:50.320 please tell
00:08:51.440 me
00:08:55.880 anyway good sound anyway so back to the
00:08:59.880 Lo loor philosophy
00:09:04.680 so we think that the parallel
00:09:07.480 programming is very very difficult
00:09:10.000 because the we need to synchronize the
00:09:14.079 shared mutable data or objects between
00:09:17.959 threads so we cannot uh if we if we
00:09:23.399 manipulate any objects without
00:09:26.480 synchronization the program will be
00:09:29.880 crushed or something critical
00:09:34.600 issues on threats on on on a SL system
00:09:39.240 it is very easy to share an object and
00:09:42.920 it is hard to trace furthermore if we
00:09:47.079 use many many libraries so we we should
00:09:50.519 we couldn't read any Li which Library
00:09:54.360 mutates the data or something like
00:09:57.079 that so it is same on she Ru concurrent
00:10:01.480 threats so previous I presentation say
00:10:06.200 that the GBL doesn't uh protect your
00:10:11.800 application but the context switch point
00:10:14.399 is very limited so it is uh easier than
00:10:19.120 the the the uh uh the parall
00:10:23.640 Computing so the diff so degree of if we
00:10:28.200 uh show the degree of the uh difficulty
00:10:31.279 of programming so the par programing is
00:10:33.959 most uh difficult and the the program is
00:10:38.839 very most easy so it is more easier than
00:10:43.560 the than par programming the the current
00:10:47.120 CB thre is uh with GBL is uh easier than
00:10:52.360 parallel programming I
00:10:54.680 think so this figure this page is quoted
00:11:00.279 from their uh their famous why threats
00:11:04.800 are but idea presentation by a famous
00:11:11.760 Professor so he he says that the thre
00:11:15.720 programming only by
00:11:18.760 Wizards so 30 years so this presentation
00:11:22.000 is 30 years uh from 30 years ago so the
00:11:27.639 example is visual based
00:11:32.200 so maybe I think that Ruby is easier
00:11:37.079 than Visual Basic so maybe Ruby is here
00:11:41.800 same same as on the Visual Basic I think
00:11:45.560 anyway so I think the so the threat
00:11:50.200 programming is uh should should not be
00:11:53.560 allowed uh anymore I think for the uh so
00:11:57.600 easy programming
00:12:01.240 and also uh
00:12:03.639 the I have another uh reason why we
00:12:08.720 introduce GBL so we want to keep the
00:12:12.959 quality of The
00:12:15.199 Interpreter so so sh doesn't allow to
00:12:19.000 stop by the critical error so
00:12:22.360 segmentation for for example so if you
00:12:24.839 see the segmentation for there it will
00:12:27.959 it should be a interpreters bug not for
00:12:31.639 not of the your applications
00:12:34.320 bug so to to keep this uh condition so
00:12:39.560 accessing all of mutable objects
00:12:41.720 shouldn't should should be threat safe
00:12:44.519 for example the array hash or string so
00:12:48.680 basic data structure l in C should be
00:12:52.440 protected by the some kind of uh fine
00:12:56.519 grain uh mutex or something like
00:12:59.680 that so thanks to the GBL we don't need
00:13:03.519 to care because the GBL protects all of
00:13:10.279 them so Ruby is open source software and
00:13:14.440 the developer is limited so the
00:13:17.959 productivity of the Ruby interpreter is
00:13:21.120 very important for
00:13:23.040 us so recently the Shopify uh Shopify
00:13:27.800 provide many Developers so the situation
00:13:31.240 is some maybe changed but maybe this
00:13:36.800 productivity is important the the this
00:13:41.000 kind of the importance is not changed I
00:13:43.920 think and also we there another uh
00:13:48.800 concern is the
00:13:51.000 performance so the introducing such a
00:13:54.720 slight safety uh locking or
00:13:57.759 synchronization need there many many
00:14:01.040 overheads so I think the the current so
00:14:06.720 GB is
00:14:08.600 most uh fast fastest way I think so by
00:14:13.720 the way the recent P recently python
00:14:17.440 Community decided to tackle to to
00:14:21.519 release the Gil Global interpret Lo uh
00:14:26.800 so such a difficult issues so I respect
00:14:30.360 the this decision and I'm looking
00:14:32.519 forward to see the conclusion on this
00:14:38.680 trial so back to the the uh background
00:14:44.480 of the parall programming why the parall
00:14:48.000 programming is difficult so difficulty
00:14:50.600 is come from the shared mutable
00:14:54.680 objects so shared M so if we don't have
00:14:58.399 a shared mutable object between SLS so
00:15:01.839 the we are happy to make parall
00:15:06.160 programs so how to solve this one uh
00:15:11.560 this issue so there are many many idea
00:15:15.000 so for example so prohibits the mutable
00:15:17.880 data mutable
00:15:19.800 objects okay let's use the all or
00:15:24.320 Elixir or other functional program
00:15:27.759 languages okay
00:15:29.759 Trace by typing so type system can help
00:15:34.279 to avoid such a data uh so such a slight
00:15:38.759 safety
00:15:40.440 issues so you can use
00:15:43.680 last another idea is a manage or M so
00:15:47.839 mut all of mut mutation can be uh
00:15:52.600 protected with uh transaction memory
00:15:56.680 then you can use a cruiser
00:15:59.880 langage so Trace mutation ends looking
00:16:03.160 by tooling so some deer or something
00:16:05.920 like that so you can use just Kuran so
00:16:09.720 thre sanitizer or or something similar
00:16:14.880 tools or so prohibiting prohibits
00:16:19.480 sharing
00:16:21.639 data so you can use the for forking the
00:16:26.399 process or microservices D or failed mbn
00:16:32.920 projects so there are many many ideas
00:16:36.199 but there it
00:16:38.440 is difficult to introduce then into Ruby
00:16:43.160 for example so if if M so at the keynote
00:16:49.519 if must say oh let's prohibit the
00:16:52.880 mutation for example if we we cannot
00:16:57.560 assign any instance
00:17:00.759 variables maybe
00:17:03.640 mat has many many so cranes I
00:17:08.120 think so there our uh choice is the
00:17:13.199 separat shareable and unshareable object
00:17:16.000 carefully so this is a
00:17:18.439 Lor so we introduce uh the Lor as
00:17:23.880 isolated object space so objects uh can
00:17:28.960 not access to the other rors
00:17:32.039 basically and uh so it means that most
00:17:36.880 objects are
00:17:39.760 unshareable and some we introduce some
00:17:42.640 sharable objects such as immutable
00:17:46.160 objects or classes and modules or
00:17:50.840 special other cared objects so in this
00:17:55.480 uh trick we can only focus on the shared
00:18:00.559 objects sharable objects to protect uh
00:18:04.880 care
00:18:09.600 carefully but
00:18:15.480 so if we separate the object space but
00:18:19.240 sometimes we want to share the state for
00:18:21.960 example the we want so this is a s
00:18:25.400 simplest example so
00:18:29.559 they want so if we want to count some uh
00:18:33.360 tasks how many tasks are all done then
00:18:37.640 so with the thre it is easy to share the
00:18:40.640 this count local
00:18:43.760 variable with this kind of data uh this
00:18:47.120 kind of pro program uh please note that
00:18:50.480 this count doesn't have in loing system
00:18:54.320 so this program is not a complete one so
00:18:58.240 this is why it is the the threat
00:19:00.520 programming is difficult
00:19:03.120 anyway so on the rure system so we have
00:19:07.600 maybe three
00:19:09.559 options so the simplest way so easiest
00:19:13.760 way is to use the external database for
00:19:16.760 example the relational database L this
00:19:20.480 or file system or something like that
00:19:25.280 so another one is using the actual or
00:19:28.400 transac
00:19:29.240 variable so I want to introduce two and
00:19:32.840 three so we use we can enclose uh the
00:19:36.679 state to the the one lecture and uh
00:19:40.799 worker access uh ask to increment them
00:19:44.799 and the main rter uh ask to get the
00:19:48.720 counter value and the value will be
00:19:52.320 returned to the main Lor with this kind
00:19:55.240 of leor programs so this is a very uh
00:20:00.280 simple way to make ACTA style
00:20:05.000 programs so another one is uh using the
00:20:08.640 transactional variable so transactional
00:20:12.080 uh the was transactional is come from
00:20:15.320 database and research from software
00:20:17.840 transaction memory so there I eliminates
00:20:22.480 the details with we can use this
00:20:25.360 transaction variable like uh with uh
00:20:28.960 this
00:20:30.520 gem like that so with the transaction
00:20:34.679 memory or variable we can we can share
00:20:38.320 with the uh share the state with rors
00:20:43.120 multiple rors with safety
00:20:47.559 way so this is current so the ideas of L
00:20:54.240 so I want to show the the kind
00:20:57.120 station so good news is that of course
00:21:00.400 the Loa was released with rby zero so
00:21:05.000 maybe four years about four years ago
00:21:08.240 and lo the support uh
00:21:10.120 so the back G I wrote is aim to uh
00:21:15.880 support lter and the M threats for
00:21:19.200 lightweight lter and thre creation
00:21:21.640 technique is was
00:21:23.279 introduced last year and the few few
00:21:27.000 usage reports which achieves the
00:21:29.799 performance improvements and more the
00:21:33.520 bad news is is the RO so de Jam doesn't
00:21:37.520 support the lcta yet and administrate uh
00:21:41.559 does it wasn't tuned for the ler more
00:21:46.559 and only a few only few usage
00:21:49.799 reports uh are
00:21:52.720 there so maybe
00:21:55.320 because so there are many many reasons
00:21:58.640 but the the the most uh biggest issue is
00:22:02.880 ecosystem is not grown with
00:22:06.760 rter so for example so to to uh achieve
00:22:13.880 the uh the
00:22:16.960 isolated object space we introduce some
00:22:19.720 many limitation to the the Luby language
00:22:23.440 so we need to rely to existence existing
00:22:27.679 libraries and for example the L doesn't
00:22:31.600 work with lus so maybe we need a huge
00:22:35.240 effort to run lays on laus in par I
00:22:40.240 think and for example another the
00:22:44.240 simplest example we cannot learn on lcta
00:22:47.720 is the here so it doesn't work on the
00:22:54.120 Luby
00:22:55.440 3.3 because the P PP call require the pp
00:23:03.320 library and after that the require is
00:23:07.159 not allowed on the uh non main
00:23:10.919 lectors so this is
00:23:13.159 problem and another Pro problem is uh
00:23:17.840 the
00:23:19.919 performance so I don't show the details
00:23:23.679 but the this disabled G disabled station
00:23:28.679 we can see we can check we can get uh
00:23:33.039 good
00:23:33.880 performance however if we enable the
00:23:38.000 garbage corlection so their performance
00:23:41.480 is very
00:23:42.840 very very very slow through with garbage
00:23:46.760 correction so this is uh so not tune so
00:23:51.159 rcta is not tuned for the garbage
00:23:53.320 correction so this is big problem to
00:23:57.600 introduce the the L to the produ your
00:24:01.919 production so we have many issues and we
00:24:04.760 need to improve step by
00:24:08.039 step so there uh there Ruby
00:24:13.440 3.4
00:24:15.799 uh I want to introduce some
00:24:21.520 features
00:24:24.720 uh by the way so this is off topic so
00:24:28.480 Luby
00:24:30.120 3.4 uh introdu uh un use block warning
00:24:35.240 so maybe somebody write this kind of
00:24:38.240 program like that so the method who with
00:24:42.399 broke but if we want to show the result
00:24:46.480 of the this methods then the this
00:24:51.960 block is uh passed to the method
00:24:56.159 P accidentally
00:24:58.799 so this kind so we introduce a new
00:25:04.880 warning so for example the this method
00:25:07.919 who doesn't accept any block and passing
00:25:11.840 the the block then warning their uh
00:25:15.399 warning this kind this one with uh High
00:25:19.880 dasw uh
00:25:24.159 option anyway so back to the Lor talk so
00:25:31.399 PP is a good example we need to
00:25:34.320 introduce a li support the Lor require
00:25:38.440 on another Ras so and also the out road
00:25:42.720 is also a good
00:25:45.919 example so
00:25:49.320 we achieve the uh the L on lur on Luby
00:25:55.559 3.3 or 3.4
00:25:58.600 uh with the uh es main L to the CER and
00:26:03.600 wait the
00:26:04.840 result like that so if the child doctor
00:26:09.440 Le require then ask to the main doctor
00:26:13.360 to make a new thread to
00:26:16.760 require and the require on this thread
00:26:20.799 in Main rure and the back to the uh the
00:26:26.480 original so child RoR
00:26:29.159 return Returns the result requires
00:26:32.039 result and restarts the program
00:26:37.080 here and this
00:26:41.120 lcore require method is called with the
00:26:45.840 this Anonymous
00:26:48.320 prepended
00:26:50.080 module so you don't need to care about
00:26:54.120 uh the this one so you only need to
00:26:57.919 reest
00:26:58.960 as
00:27:00.080 usual and the uh under uh underscore
00:27:05.279 Lian method will be
00:27:12.640 invoked after that uh so another topic
00:27:15.960 is this is not uh implemented yet but
00:27:20.159 maybe time out uh Library will support
00:27:23.480 rure so there uh don't uh
00:27:28.679 net net net HTTP Library can works fine
00:27:32.960 on
00:27:34.279 lures another uh there are another uh
00:27:38.600 new new features on Ruby
00:27:42.240 3.4 for example the thre
00:27:48.039 supports and
00:27:53.320 there so in
00:27:56.320 future so there are many many things we
00:27:59.399 want to uh improve whether uh the the
00:28:04.440 ler a uh GC tuning is maybe
00:28:12.880 most most important thing I think so the
00:28:18.399 so
00:28:19.960 previous uh pre on previous talk the
00:28:23.200 iall propos that the parallel garbage
00:28:25.880 collection or something like that so the
00:28:28.120 if we introduce the Lor local garbage
00:28:31.120 correction so each Lor can uh the
00:28:35.399 garbage corlection in each RoR so uh it
00:28:38.200 means that's a parallel uh garbage
00:28:40.960 collection so I want to try so we tried
00:28:44.240 this Al this uh implementation in four
00:28:48.279 years but it is not implemented yet so
00:28:52.080 next year next year I want to I want to
00:28:55.480 achieve that so anyway
00:29:00.480 so I introduced as many uh philosophy
00:29:04.559 and their uh background of the lecture
00:29:07.640 and show the current situation and
00:29:11.080 what's new on 3.4 and F more future so
00:29:18.320 thank you so much
Explore all talks recorded at RubyConf 2024
+64