Performance optimizations in Analysis Request creation #237
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.
This Pull Request contains very small changes, but it makes ~185 analyses from a Profile or Template get populated in less than 3s in AR Add form, even with the creation of 4 Analysis Request at once. With this PR, a delay because of BatchUID reindexing on analyses has been fixed too. As a result, the process of creation of an Analysis Request is significantly faster than before:
For these numbers, a laptop has been used, with a standalone instance, started in fg mode and with other applications (email, firefox, openoffice and PyCharm) running, so the numbers should be better in a dedicated server with an instance with zeo mode.
Breakdown of processes that take more than 1s during the creation of an AR with 94 analyses:
a) Submission of form: ~15s
b) Transition of AR to sampled : ~8s
c) Transition of AR to sample_due: ~8s
The most time-consuming task is the creation of the AR by using the
ar.processForm(REQUEST=request, values=values)
https://github.com/naralabs/bika.lims/blob/d827845190fd78ba55fe2359dee73152ae61cfb7/bika/lims/utils/analysisrequest.py#L75, but don't think there is too much room for improvement here unless we remove fields from the Schema and ensure there is no Created/ModifiedEventHandlers that makes the system to be slow. In any case, worth to review in detail.Regarding transitions, there is still window for improvement, specially because the Analysis Request object (as well as Sample, Partitions and Analyses) needs to be transitioned several times (sample_received -> sampled -> sample_received) before reaching the desired state. There is some overhead because of transitions cascading and promotion, and there is work going on to address these shortcomings already.