-
Notifications
You must be signed in to change notification settings - Fork 91
Make SPICE kernel management reference counted #1180
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
base: develop
Are you sure you want to change the base?
Conversation
|
Assigned to @Mark2000 because I'll be out for a couple weeks. |
25d8959 to
627bf3f
Compare
627bf3f to
69a2114
Compare
|
Looks like the spice thread safety test is failing across various runners. |
I grabbed the test from an old PR from Nico, but instead of only doing two parallel workers I did 50. That's like 150 sims interacting with Spice at the same time. Clearly that's too much, and the mutex protection for loading (or unloading) doesn't really address it. If this PR performs well in bsk-rl (it doesnt introduce any of the errors you guys were observing with Niko's original PR), then I'd say this is not a complete solution but at least a positive step. Feel free to make changes to the branch and take over. |
|
Sure, so the failing test is to see if the PR is successfully addressing #220, and not reflecting a regression? If so, I think it makes sense to leave the test and mark it as skipped (or flakey) so that there's a reference for the desired but currently unsuccessful behavior. This PR does improve the performance of BSK-RL considerably, so as long as there are no regressions for other use cases I think we should go with this implementation. |
REQUIRED_KERNELS#1010, closes Spice makes BSK simulations not thread safe #220Description
This change refactors SPICE kernel lifetime management so that kernels are reference counted per canonical absolute file path instead of being repeatedly loaded and unloaded per simulation.
Key pieces:
SpiceKernel, an RAII helper that furnishes a kernel on construction and unloads it on destruction. Instances are cached in a staticstd::unordered_map<std::string, std::weak_ptr<SpiceKernel>>guarded by astd::mutex, so a given path is only furnished once per process and is unloaded when the last shared pointer goes out of scope.SpiceInterface::loadSpiceKernelandSpiceInterface::unloadSpiceKernelto useSpiceKernel::requestand a per interfaceloadedKernelsmap keyed by canonical absolute path, instead of callingfurnsh_corunload_cdirectly.SpiceInterface::clearKeeperin the header and via SWIG (%deprecated_function), documenting that it clears all kernels for the process and should be avoided in favor of automatic per interface cleanup.Verification
test_multipleInterfacesto construct many small simulations, each with its ownSpiceInterface, then verify that:gc.collect()runs, the kernel is no longer reported as loaded.test_spiceThreadSafetywhich:SpiceInterfaceinstances against a fixed data path, with a short sleep to increase contention.Documentation
bskReleaseNotes.rst.spiceInterface.handspiceInterface.cppforSpiceKernel,SpiceInterface::clearKeeper, and the new helper functions, to clarify lifetime semantics and deprecation status.SpiceInterface::clearKeeperas deprecated in the SWIG interface so Python users will receive a warning and updated guidance.Future work
These kinds of errors are very hard to catch consistently, so only experience will tell us if this actually addresses all user errors.