Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-25890

Pages are slow under high load because of contention on the async renderer cache

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Major
    • None
    • 10.11.5
    • Rendering - Async
    • 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

          Activity

            People

              MichaelHamann Michael Hamann
              MichaelHamann Michael Hamann
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: