Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4485

New cacheKey is too expensive to create

    XMLWordPrintableJSON

    Details

      Description

      So we pushed ognl 3.0.10 to production this afternoon, and promptly had to rollback because load on the servers went through the roof. Looking at the stack traces, the issue was tons of threads doing this:

            at java.lang.Class.getEnclosingMethod0(Native Method)
            at java.lang.Class.getEnclosingMethodInfo(Class.java:1059)
            at java.lang.Class.isLocalOrAnonymousClass(Class.java:1449)
            at java.lang.Class.getCanonicalName(Class.java:1377)
            at ognl.OgnlRuntime.buildCacheKey(OgnlRuntime.java:1944)
            at ognl.OgnlRuntime.getGetMethod(OgnlRuntime.java:1926)
            at ognl.OgnlRuntime.hasGetMethod(OgnlRuntime.java:1985)
            at ognl.OgnlRuntime.hasGetProperty(OgnlRuntime.java:2045)
            at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.getProperty(CompoundRootAccessor.java:141)
      

      The problem is that the change to buildCacheKey() for https://issues.apache.org/jira/browse/WW-4113 is way to expensive considering how often it is called.

      I'd like to suggest replacing the current buildCacheKey() implementation with this:

          private static Object buildCacheKey(Class targetClass, String propertyName) {
              return new CacheKey(targetClass, propertyName);
          }
          
          private static final class CacheKey {
              private final Class clazz;
              private final String propertyName;
      
              public CacheKey(Class clazz, String propertyName) {
                  this.clazz = clazz;
                  this.propertyName = propertyName;
              }
              
              public boolean equals(Object obj) {
                  CacheKey cacheKey = (CacheKey) obj;
                  return clazz.equals(cacheKey.clazz)
                      && propertyName.equals(cacheKey.propertyName);
              }
              
              public int hashCode() {
                  return clazz.hashCode() * 31 + propertyName.hashCode();
              }
          }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                lukaszlenart Lukasz Lenart
                Reporter:
                perfnorm Jasper Rosenberg
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: