-
Notifications
You must be signed in to change notification settings - Fork 35
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
Bugfix in priority of put!/get of a resource #101
base: master
Are you sure you want to change the base?
Conversation
jvkerckh
commented
Oct 6, 2023
- put!/get (lock/unlock) requests for a resource are now handled in descending priority order, the same way as simulation events.
* put!/get (lock/unlock) requests for a resource are now handled in descending priority order, the same way as simulation events.
Is this the appropriate way to fix this? I am wondering because I imagine someone might be confused that |
I understand the concern here. What I did was take a look at the If preferred, I could implement it the way you suggest instead. |
I think we indeed should avoid changing the meaning of Do you mind adding a test that fails on the current master branch, showcasing what the bug is? I think it would be easier for me to comment after I see that. |
* Added a test that checks if put!/get requests are handled in order of descending priority, as requested by @Krastanov in the discussion of PR #101. This test will currently fail!
Test added to In the test, However, the test fails since |
Codecov Report
@@ Coverage Diff @@
## master #101 +/- ##
==========================================
- Coverage 97.15% 96.00% -1.16%
==========================================
Files 12 12
Lines 316 325 +9
==========================================
+ Hits 307 312 +5
- Misses 9 13 +4
📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
* Changed the implementation of the bugfix to priority handling for put!/get requests to avoid changing the meaning of `isless` as per the request of @Krastanov in PR JuliaDynamics#101.
Also changed the |
Apologies for my slowness in reviewing this, I have a few urgent responsibilities to deal with until Oct 28th -- I will review promptly afterwards |
Did you mean to merge the test on master? It seems there is already a change on the master branch related to this that has made the CI badge go red. |
I thought you meant that when you asked me "Do you mind adding a test that fails on the current master branch, showcasing what the bug is? I think it would be easier for me to comment after I see that." If not, my apologies for misunderstanding. |
My bad as well, I should have been clearer. I usually aim to have the master branch always green (it makes git bisect easier and it avoids other issues). I meant adding the test in this branch so it is isolated from the master branch but still visible in the PR CI. |
Any way to perform a roll back on that accidental/undesired change? |
No need, it is minor and this PR will be merged soon enough, taking care of it. |
Got around to actually reviewing and looking up the documentation of PriorityQueue and the notion of priority documented in this package, and it is actually a bit underdefined and I am getting confused. I could not find a piece of documentation or test code that actually imposes what is the "correct" priority ordering and how to use it. The word I have a couple of questions.
If in point 1 I am correct that there is no public API for simulation event priority (I am not sure of that), should we instead make the change there to ensure that we do not have "breaking change" issues as discussed in point 3? If I am correct about point 1, maybe we should also create a public API for simulation event priorities? |
Here is a toy I set up to try to understand how priorities for resources work: on master
The very first event seems wrong, but the other events seem correct, assuming ordering by ascending priority. Did I do something wrong here? on this PR
Here we have the same issue: the first event seems wrong, but then the ordering is correct, assuming sorting by decreasing priority. ConclusionI think there might be an unrelated problem with the priorities for resources (the first event being mistreated), but I think we should keep the ascending order in the resources priorities, because otherwise there would be a breaking change. If there is a public API for simulation event priorities, the way there is one for resources priorities, indeed we should make the two APIs match, and that is an unavoidable breaking change. But if there is no public API for simulation event priorities, maybe we can fix this mismatch in orders by changing the non-public one. Apologies for not investigating this earlier, before the previous round for discussions and prompting you to modify the PR -- I have not used the priorities functionality before and did not suspect how much I am missing. |
I'll try to answer both your posts in one go. Answers to questionsQuestion 1
That's correct, there is no public API for this. As far as I understand the code, this is because when an event is defined, it is immediately inserted into the priority queue of the simulation for simulation events, or in the appropriate priority queue of the resource for put!/lock and get/unlock events. Question 2
Correct on both counts. The A simulation event's priority is determined based on the following three criteria:
Since resource put!/get events don't have a time associated with them, only steps 2 and 3 need to be checked. This is the reason why the first iteration of this PR was the way it was. Question 3
Indeed. A very good point, which I had failed to consider. Question 4
Given that the PR as it is now will introduce potential breaking changes, this might indeed be desirable. In particular, I would suggest the following:
More changes might be needed to ensure 100% backwards compatibility, so this list of proposed changes isn't exhaustive. Uncovered priority issueYour toy problem revealed an issue that I haven't seen before, and it's a real puzzler. Also, no need to apologise for not investigating this earlier. If anyone should've noticed, it should've been me since I've been using SimJulia/ConcurrentSim for close to 7 years now, though never with resource put!/get priorities. SummaryGiven the fact that my proposed changes are breaking, I agree to not incorporate this PR in the master branch as it is now. Because of that, it might be wise to roll back the currently failing test that I (unwisely) included in the master branch. I'll definitely take another look at how resource events are scheduled to really understand what is going on there since it honestly makes no sense whatsoever at first glance. If desired, I can also look into the changes proposed in my answer to your 4th question. |
I've taken an in-depth look at what is happening in the example that you posted. After initialising the simulation and assigning the processes, but before
These events correspond to the processes as entered. Checking the resource shows that it has been initialised as it should be.
The first step of the simulation runs Using
which is as expected: the first event has been handled, and the
This is expected behaviour due to how
Linking back to the example, the If there's anything about this that is unclear still, please let me know. |
Thank you for the detailed explanation, this now makes a lot of sense! I will not be able to answer the various planning questions until next week, but in the meantime, I vote we keep the test you had added and just change it to |
Alright. Will you make the change to the test, or shall I? |
* Added an optional keyword argument, `highpriofirst` to Simulation, Container, Store, and their derivatives, so the user can select how they wish priorities to be handled (`true` for high to low, `false` otherwise). * Default for Simulation is `true`, default for Container and Store is `false` so as not to break existing code.
* Added the optional keyword argument to all methods and Resources derived from base Container and Store. * Added a line about the keyword argument in the docstring of Container and Store.
I've made the first two changes that I suggested a few posts back. A detailed overview of what's changed:
|
Thanks! I will plan to provide a review early next week. |
Apologies, this fell off my radar. This looks very near good to merge, but I have a few questions. Before merging though, could you share your thoughts on the following: Resource priorities have had a public API for a while and it is However, Simulation did not have a public API for priority ordering. This is making such an API public and it is defaulting to Given the lack of testing, I would suggest one of the following changes:
My reasoning is that I am scared of supporting functionality that does not have extremely thorough tests, especially one so basic (I would not be surprised if the ordering is used implicitly somewhere deep inside the internals of the library, leading to breackage). I think it makes sense to export the priority orderings you have defined. |
Hi, Johan! I will convert this back to draft, just to make it easier for me to track what I need to be reviewing among the handful of repos I work on. Please do not hesitate to convert it back to non-draft. |