-
Notifications
You must be signed in to change notification settings - Fork 14
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
BHoM_Engine: ThreadStatic attribute taken off the debug log and replaced by a lock #2750
Conversation
@pawelbaran to confirm, the following checks are now queued:
|
@BHoMBot check compliance |
@pawelbaran to confirm, the following checks are now queued:
|
@pawelbaran to confirm, the following checks are now queued:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy with the solution.
Agreed that it is best to keep things simple and leave the log where it is for now.
@BHoMBot check ready-to-merge |
@pawelbaran to confirm, the following checks are now queued:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. All instances using the m_DebugLog
or calling the DebugLog()
method are protected with the same lock.
Looks safe to me as long as the DebugLog()
method stays internal as stated in the PR description by @pawelbaran .
In terms of testing, could be done with a dummy method with a Parallel.ForEach or similar simply raising tons of events and making sure no race conditions occurs. From the code side I can not see that being an issue, but ofc, good to test before merging.
Thanks @adecler @IsakNaslundBh. Following the request, I am pasting the code that I have used to (simply) test the feature, with positive results: int errorCount = 10000;
BH.Engine.Base.Compute.ClearCurrentEvents();
Parallel.ForEach(Enumerable.Range(0, errorCount), i => { BH.Engine.Base.Compute.RecordError($"Error no. {i + 1}"); });
var errors = BH.Engine.Base.Query.CurrentEvents();
foreach (var e in errors)
{
Console.WriteLine(e.Message);
}
Console.WriteLine($"\nTotal error count: {BH.Engine.Base.Query.CurrentEvents().Count}, test finished with result: {errors.Count == errorCount}");
BH.Engine.Base.Compute.ClearCurrentEvents(); I will merge the PR now, thanks all 👍 |
Issues addressed by this PR
Closes #2009
Closes #2745
Test files
Not sure how to test it meaningfully - the code still works as previously and does not show any signs of issues. I think that the best way of tasting can be simply merging the change and watching the logs carefully for the coming 2 sprint to make sure that this does not break anything.
Changelog
Additional comments
The approach taken has been discussed with @IsakNaslundBh: it seems to deliver best value for price:
Global
, so it can be used across the entire projectQuery.DebugLog
has already beeninternal
so there is no risk of the collection being modified from the outsideAn alternative that we discussed with @IsakNaslundBh was moving
BH.oM.Base.Debugging.Log
to the engine'sObjects
and encapsulating it properly. However, this would require more effort that does not seem to be justified for now.