Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-606

Velocity 1.5 performance bottlenecks

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.6
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      Win XP, 1 Gb, single core, Maven 2, JUnitPerf, JRat, cached Velocity templates with a ClassLoader

      Description

      I did some quite extensive profiling to identify performance bottlenecks in Velocity 1.5.

      Using Maven 2, JUnitPerf and JRat I was able to identify these methods as top bottlenecks:

      org.apache.velocity.util.introspection ClassMap - findMethod(String,Object[])
      org.apache.velocity.util.introspection IntrospectorBase - getMethod(Class,String,Object[])
      org.apache.velocity.runtime.parser.node SimpleNode - literal()
      org.apache.velocity.runtime.parser.node SimpleNode - render(InternalContextAdapter,Writer)
      org.apache.commons.collections ExtendedProperties - getBoolean(String,boolean)
      org.apache.velocity.runtime.parser.node ASTReference - render(InternalContextAdapter,Writer)

      The first two eat over 50% of the CPU with many threads. See attached screenshots.

      Interestingly enough the synchronized
      org.apache.velocity.runtime RuntimeInstance getTemplate(String,String)

      isn't a big problem when templates are cached. However, if all resources are not cached it becomes a serious performance bottleneck. ResourceCacheImpl also uses a synchronized map which slows things down.

      I think these bottlenecks could be at least made less worse by reducing synchronization by using ConcurrentHashMap and StringBuilder that ship with JDK 1.5. I'm investigating what kind of benefits could be achieved with those.

        Attachments

        1. velocity-1.5-250-threads-loadtest.PNG
          127 kB
          Jarkko Viinamäki
        2. velocity-1.5-50-threads-loadtest.PNG
          127 kB
          Jarkko Viinamäki
        3. VELOCITY-606-light.patch
          11 kB
          Nathan Bubna
        4. VELOCITY-606.patch
          21 kB
          Nathan Bubna
        5. velocity-1.6-dev-concurrentmods.patch
          26 kB
          Jarkko Viinamäki
        6. velocity-1.6-dev-concurrentpatch-250-threads-loadtest.PNG
          119 kB
          Jarkko Viinamäki
        7. velocity-1.6-head-20080725-test.vm.PNG
          116 kB
          Jarkko Viinamäki

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              wyla Jarkko Viinamäki
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: