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

Reduce contention in heavy IO operations #7806

Merged
merged 4 commits into from May 30, 2023

Conversation

headius
Copy link
Member

@headius headius commented May 23, 2023

This moves the creation of a new selector outside of the sync section, to avoid blocking threads that are just trying to put a selector back when we are waiting to open a new one.

This whole class could use some improvement using nonblocking collections, but this should help reduce contention for now.

Edit: This has expanded to remove additional areas of contention.

See #7805.

This moves the creation of a new selector outside of the sync
section, to avoid blocking threads that are just trying to put a
selector back when we are waiting to open a new one.

This whole class could use some improvement using nonblocking
collections, but this should help reduce contention for now.

See jruby#7805.
@headius headius force-pushed the reduce_contention_selector_pool branch from 2c11bc1 to bea00c4 Compare May 23, 2023 16:18
@headius
Copy link
Member Author

headius commented May 23, 2023

I've pushed an additional commit that removes all locking from SelectorPool by using concurrent collections. If the contention is really due to locking in SelectorPool, this should definitely eliminate it.

@headius headius changed the title Reduce contention in the selector pool Reduce contention in heavy IO operations May 24, 2023
The data struct logic has used VariableTableManager and internal
variable logic for years, which is concurrency-safe. There's no
need for these to be synchronized.

Note that this code is not used many places, but notably all forms
of IO#each (like File#each, Socket#each) use it to support the
ARGF feature of Ruby, which is shared across threads. This showed
up as a point of contention after removing SelectorPool's excess
locking in jruby#7806, meant to address contention reported by LogStash
users in jruby#7805.
@headius
Copy link
Member Author

headius commented May 24, 2023

Additional commit to remove synchronization from RubyBasicObject.dataGetStruct/dataWrapStruct because they should not need it (they utilize VariableTableManager which is concurrency-safe).

The various forms of puts at the very least use the two-argument
form, which was falling through the varargs path and allocating
argument arrays. I add three-argument form for completeness.
@headius headius merged commit b5e2e3c into jruby:jruby-9.3 May 30, 2023
53 of 54 checks passed
@headius headius deleted the reduce_contention_selector_pool branch May 30, 2023 19:37
headius added a commit to headius/jruby that referenced this pull request May 30, 2023
The data struct logic has used VariableTableManager and internal
variable logic for years, which is concurrency-safe. There's no
need for these to be synchronized.

Note that this code is not used many places, but notably all forms
of IO#each (like File#each, Socket#each) use it to support the
ARGF feature of Ruby, which is shared across threads. This showed
up as a point of contention after removing SelectorPool's excess
locking in jruby#7806, meant to address contention reported by LogStash
users in jruby#7805.
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.

None yet

1 participant