Wednesday, May 14, 2014

How to find component load time on a page in CQ

Use Case: Your page is loading slow and you want to know which component in a page is slow in render

Solution: You can use CQ timing info to get that data. timing load uses resource dumper https://sling.apache.org/apidocs/sling5/org/apache/sling/api/request/RequestProgressTracker.html to track load time of each jsp within page.

To enable debugging

version <= CQ5.6.1

1) Go to /libs/foundation/components/timing/timing.jsp through CRXDE light and comment following like of code

//uncomment the following to get more timing details in the page
out.println("\nRaw RequestProgressTracker data:");
StringBuilder mb = new StringBuilder();
Iterator<String> it = t.getMessages();
while(it.hasNext()) {
    mb.append(it.next());
}
out.print(mb.toString());
out.println("\nChartData dump:");
for(ChartBar d : chartData) {
    out.print(d.start);
    out.print(' ');
    out.print(d.fullname);
    out.print(" (");
    out.print(d.elapsed);
    out.println("ms)");
}

2) Make sure that timing.jsp is included in your global template using

<cq:include path="timing" resourceType="foundation/components/timing"/>

3) Load your page and do view source

4) Scroll down to bottom of page where you will see google chart URL



5) Copy that URL and paste it in browser to get timing info



CQ > 6

CQ 6 has this feature OOTB



Notes: Please also read http://dev.day.com/docs/en/cq/current/deploying/monitoring_and_maintaining.html to see how you can analyze request log to find page load time on server side. This is also very useful to find any thread contention issues wither using thread dump or session dump from felix console.

On client side there are different products you can use (I don't have preference) (AppDynamic, New Relic, Google Page Speed, Google Analytics etc) to find client side load time.

5 comments:

  1. Great writeup. We will promote this.

    ReplyDelete
  2. I am unable to see timing URL. Basically I am having confusion. Above it is written that 'Make sure that timing.jsp is included in your global template using'.
    By 'global template' you mean global.jsp, if yes then this thing is making issue for me i.e. at the end of global.jsp I have added this
    '' right next to ''.
    But unfortunately I am getting exception when I load my page in browser i.e. 'Cannot serve request to /cf in /libs/foundation/components/timing/timing.jsp' and in stacktrace I see 'org.apache.sling.api.SlingException'

    ReplyDelete
  3. I am unable to see timing URL. Basically I am having confusion. Above it is written that 'Make sure that timing.jsp is included in your global template using'.
    By 'global template' you mean global.jsp, if yes then this thing is making issue for me i.e. at the end of global.jsp I have added this
    '' right next to ''.
    But unfortunately I am getting exception when I load my page in browser i.e. 'Cannot serve request to /cf in /libs/foundation/components/timing/timing.jsp' and in stacktrace I see 'org.apache.sling.api.SlingException'

    ReplyDelete
  4. I am sorry but I am unable to wrote the markup code, the cq:include one

    ReplyDelete
  5. The Post seems to be good i really gather lot of information from the post thanks for sharing this awesome post...
    website load

    ReplyDelete