Performance: Reduce use of synchronize collection for cache
Description
Environment
None
Activity
Show:
Heng Sin Low April 26, 2024 at 1:19 PM
hi @Carlos Ruiz , since you are hitting this issue, it should be easier for you to test and submit the PR.
Heng Sin Low April 26, 2024 at 12:39 PM
By right, key should never be null. Anyway, it is harmless to add that to CCache.get
Carlos Ruiz April 26, 2024 at 11:44 AM
Hi @Heng Sin Low
I think is because of this ticket that REST is throwing this error when executing the endpoint /api/v1/forms without parameters:
13:42:45.084===========> FormResourceImpl.getForms: Cannot invoke "Object.hashCode()" because "key" is null [182]
java.lang.NullPointerException: Cannot invoke "Object.hashCode()" because "key" is null
at java.base/java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
at com.github.benmanes.caffeine.cache.BoundedLocalCache.getIfPresent(BoundedLocalCache.java:2179)
at com.github.benmanes.caffeine.cache.BoundedLocalCache.get(BoundedLocalCache.java:2174)
at org.compiere.util.CCache.get(CCache.java:400)
at com.trekglobal.idempiere.rest.api.json.filter.DefaultQueryConverter.convertStatement(DefaultQueryConverter.java:55)
at com.trekglobal.idempiere.rest.api.v1.resource.impl.FormResourceImpl.getForms(FormResourceImpl.java:68)
Line 55 on REST is:
ConvertedQuery cache = convertCache.get(queryStatement);
and queryStatement is null, the fix in REST is easy, but as is not failing in release-11 I think the fix maybe must be on CCache.get to return null when the key is null?
WDYT?
Heng Sin Low April 1, 2024 at 8:30 AM
Remove use of synchronization in MUserDefInfo, MUserDefWin and MUserDefProc
Reduce the use of synchronize collection for cache should improve the performance of iDempiere in highly concurrent environment.
Changes:
CCache
Replace AtomicLong with LongAdder
Use ConcurrentHashMap for null list
CacheMgt
Use ConcurrentHashMap for local cache that is not using max size
AEnv
Use ConcurrentHashMap for session window cache
Remove expire and max size cache setting for the following:
GridTabVO
MAcctSchema
MClient
MClientInfo
MClientShare
MColumn
MCtxHelpMsg
MForm
MInfoWindow
MLanguage
MMenu
MOrg
MOrgInfo
MProcess
MRefList
MRefTable
MReference
MSysConfig
MSystem
MTab
MTable
MTableScriptValidator
MTableValRule
MWindow
MWFNode
MWorkflow
ThemeManager