Details
-
Improvement
-
Resolution: Unresolved
-
Major
-
None
-
10.11.5
-
Unknown
-
Description
Under high load, requests that display cached asynchronous content (panels, UI extensions, wiki macros with "Cached" enabled) wait for each other, and pages become very slow even though most of this content is already in the cache.
Observed
During a load spike on xwiki.org (XWiki 18.4.x, CPU saturated), a Glowroot profile of the home page showed about 25% of the request time parked in DefaultAsyncRendererExecutor.render, on the read lock of AsyncRendererCache. Across all requests of the node, 16,759 samples were parked on this read lock and 843 were waiting for its write lock, with almost nothing running inside the locked code.
Cause
AsyncRendererCache has a single ReentrantReadWriteLock for the whole JVM:
- every cache lookup takes the read lock, and on a hit also replays the skin extensions under it;
- starting an asynchronous job, and storing any result (put), take the write lock.
Once a writer is queued, every new reader parks behind it, so each cache miss anywhere on the instance stalls every request that displays cached content. Under CPU saturation, lock holders get descheduled and the queues grow.
The lock was added for XWIKI-16116. It prevents a client id that is registered after put has copied the job's clients from never being stored in the async cache. That race is per job and doesn't need a global lock. The lock doesn't order put against invalidations: the cleanCache* methods don't take it.
Proposal
The same approach as XWIKI-22979 for the security cache:
- Remove the read lock from the cache hit path. Make the result of AsyncRendererJobStatus volatile and set it last in AsyncRendererJob, so a status with a result also has its uses.
- Register clients per status: a client added after its status was stored is put in the async cache directly. Job starts and put then need no global lock. This also fixes XWIKI-25273.
- Update the reference, role and right mappings atomically (compute/computeIfPresent).
- Remove AsyncRendererCache#getLock() (internal).
Possible follow-ups:
- Start a single job when several requests miss the same key at the same time.
- An invalidation counter, so that a result computed while a document it uses is being modified isn't cached stale.
- A larger default size for the rendering.asyncrenderer.long cache (100 entries, which can be changed in the Infinispan configuration). The cost of the invalidation code with many more entries needs to be checked first: for example, invalidating a wiki iterates over all the reference mappings.
Attachments
Issue Links
- is related to
-
XCOMMONS-3937 Concurrent requests block each other when resolving entity references
-
- Open
-
-
XWIKI-25889 Displaying the page authors footer and the tips panel blocks other requests under high load
-
- Open
-
- relates to
-
XWIKI-25273 A forced asynchronous placeholder for an already rendered result cannot be resolved
-
- Open
-
-
XWIKI-22979 Access to pages is slow under high load on the security cache
-
- Closed
-
-
XWIKI-16116 Asynchronous panels randomly broken
-
- Closed
-