Projects:Improve Org Session Cache&action=edit/Specs
Contents |
Introduction
The goal of this project is to improve scalability by reducing the memory used per session in Organization cache.
Measurements
In every operation performed in Openbravo, organization tree structure needs to be checked in order to guarantee correct access rules are applied, so it is cached in memory per session to improve performance.
Currently (3.0PR18Q1), the size of this cache depends on various factors:
- Number of organizations in the instance
- Number of accessible organizations by session's role
- Topology of the tree, in short: trees with deeper node hierarchies consume more memory than others which are more flattened.
In an instance with 600 organizations, a role with access to all of them would consume:
- Around 1MB if the org tree is flat, this is all the 600 organization have a single common ancestor node.
- Around 14MB for an extreme case where there are no sibling nodes being each organization ancestor of the rest.
Problems
These are the 3 problems that will be addressed in the scope of this project:
Redundant caches
Organization tree is cached in two different structures:
- OrgTree: which is pretty old and very rarely used. Was implemented in 2.50 and replaced in 3.0 by
- OrganizationStructureProvider
For the 600 organizations case, OrgTree consumes around 200KB per session. This cache should be completely removed, replacing the few uses of it with OrganizationStructureProvider.
Excessive caching
OrganizationStructureProvider caches natural trees and ascendant and descendant trees for every single organization in the tree.
If computation of ascendant and descendant trees is optimized, a single structure caching the whole tree definition could be cached this structure would replace current duplicates for each organization.
Note further improvement could be done if this common tree definition would be cached not per session but per system. The problem with this approach is how and when this cache should be invalidated in case of modifications in the tree structure, because of this complexities it will not be implemented for the moment:
- currently, tree structure is fixed at login time, in case tree structure is modified, those changes will not be seen until new log in, this is very simple to do having a cache per session, but much more difficult having a common one
- in clustered installations, there would be a cache per JVM, making much harder to invalidate caches in separate JVMs when structure is detected to be modified in one of them
Missing cache
Some attributes of the organization (such as flags to allow transactions on it) are not cached, so they are queried from DB every time they are going to be used. Adding those flags to a common cache per session, will not add a significant overhead in terms of consumed memory, but will reduce the number of queries required to make use of it.