Components each process twice

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Components each process twice

lancedolan
Through my years in Adobe CQ and AEM, I've noticed that LOG files from components that I write always render twice per page request. Today I was debugging my code in Sling 8 and noticed that My debugger was kicked open twice each time I requested a page instead of once.

What's the deal with this? It seems really common, you guys must all be familiar with it also?

It's dangerous because all components logic must be idempotent (imagine posting duplicate records to a database). And then obviously, it's bad for performance to do things twice unnecessarily.  

I've seen this so often on so many projects that I'm not really tempted to offer any steps to reproduce, you guys must be seeing this also right?

NOTE: The component is NOT included on the page more than once. This behavior will occur when a component is included only once.
Reply | Threaded
Open this post in threaded view
|

Re: Components each process twice

drfits
Can you please provide a small code example for this?

We've faced with similar behavior in our project (AEM 6.1, Sightly) but
it was according to "architecture" (components was rendered twice per
request) therefore I had to change it to single include.


On 02/02/2017 05:08 AM, lancedolan wrote:

> Through my years in Adobe CQ and AEM, I've noticed that LOG files from
> components that I write always render twice per page request. Today I was
> debugging my code in Sling 8 and noticed that My debugger was kicked open
> twice each time I requested a page instead of once.
>
> What's the deal with this? It seems really common, you guys must all be
> familiar with it also?
>
> It's dangerous because all components logic must be idempotent (imagine
> posting duplicate records to a database). And then obviously, it's bad for
> performance to do things twice unnecessarily.
>
> I've seen this so often on so many projects that I'm not really tempted to
> offer any steps to reproduce, you guys must be seeing this also right?
>
> NOTE: The component is NOT included on the page more than once. This
> behavior will occur when a component is included only once.
>
>
>
> --
> View this message in context: http://apache-sling.73963.n3.nabble.com/Components-each-process-twice-tp4070042.html
> Sent from the Sling - Users mailing list archive at Nabble.com.

--
With best regards
Evgeniy Fitsner

E-mail: [hidden email]
Skype: drfits
Phone: +375 29 5386858

Reply | Threaded
Open this post in threaded view
|

Re: Components each process twice

Carsten Ziegeler
In reply to this post by lancedolan
No, I've never seen this before, except when the component was really
called twice per request. Your mail is really very general and makes us
guess what you're talking about. Are these OSGi components, rendering
components, a script? Please be more specific.

Thanks
Carsten

Lancedolan wrote

> Through my years in Adobe CQ and AEM, I've noticed that LOG files from
> components that I write always render twice per page request. Today I was
> debugging my code in Sling 8 and noticed that My debugger was kicked open
> twice each time I requested a page instead of once.
>
> What's the deal with this? It seems really common, you guys must all be
> familiar with it also?
>
> It's dangerous because all components logic must be idempotent (imagine
> posting duplicate records to a database). And then obviously, it's bad for
> performance to do things twice unnecessarily.  
>
> I've seen this so often on so many projects that I'm not really tempted to
> offer any steps to reproduce, you guys must be seeing this also right?
>
> NOTE: The component is NOT included on the page more than once. This
> behavior will occur when a component is included only once.
>
>
>
> --
> View this message in context: http://apache-sling.73963.n3.nabble.com/Components-each-process-twice-tp4070042.html
> Sent from the Sling - Users mailing list archive at Nabble.com.
>


 

--
Carsten Ziegeler
Adobe Research Switzerland
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Components each process twice

lancedolan
This response is good enough for me. The fact that the community hasn't largely said "yea we see it all the time and it's normal" tells me I'm probably causing this myself somewhere, and I'll have to look into it. I just didn't want to lose a day figuring out the root cause if this was known normal sling behaviour, or that sometime it just needs to render a component twice to for its own reasons.

Curious that I've observed this on other projects from other devs - we must be falling for the same pitfall.
Reply | Threaded
Open this post in threaded view
|

Re: Components each process twice

naveenChoudhary
In reply to this post by drfits
Hi,
Can you please elaborate how you have resolved the problem as we are also facing the same.
AEM 6.1 sightly.

Thanks
Naveen
Reply | Threaded
Open this post in threaded view
|

Re: Components each process twice

Santiago García Pimentel
In reply to this post by lancedolan
Hello,

I have seen this issue a couple of times. In every case it has been because sightly would initialize the same class twice, first using the adaptTo  and then the java Pojo provider. This was caused in every case by an error in the Post Construct method of the Sling Model class, which meant the adaptTo would return null and sightly would just keep trying different use providers.

Is this your scenario maybe?

Greetings.

Santiago García Pimentel| Sr Software Engineer
Netcentric Ibérica SLU
M: +34687915463
[hidden email] <mailto:[hidden email]> | www.netcentric.biz <http://www.netcentric.biz/>

> On Feb 2, 2017, at 3:08 AM, lancedolan <[hidden email]> wrote:
>
> Through my years in Adobe CQ and AEM, I've noticed that LOG files from
> components that I write always render twice per page request. Today I was
> debugging my code in Sling 8 and noticed that My debugger was kicked open
> twice each time I requested a page instead of once.
>
> What's the deal with this? It seems really common, you guys must all be
> familiar with it also?
>
> It's dangerous because all components logic must be idempotent (imagine
> posting duplicate records to a database). And then obviously, it's bad for
> performance to do things twice unnecessarily.  
>
> I've seen this so often on so many projects that I'm not really tempted to
> offer any steps to reproduce, you guys must be seeing this also right?
>
> NOTE: The component is NOT included on the page more than once. This
> behavior will occur when a component is included only once.
>
>
>
> --
> View this message in context: http://apache-sling.73963.n3.nabble.com/Components-each-process-twice-tp4070042.html
> Sent from the Sling - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Components each process twice

naveenChoudhary
Thanks for the reply but in my case there is no error , both the times it is working properly without any issue.

So now for you is it making only one call ?

In my case the problem is page is getting heavy and it is impacting performance very badly .

So I looking for the solution to avoid more than one call even if there is any failure how can we control the behaviour of sightly is there any way or the class I can refer to ?

Or is the default behaviour does anyone created a daycare for it ?

Any help will be appreciated ?

Thanks
Naveen
Reply | Threaded
Open this post in threaded view
|

Re: Components each process twice

Santiago García Pimentel
Hi again,

Made a quick test on an AEM instance.

I did get the duplicated sling model processed, but only in author mode when using touchUI in editor window. in every other case it is only one. Also they seemed to be two different requests, so each model is still processed once per request. AEM seems to trigger a second request at some point.

So this doesn't look like a problem with sling and more with the touch ui editor from AEM.

Greetings.

Santiago García Pimentel| Sr Software Engineer
Netcentric Ibérica SLU
M: +34687915463
[hidden email] <mailto:[hidden email]> | www.netcentric.biz <http://www.netcentric.biz/>

> On Mar 2, 2017, at 11:32 AM, naveenChoudhary <[hidden email]> wrote:
>
> Thanks for the reply but in my case there is no error , both the times it is
> working properly without any issue.
>
> So now for you is it making only one call ?
>
> In my case the problem is page is getting heavy and it is impacting
> performance very badly .
>
> So I looking for the solution to avoid more than one call even if there is
> any failure how can we control the behaviour of sightly is there any way or
> the class I can refer to ?
>
> Or is the default behaviour does anyone created a daycare for it ?
>
> Any help will be appreciated ?
>
> Thanks
> Naveen
>
>
>
> --
> View this message in context: http://apache-sling.73963.n3.nabble.com/Components-each-process-twice-tp4070042p4070865.html
> Sent from the Sling - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Components each process twice

naveenChoudhary
This post has NOT been accepted by the mailing list yet.
Thanks Friend