[ 
https://issues.apache.org/jira/browse/WW-5121?focusedWorklogId=569580&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-569580
 ]

ASF GitHub Bot logged work on WW-5121:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Mar/21 08:47
            Start Date: 22/Mar/21 08:47
    Worklog Time Spent: 10m 
      Work Description: davoustp opened a new pull request #479:
URL: https://github.com/apache/struts/pull/479


   Fixes the contention issue described in WW-5121 by applying a 
double-null-check-with-volatile pattern to avoid the synchronized cost on each 
and every injection of the singleton.
   
   Same patch as #478 but against the Struts 2.5.x branch.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 569580)
    Time Spent: 20m  (was: 10m)

> Contention when injecting Scope.SINGLETON instances
> ---------------------------------------------------
>
>                 Key: WW-5121
>                 URL: https://issues.apache.org/jira/browse/WW-5121
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.5.20
>            Reporter: Pascal Davoust
>            Priority: Major
>             Fix For: 2.5.27, 2.6
>
>         Attachments: image-2021-03-22-09-13-03-703.png
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> The container injection (DI) mechanism shows high contention when injecting 
> {{Scope.SINGLETON}} instances under high stress load in an enterprise 
> application using Struts 2.5.20.
> The symptom is that UI response times vary from a few dozens of milliseconds 
> up to a full second without any obvious reason.
> Profiling the app while under load stress using 
> [https://github.com/jvm-profiling-tools/async-profiler] (using the {{lock}} 
> mode and {{--reverse}} option to aggregate on the various contention code 
> locations) shows the following picture:
> !image-2021-03-22-09-13-03-703.png|width=975,height=117!
> Analyzing the code path shows the highly contended code:
> {code:java}
>     SINGLETON {
>         @Override
>         <T> InternalFactory<? extends T> scopeFactory(Class<T> type, String 
> name, final InternalFactory<? extends T> factory) {
>             return new InternalFactory<T>() {
>                 T instance;
>                 public T create(InternalContext context) {
>                     synchronized (context.getContainer()) {
>                         if (instance == null) {
>                             instance = 
> InitializableFactory.wrapIfNeeded(factory).create(context);
>                         }
>                         return instance;
>                     }
>                 }
> ...
>     },{code}
> The fully {{synchronised}} section for accessing the singleton instance is 
> the core issue here.
>   
>  Using the double-null-check-on-volatile pattern (which I dislike but is 
> reliable since Java 1.5 with the {{volatile}} keyword) entirely removes the 
> contention issue and response times become much more stable.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to