In the current implementation of Cache in ballerina/cache, the cacheCleanupService is scheduled per Cache object. A global cache map is maintained to keep track of each Cache object created and the function for cleaning up expired cache entries cleans up each of the cache in this cache map. Since now cleanup tasks are scheduled per object using this same cleanup function, this leads to concurrent modification issues, with keys already being cleaned up by another task when one task tries to clear invalid cache entries.
Note - Creating a new task when creating a new a Cache is redundant. This will create lots of tasks which will affect the performance AFAIS. Ideally, one (global) task is enough to clean cache.
AFAIS, moving the timer creation, scheduling (https://github.com/ballerina-platform/ballerina-lang/blob/master/stdlib/cache/src/main/ballerina/src/cache/cache.bal#L74-L78) and starting (https://github.com/ballerina-platform/ballerina-lang/blob/master/stdlib/cache/src/main/ballerina/src/cache/cache.bal#L86) to the top level should solve this issue.
Hi Shan,
Yes, but the issue is that if we put the task creation to the top level,
the task will start running when we import the cache module. That also
affects the performance.
But we have to come to a conclusion here on what are we going to compromise
on.
On Mon, Aug 12, 2019 at 11:43 AM Shan Mahanama notifications@github.com
wrote:
Note - Creating a new task when creating a new a Cache is created is
redundant. This will create lots of tasks which will affect the performance
AFAIS. Ideally, one (global) task is enough to clean cache.AFAIS, moving the timer creation, scheduling (
https://github.com/ballerina-platform/ballerina-lang/blob/master/stdlib/cache/src/main/ballerina/src/cache/cache.bal#L74-L78)
and starting (
https://github.com/ballerina-platform/ballerina-lang/blob/master/stdlib/cache/src/main/ballerina/src/cache/cache.bal#L86)
to the top level should solve this issue.—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
https://github.com/ballerina-platform/ballerina-lang/issues/16703?email_source=notifications&email_token=AJRJROIGNFPNKTMRSNLUXW3QED5QLA5CNFSM4IDULAH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4BUNCY#issuecomment-520308363,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJRJROO227HHMKEJ3L5KMSTQED5QLANCNFSM4IDULAHQ
.
--
*Thisaru Guruge *| Software Engineer | WSO2 Inc.
(m) +94 71 720 9 720 | (e) [email protected]
https://wso2.com/signature