Release GVL during routing solves when no Ruby transit callbacks are registered#83
Open
erickreutz wants to merge 1 commit into
Open
Release GVL during routing solves when no Ruby transit callbacks are registered#83erickreutz wants to merge 1 commit into
erickreutz wants to merge 1 commit into
Conversation
Ruby-proc transit callbacks re-enter Ruby mid-search, so the solve bindings hold the GVL. Models built purely from transit matrices and vectors never call back into Ruby; for those, wrap SolveWithParameters and SolveFromAssignmentWithParameters in rb_thread_call_without_gvl so long solves stop blocking every other thread in the process. Tracking lives in RoutingModel Ruby wrappers: registering a Ruby transit callback keeps solves on the GVL-holding path. Public API is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Routing solves currently hold the GVL for their full duration, so in multi-threaded processes (Sidekiq, Puma) a solve with
time_limit = 3freezes every other Ruby thread for 3 seconds.This releases the GVL around
SolveWithParameters/SolveFromAssignmentWithParametersviarb_thread_call_without_gvl, but only when the model has no Ruby transit callbacks registered. Procs registered throughregister_transit_callback/register_unary_transit_callbackare re-entered by the search constantly, so those models keep the GVL and behave exactly as today. Models built fromregister_transit_matrix/register_unary_transit_vectorand the other native registrations never re-enter Ruby during the solve, so releasing is safe: input data is copied into the model at registration, and the returnedAssignment*is model-owned and only read after the GVL is reacquired.Implementation: the C++ bindings become
_solve_with_parameters(params, release_gvl)and_solve_from_assignment_with_parameters(assignment, params, release_gvl); the Ruby side keeps the existing public API and passesrelease_gvlunless a Ruby callback was registered (the two callback registration methods set a flag and delegate to the renamed bindings, sokeepAlivesemantics are unchanged).Tests: a background thread keeps running during a matrix-model solve (GVL released), callback models still solve correctly (GVL kept), matrix and callback models produce identical objectives, and
solve_from_assignment_with_parametersgets the same coverage.