Uploaded image for project: 'JBoss Enterprise Application Platform 4 and 5'
  1. JBoss Enterprise Application Platform 4 and 5
  2. JBPAPP-4786

Performance risk: Incorrect synchronization in JBossWebMetaData.getRunAsIdentity

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • EAP_EWP 5.1.0_CR3
    • EAP 5.0.0
    • Web
    • None

      During a JNDI lookup test, it looks to me that in org.jboss.metadata.web.jboss.JBossWebMetaData there is a useless synchronization by runAsIdentity (marked by >>) since runAsIdentity is not touched by neither of the lines besides .put() method call.

      If the synchronization is only wrapping put() call, double calls to put() wont harm the behaviour (if roleName stays the same) but wont cause thread contention when runAs is null. It is responsible for roughly 9% of all thread contention (see attached graphs and data). Example patch attached.

      The proper synchronization should have also covered the initial runAsIdentity.get(servletName) so that there arent 2 threads heading into the put section but it is not performance-friendly.

      /**

      • Access the RunAsIdentity associated with the given servlet
      • @param servletName - the servlet-name from the web.xml
      • @return RunAsIdentity for the servet if one exists, null otherwise
        */
        @XmlTransient
        public RunAsIdentityMetaData getRunAsIdentity(String servletName)
        {
        RunAsIdentityMetaData identity = runAsIdentity.get(servletName);
        if (identity == null)
        {
        JBossServletsMetaData servlets = getServlets();
        if(servlets != null)
        {
        ServletMetaData servlet = servlets.get(servletName);
        if (servlet != null)
        {
        // Check for a web.xml run-as only specification
        >> synchronized (runAsIdentity)
        Unknown macro: { RunAsMetaData runAs = servlet.getRunAs(); if (runAs != null) { String roleName = runAs.getRoleName(); identity = new RunAsIdentityMetaData(roleName, null); runAsIdentity.put(servletName, identity); } }

        }
        }
        }
        return identity;
        }

        1. threads.png
          threads.png
          116 kB
        2. metadata.diff
          1 kB
        3. contention1.png
          contention1.png
          287 kB

              mmoyses Marcus Moyses (Inactive)
              rhn-engineering-rhusar Radoslav Husar
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: