-
Notifications
You must be signed in to change notification settings - Fork 111
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
FM2-642: Improve performance of loading locations by tag #547
Conversation
Thanks, @ibacher. Any work on performance is highly appreciated. Thanks for the clear description of the implementation approach |
I have no idea why the tests are failing here... they pass locally in every way I can figure out how to run them. |
@ibacher Thanks for this PR and the detailed description. Here's some feedback from my local tests. The above changes have introduced a significantly high initial loading time for the module in my instance whenever it's run alongside the event module (tried 2.8.0 to 2.10.0). My 8GB M1 Mac laptop did not succeed in loading the module at all. See the error below:
Reverting to the previous commit restores the initial(normal) loading time. |
Description of what I changed
As we know, the FHIR Location end point is quite a bit slower than it ought to be. Based on the profiling of individual requests, I thought most of this overhead was just the overhead of translating to FHIR. However, our new performance test suite convinced me otherwise since it shows a median response time of 5 seconds for loading 50 locations (the minimum response time of 132ms is closer to the overhead I expected).
As a result I did some extensive profiling of the locations search request which pointed to two relatively easy-to-fix hotspots:
For the first of these I made the following optimizations:
For the second of these, directly invoking
getMessage(String, Object[], Locale)
is about 50% faster than invokinggetMessage()
, which seems to be due to Spring overhead. While individually this doesn't mean much, across millions of invocations of thegetMetadataTranslation()
method, it shaves a substantial portion of time.Between these two optimizations, I reduced the time to make 1 million search requests for locations by tag from 25 minutes to about 4 minutes, so this hopefully represents a serious improvement in perceptible performance.
Additionally, while doing this, I noticed that it was actually common (in the various tests) to wind up with multiple copies of FhirContext objects. FhirContext objects are extremely expensive to construct, so I've switched things up so we should only end up with at-most two FhirContexts (one for R4, one for DSTU3), which should speed up the time it takes for tests to run and may have a small impact on runtime performance in the real world too.
Outstanding work:
Issue I worked on
see https://openmrs.atlassian.net/browse/FM2-642
Checklist: I completed these to help reviewers :)
My IDE is configured to follow the code style of this project.
No? Unsure? -> configure your IDE, format the code and add the changes with
git add . && git commit --amend
I have added tests to cover my changes. (If you refactored
existing code that was well tested you do not have to add tests)
No? -> write tests and add them to this commit
git add . && git commit --amend
I ran
mvn clean package
right before creating this pull request andadded all formatting changes to my commit.
No? -> execute above command
All new and existing tests passed.
No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.
My pull request is based on the latest changes of the master branch.
No? Unsure? -> execute command
git pull --rebase upstream master