Skip to content
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

Performance Loading Translations #5095

Merged

Conversation

thomaslow
Copy link
Collaborator

@thomaslow thomaslow commented Apr 27, 2022

Contributes to:

Translations are loaded using a java.util.ResourceBundle. In order to allow to customize translations by providing custom messages in the /usr/local/kitodo/messages directory, a CustomResourceBundle was already implemented, which first checks whether a corresponding file, e.g. messages_en.properties exists, and if it exists, uses that for translating messages.

In order to access property files outside of the current jar (meaning from the directory /usr/local/kitodo/messages), a new URLClassLoader was initizalized upon every call of getResourceBundle, see Line 91, and used to load the resource bundle.

Unfortunately, using a new URLClassLoader instance effectively disables caching of resource bundles. That means, upon every translation request, e.g., #{msgs.something}, the resource bundle was loaded again, potentially hundreds of times when displaying large process lists.

The proposed pull request changes the implemetation of CustomResourceBundle to initialize a URLClassLoader ideally only once during the lifetime of the webapp, such that resource bundles are fully cached.

With caching properly working, loading times improve significantly across all pages of Kitodo, e.g.:

  • Dashboard from 500ms to 350ms
  • List of 100 processes from 3100ms to 1400ms
  • Metadataeditor backend with 1000 pages from ~4000ms to ~2600ms

Potential problems

In order to pass all units tests, where property files are generated at runtime during the test, a fallback was added, which re-creates the URLClassLoader in case a resource bundle is not found. As a consequence, a Kitodo deployment which does provide a directory /usr/local/kitodo/messages/ but not include a required property file (resource bundle) will check for that resource bundle many times and suffer from the original performance drawbacks. This means:

  • either have no directory /usr/local/kitodo/messages/ (which causes all messages to be loaded from the jar)
  • or have a directory /usr/local/kitodo/messages/ that contains all required property files

If one property file or resource bundle is missing, the caching will be partially disabled again.
Alternatively, we need to update unit tests to not test resource bundles by dynamically creating property files during runtime.

Update 2022-05-03: Unit tests have been updated, which makes the previously suggested fallback obsolete. Resource bundles (property files) are now loaded upon first access. Changes to the property files requires a re-deployment of the web application to take effect.

thomaslow and others added 3 commits April 26, 2022 11:29
… translations is cached instead of being loaded upon every request.
…is required for successful unit testing, since resource directories are created temporarily during runtime.
thomaslow and others added 3 commits May 3, 2022 13:57
…undle loading. Remove fallback reload behavior in case external resource bundle is not found.
…le exists. Otherwise, wrong resource bundles are loaded in some circumstances during intergration tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants