Parsing with Ractors & Multiple Threads

30 views
Skip to first unread message

Keith Bennett

unread,
Feb 21, 2023, 3:12:21 AM2/21/23
to nokogiri-talk
I'm doing some simple XML parsing but would like to speed it up by using multiple CPU's. Can I use ractors to do this, or is there something about Nokogiri's design that would not support this?

Also, could I use multiple threads in JRuby (since JRuby uses multiple CPU's for its threads)?

Are there any other strategies you would recommend to accomplish this speedup?

Thanks,
Keith Bennett

Mike Dalessio

unread,
Feb 27, 2023, 9:34:02 AM2/27/23
to nokogi...@googlegroups.com
Hi Keith,

Great question. In theory libxml2 supports multiple threads, but only one-thread-per-document (that is, you can't have two threads modifying the same document at the same time). More info on libxml2l thread support here:


However, Nokogiri doesn't do a good job of releasing the GVL when it enters libxml2 functions, so Ruby threads won't get you very far. Ractors probably will allow you to do concurrent processing, though!

JRuby will definitely support multiple threads.

I'd love to hear what you learn and if you determine any good practices.

--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nokogiri-talk/cc2e7179-c4a7-4763-a590-b6ee2f0c25edn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages