<div dir="ltr">oh - I'm not saying this is the biggest part of the IntialContext blocks. The largest by far is all the calls to "lookup". This was just the first one that I pinned down, and seemed like an easy fix. I'm looking at the lookup calls, and will post more on it.<br>
<br>FYI - When I profiled with the patch I included the block simply moved farther down into the InitialContext creation code. So a real fix would be limiting the number of instantiations, but as you say it might not be worth the effort. We'll have to see once we have optimized else where.<br>
<br>-Jay<br><br><div class="gmail_quote">On Tue, Sep 30, 2008 at 4:37 PM, Gavin King <span dir="ltr"><<a href="mailto:gavin@hibernate.org">gavin@hibernate.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Good work, Jay. I'm surprised to find that this is an issue. Really, creation of<br>
an InitialContext should be very lightweight (it should be optimized by the<br>
appserver). But if it's not, then Seam should optimize it.<br>
<div><div></div><div class="Wj3C7c"><br>
On Tue, Sep 30, 2008 at 2:01 PM, Jay Balunas <<a href="mailto:tech4j@gmail.com">tech4j@gmail.com</a>> wrote:<br>
> I have been looking more into the InitialContext and some of the performance<br>
> issues surrounding it.<br>
><br>
> There are really a couple of things to look at. One is how the<br>
> InitialContext is created, and manged, and the other broad category is how<br>
> often and what items are looked up? I have investigated the first, and have<br>
> begun investigating the second.<br>
><br>
> InitialContext creation and management<br>
> ------------------------------------------------<br>
> The only location were seam creates and manages the InitialContext is the<br>
> "org.jboss.seam.util.Naming" class (see:<br>
> <a href="http://fisheye.jboss.org/browse/Seam/trunk/src/main/org/jboss/seam/util/Naming.java?r=5444" target="_blank">http://fisheye.jboss.org/browse/Seam/trunk/src/main/org/jboss/seam/util/Naming.java?r=5444</a><br>
> ).<br>
><br>
> The properties are set in one location and done only once in the<br>
> initialization of seam (see:<br>
> <a href="http://fisheye.jboss.org/browse/Seam/trunk/src/main/org/jboss/seam/init/Initialization.java?r=9116#l915" target="_blank">http://fisheye.jboss.org/browse/Seam/trunk/src/main/org/jboss/seam/init/Initialization.java?r=9116#l915</a><br>
> ).<br>
><br>
> I see two issues here - one is creating the initial context every single<br>
> time it is needed, and the other is processing/checking the properties every<br>
> time it is called.<br>
><br>
> The first issue would require some caching mechanism or logic for reuse. I<br>
> am not an expert on when it makes sense to reuse an instance of the<br>
> InitialContext, and when we need to get it fresh. I can say that we<br>
> currently use they exact same properties to initialize it and those are set<br>
> during Seam initialization and do not appear to ever change once created.<br>
> Is there a way to cache and optimize this instantiation?<br>
><br>
> The second issue is that we do a certain amount of processing every time the<br>
> context is requested, this could be optimized. Currently I see a few<br>
> blocked threads on the "props.size()" call in the Naming class which is a<br>
> synchronized method on the Hashtable. This could easily be avoided.<br>
> Although we need to maintain the logic that if the property list is empty we<br>
> continue to call "new InitialContext()" and not pass in the properties<br>
> object. This is because the first thing the InitialContext constructor does<br>
> with a properties object is clone it which can be costly. I have attached a<br>
> patch that implements these changes for review.<br>
><br>
> Another item I noticed is that the only place (excluding some test code)<br>
> that does not use "Naming.getInitialContext()" is the<br>
> "org.jboss.seam.remoting.messaging.JBossConnectionProvider". It using the<br>
> "new InitialContext()" directly. Shane - is there a reason for this?<br>
><br>
> I'll write up my findings on the lookup usage asap.<br>
><br>
> Thanks,<br>
> Jay<br>
> --<br>
> blog: <a href="http://in.relation.to/Bloggers/Jay" target="_blank">http://in.relation.to/Bloggers/Jay</a><br>
><br>
</div></div>> _______________________________________________<br>
> seam-dev mailing list<br>
> <a href="mailto:seam-dev@lists.jboss.org">seam-dev@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/seam-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/seam-dev</a><br>
><br>
><br>
<font color="#888888"><br>
<br>
<br>
--<br>
Gavin King<br>
<a href="mailto:gavin.king@gmail.com">gavin.king@gmail.com</a><br>
<a href="http://in.relation.to/Bloggers/Gavin" target="_blank">http://in.relation.to/Bloggers/Gavin</a><br>
<a href="http://hibernate.org" target="_blank">http://hibernate.org</a><br>
<a href="http://seamframework.org" target="_blank">http://seamframework.org</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>blog: <a href="http://in.relation.to/Bloggers/Jay">http://in.relation.to/Bloggers/Jay</a><br>
</div>