Skip to content

briefly defer yielding the thread/gvl around syscalls#15294

Closed
jpl-coconut wants to merge 3 commits into
ruby:masterfrom
jpl-coconut:deferred_thread_wait_master
Closed

briefly defer yielding the thread/gvl around syscalls#15294
jpl-coconut wants to merge 3 commits into
ruby:masterfrom
jpl-coconut:deferred_thread_wait_master

Conversation

@jpl-coconut

Copy link
Copy Markdown

This addresses Bug: 21685.

Details are in the issue. The following is a summary.

Before the fix:

  • The active thread drops the GVL and wakes another ready thread on each syscall.
  • This causes significant context swiching on real world applications (including rails).
  • As a result of the high rate of context switching, multicore machines may experience 10x worse performance on some benchmarks compared to single-core machines.

After the fix:

  • The active thread only drops the GVL after a syscall has been blocked for 100usec. This is achieved by adding an extra monitor thread (deferred_wait).
  • We see significantly less context switching on benchmarks (1000x less).
  • On those same benchmarks, single-core performance improves up to 2x and multi-core performance shows parity with single-core.

Following brief discussion on the issue I am creating this PR to further the discussion.

@jpl-coconut
jpl-coconut marked this pull request as draft November 23, 2025 05:14
@jpl-coconut
jpl-coconut force-pushed the deferred_thread_wait_master branch from 0beb0ee to 48d19a7 Compare December 4, 2025 06:44
@jpl-coconut

Copy link
Copy Markdown
Author

I think this is ready for review. I've taken the suggestion of @luke-gru and it now uses one thread per process, rather than one per ractor.

There is exactly one test failing (under multiple actions). That one is MultiIRBTest::test_irb_fg_jobs_and_kill_commands

I think updating the test in this case is better than trying to replicate the old behavior, but it's debatable. A simple test fix is here.

@jpl-coconut
jpl-coconut marked this pull request as ready for review December 4, 2025 17:01
@jpl-coconut

Copy link
Copy Markdown
Author

Closing in favor of a better approach

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

Successfully merging this pull request may close these issues.

1 participant