<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Slow performance of Freemarker Templates in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/slow-performance-of-freemarker-templates/m-p/184300#M137430</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;again replying to my own post, but I found out something interesting, which might be a bug in freemarker (already inserted at &lt;/SPAN&gt;&lt;A href="http://sourceforge.net/tracker/index.php?func=detail&amp;amp;aid=2417204&amp;amp;group_id=794&amp;amp;atid=100794" rel="nofollow noopener noreferrer"&gt;http://sourceforge.net/tracker/index.php?func=detail&amp;amp;aid=2417204&amp;amp;group_id=794&amp;amp;atid=100794&lt;/A&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not too sure where the problem ist, but when I remove commentaries (which include other freemarker commands, like &amp;lt;#– &amp;lt;#return foo –&amp;gt;) and newlines out of my template, it runs significantly faster. But this problem bursts, when I try to access the same freemarker template with several HTTP clients at the same time. Then each template needs more time rendering (the time to&amp;nbsp; render increases with each parallel http request). This smells like some synchronization problem, but I cannot track this down for sure.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also wrote an own FreeMarkerProcessor.java class, which does not use any caching mechanism in order to sort this problem out - but it did not change anything.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope to get some feedback from the freemarker people, but if any of the developers might know some bottleneck in context of concurrency and parsing time (any synchronized parts during parsing/rendering), feel free to speak up, so we could try to sort this problem out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However I am now up to 20 requests per second, when there are more than two parallel connections, which is a fair value (but who knows, perhaps it can still be pushed). Two parallel connections might be handled by the Pentium4 CPU with Hyperthreading which it runs on (meaning two truly parallel running threads), so it might not be possible to be any quicker?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Alexander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Dec 2008 10:20:12 GMT</pubDate>
    <dc:creator>alr</dc:creator>
    <dc:date>2008-12-12T10:20:12Z</dc:date>
    <item>
      <title>Slow performance of Freemarker Templates</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/slow-performance-of-freemarker-templates/m-p/184296#M137426</link>
      <description>HelloI've run into a serious performance problem with my freemarker templates, when rendering a document. This is my szenario:1. One document, which has an association to seven other documents2. These seven documents each have associations to 1-3 other documents.Each association gets looked up and I</description>
      <pubDate>Thu, 20 Nov 2008 08:51:39 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/slow-performance-of-freemarker-templates/m-p/184296#M137426</guid>
      <dc:creator>alr</dc:creator>
      <dc:date>2008-11-20T08:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Slow performance of Freemarker Templates</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/slow-performance-of-freemarker-templates/m-p/184297#M137427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have made some advances in finding the bottleneck. The bottleneck was a self written function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&amp;lt;#function loadNode nodeID&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;#return companyhome.nodeByReference["workspace://SpacesStore/" + nodeID]&amp;gt;&lt;BR /&gt;&amp;lt;/#function&amp;gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;This function is incredibly slow. When rendering my freemarker template I am calling this function quite often. In my szenario I can be sure, that the data does not change anymore when it is accessed via this template. So the most simple solution is to create a cache. This is what I did, I implemented my own "getNodeFromCache" freeMarker function in Java, which caches classes from type "TemplateNode" in a HashMap. Here are some numbers to compare:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my test I call loadNode() with exactly the same node id several times (showing with the amount of iterations)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;10 iterations: 609 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;20 iterations: 1.141 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;50 iterations: 3.437 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;100 iterations: 5.890 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;250 iterations: 14.670 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;500 iterations: 30.543 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;750 iterations: 43.980 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1.000 iterations: 55.525 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2.000 iterations: 79.600 ms &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my second test I call my caching getNodeFromCache function, which looks up first in its own cache and if it is not found, it does the same lookup then companyhome.getNodeByReference()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;10 iterations: 0 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;20 iterations: 15 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;50 iterations: 31 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;100 iterations: 63 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;250 iterations: 156 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;500 iterations: 297 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;750 iterations: 437 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1.000 iterations: 594 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2.000 iterations: 1.250 ms&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This was the first of my found bottlenecks. I am now up to 7-9 requests per second (about 20 times faster than before), which is ok, but not yet good enough for my use case.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The next thing I would like to cache, is a call like &amp;lt;#include&amp;gt; (or at least implement some prerendering functionality), however this is a freemarker core call, so I am not sure, whether this is the way to go. The first thing I would like to know (as I have not found it yet in the source) is, why can you do something like&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&amp;lt;#include "workspace://SpacesStore/" + freeMarkerContainerTemplateID&amp;gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;This implies, that the include call is overwritten in the Alfresco Repository, as you are not able to use a NodeID by default, or? Any pointers in the right direction are appreciated. Thanks! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;–Alexander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2008 10:28:19 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/slow-performance-of-freemarker-templates/m-p/184297#M137427</guid>
      <dc:creator>alr</dc:creator>
      <dc:date>2008-11-25T10:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Slow performance of Freemarker Templates</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/slow-performance-of-freemarker-templates/m-p/184298#M137428</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a document report that iterates spaces. If this is run inline (to be renderd within the webclient) it takes about 30-45 seconds. If I call the template and shows it outside of the webclient it wil render in 5-10 seconds.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To do this I have a&amp;nbsp; fremarker template inline with links&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&amp;lt;a href="/alfresco/template/?templatePath=/Company%20Home/Data%20Dictionary/Presentation%20Templates/Document_Report.ftl&amp;amp;contextPath=${space.displayPath}/${space.properties.name}" target="_blank"&amp;nbsp; &amp;gt;Full document report&amp;lt;/a&amp;gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Clicking that link, and it will display a new window with only your freemarker output. Try this and see if you get the same performance improvement.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2008 10:56:41 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/slow-performance-of-freemarker-templates/m-p/184298#M137428</guid>
      <dc:creator>loftux</dc:creator>
      <dc:date>2008-11-25T10:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Slow performance of Freemarker Templates</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/slow-performance-of-freemarker-templates/m-p/184299#M137429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am already outside of the webclient and rendering my freemarker template with the GuestTemplateServlet calling like&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;&lt;A href="http://localhost:8080/alfresco/guestTemplate?templatePath=/Company%20Home/Data%20Dictionary/Presentation%20Templates/render_visual.ftl&amp;amp;contextPath=/Company%20Home/User%20Homes/my_visual.vis" rel="nofollow noopener noreferrer"&gt;http://localhost:8080/alfresco/guestTemplate?templatePath=/Company%20Home/Data%20Dictionary/Presentation%20Templates/render_visual.ftl&amp;amp;contextPath=/Company%20Home/User%20Homes/my_visual.vis&lt;/A&gt;&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;–Alexander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2008 12:17:24 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/slow-performance-of-freemarker-templates/m-p/184299#M137429</guid>
      <dc:creator>alr</dc:creator>
      <dc:date>2008-11-25T12:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Slow performance of Freemarker Templates</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/slow-performance-of-freemarker-templates/m-p/184300#M137430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;again replying to my own post, but I found out something interesting, which might be a bug in freemarker (already inserted at &lt;/SPAN&gt;&lt;A href="http://sourceforge.net/tracker/index.php?func=detail&amp;amp;aid=2417204&amp;amp;group_id=794&amp;amp;atid=100794" rel="nofollow noopener noreferrer"&gt;http://sourceforge.net/tracker/index.php?func=detail&amp;amp;aid=2417204&amp;amp;group_id=794&amp;amp;atid=100794&lt;/A&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not too sure where the problem ist, but when I remove commentaries (which include other freemarker commands, like &amp;lt;#– &amp;lt;#return foo –&amp;gt;) and newlines out of my template, it runs significantly faster. But this problem bursts, when I try to access the same freemarker template with several HTTP clients at the same time. Then each template needs more time rendering (the time to&amp;nbsp; render increases with each parallel http request). This smells like some synchronization problem, but I cannot track this down for sure.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also wrote an own FreeMarkerProcessor.java class, which does not use any caching mechanism in order to sort this problem out - but it did not change anything.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope to get some feedback from the freemarker people, but if any of the developers might know some bottleneck in context of concurrency and parsing time (any synchronized parts during parsing/rendering), feel free to speak up, so we could try to sort this problem out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However I am now up to 20 requests per second, when there are more than two parallel connections, which is a fair value (but who knows, perhaps it can still be pushed). Two parallel connections might be handled by the Pentium4 CPU with Hyperthreading which it runs on (meaning two truly parallel running threads), so it might not be possible to be any quicker?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Alexander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Dec 2008 10:20:12 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/slow-performance-of-freemarker-templates/m-p/184300#M137430</guid>
      <dc:creator>alr</dc:creator>
      <dc:date>2008-12-12T10:20:12Z</dc:date>
    </item>
  </channel>
</rss>

