Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: support for JRuby #127

Open
roque86 opened this issue Jun 11, 2024 · 2 comments
Open

Feature: support for JRuby #127

roque86 opened this issue Jun 11, 2024 · 2 comments

Comments

@roque86
Copy link

roque86 commented Jun 11, 2024

JRuby does not support forking, which is used here to spaw the rack server.

I have a draft fork where I just replaced processes for threads, and it seems to be working fine for JRuby.
Is there anything specific that would prevent us from using threads for JRuby and perhaps adapt the code to check for that and decide how to boot up the rack server accordingly?

@lucastosetto
Copy link
Collaborator

@roque86 I don't think modifying the default behavior to use threads in MRI Ruby is the way to go in order to support JRuby. In summary, we would probably face some issues, like:

MRI Ruby: Using threads is limited by the GIL, preventing true parallelism and leading to complex concurrency issues like race conditions and deadlocks.

JRuby: Although threads can run in parallel, shared memory still poses risks of memory corruption and harder debugging, with potential for resource contention and reduced isolation compared to processes.

I believe we could choose between:

  1. Support the threaded approach you suggested when using Rack in JRuby via a flag that needs to be explicitly configured by the developer.
  2. Use posix_spawn in JRuby by default, as described in this article.

@arturictus I'd love to hear your thoughts on this.

@roque86
Copy link
Author

roque86 commented Jun 26, 2024

Thanks for the feedback @lucastosetto.

Perhaps I was not clear enough with my initial comment but I was not really expecting or suggesting that the default behaviour would change to use threads instead of processes.

I was leaning towards detecting jruby and only then deciding on the use of threads.
My fork was only a proof of concept that shows that switching to threads in jruby is enough to "make everything work".

You made some general comments regarding the differences between processes and threads, but I was wondering if there was something more specific to the gem.

For now, I am using a variation of my fork in a project but I could contribute to the gem if the general idea is acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants