Just a tip to exclude some resources

3 views
Skip to first unread message

Gaetan Zoritchak

unread,
Jul 16, 2010, 3:40:13 AM7/16/10
to warp-core
Using the persistence filter for all the requests have no sense.

Here a pattern I use in the servlet module of my wicket webapp:

filterRegex("/*^(?!.*(swf|jpg|jpeg|png|ico|gif|css|js)).*
$").through(PersistenceFilter.class);

Gaetan

Dhanji R. Prasanna

unread,
Jul 18, 2010, 11:33:21 PM7/18/10
to warp...@googlegroups.com
I hear this suggestion from time to time but since there is virtually no cost to running this filter I don't see the point in it. Moreover running a complicated negation regex is potentially more expensive per request and is also prone to odd errors (what if you start serving dynamic .js files that need to load the database one day, and you've forgotten about this regex).

Dhanji.


--
You received this message because you are subscribed to the Google Groups "warp-core" group.
To post to this group, send email to warp...@googlegroups.com.
To unsubscribe from this group, send email to warp-core+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/warp-core?hl=en.


yaniv kessler

unread,
Jul 19, 2010, 5:40:48 AM7/19/10
to warp...@googlegroups.com
Can I quote this on my blog ?

Gaetan Zoritchak

unread,
Jul 19, 2010, 5:54:21 AM7/19/10
to warp-core
Hi Dhanji,

I don't understand your "there is virtually no cost to running this
filter".

In my configuration (JPA, UnitOfWork.Request), an entity manager is
created on every request, the cost depends on the JPA implementation.
It seems to me that it can cost CPU. You think the entity manager
creation cost less than the regexp processing? I must do some bench
with my configuration.

Gaetan,

On 19 juil, 05:33, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:
> I hear this suggestion from time to time but since there is virtually no
> cost to running this filter I don't see the point in it. Moreover running a
> complicated negation regex is potentially more expensive per request and is
> also prone to odd errors (what if you start serving dynamic .js files that
> need to load the database one day, and you've forgotten about this regex).
>
> Dhanji.
>
> On Fri, Jul 16, 2010 at 5:40 PM, Gaetan Zoritchak <g.zoritc...@gmail.com>wrote:
>
>
>
> > Using the persistence filter for all the requests have no sense.
>
> > Here a pattern I use in the servlet module of my wicket webapp:
>
> > filterRegex("/*^(?!.*(swf|jpg|jpeg|png|ico|gif|css|js)).*
> > $").through(PersistenceFilter.class);
>
> > Gaetan
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "warp-core" group.
> > To post to this group, send email to warp...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > warp-core+...@googlegroups.com<warp-core%2Bunsubscribe@googlegroups­.com>
> > .

Dhanji R. Prasanna

unread,
Jul 19, 2010, 7:02:15 AM7/19/10
to warp...@googlegroups.com
I'll wager that EntityManager creation cost is negligible in any decent JPA implementation. My point is more about the fact that maintaining this regex is an unnecessary complexity. 

If you can demonstrate that there is a serious performance hit I'll take it seriously =)

Dhanji.

To unsubscribe from this group, send email to warp-core+...@googlegroups.com.

Gaetan Zoritchak

unread,
Jul 19, 2010, 9:34:32 AM7/19/10
to warp-core
I made some benchmarks and the conclusion is that there is a
difference.

Using the regexp filter, the small resources are served by Tomcat for
free (0 ms) on my laptop. Without the regexp it costs a minimum of 15
ms. It's not that much but if you webapp contains lots of resources
it's noticeable.

Here, the comparison beetween 2 runs of 5 load of this page :
http://www.mon-credit-immobilier.info/simulation-ptz without the
browser cache.

For each page loading, the persistence filter manage 26 requests more
(it's not that much with the cache). The total difference is one
second for 5 pages.

<?xml version="1.0" encoding="ISO-8859-1"?>
<tree type="Call tree comparison" threadSelection="All threads"
threadStatus="Runnable" aggregation="Packages"
differenceCalculation="Total call times">
<node leaf="false" package="org.apache.tomcat.util.net"
timeDelta="-165921" timeBase="2705005" countDelta="0" countBase="6">
<node leaf="false" package="com.google.inject.servlet"
timeDelta="-163760" timeBase="2313286" countDelta="0" countBase="110">
<node leaf="true" package="java.util.regex" timeDelta="43284"
timeBase="0" countDelta="220" countBase="0"/>
<node leaf="true" package="java.util" timeDelta="613"
timeBase="778" countDelta="210" countBase="330"/>
<node leaf="true" package="javax.servlet.http" timeDelta="520"
timeBase="542" countDelta="105" countBase="220"/>
<node leaf="true" package="java.util.concurrent.atomic"
timeDelta="-5" timeBase="161" countDelta="0" countBase="110"/>
<node leaf="true" package="java.lang" timeDelta="-838"
timeBase="2398" countDelta="-5" countBase="660"/>
<node leaf="false" package="javax.servlet" timeDelta="-208069"
timeBase="2294866" countDelta="0" countBase="110">
<node leaf="true" package="com.coach.web" timeDelta="62341"
timeBase="0" countDelta="115" countBase="0"/>
<node leaf="true" package="com.google.inject.servlet"
timeDelta="55059" timeBase="0" countDelta="105" countBase="0"/>
<node leaf="true" package="org.slf4j.impl" timeDelta="20363"
timeBase="0" countDelta="200" countBase="0"/>
<node leaf="false" package="com.wideplay.warp.persist"
timeDelta="-1021980" timeBase="2294556" countDelta="-105"
countBase="110">
<node leaf="true" package="java.util" timeDelta="-110"
timeBase="125" countDelta="-105" countBase="110"/>
<node leaf="true" package="java.lang" timeDelta="-111"
timeBase="125" countDelta="-105" countBase="110"/>
<node leaf="true" package="java.util.concurrent.locks"
timeDelta="-2801" timeBase="2941" countDelta="-420" countBase="440"/>
<node leaf="false"
package="com.wideplay.warp.persist.internal" timeDelta="-1017643"
timeBase="2289679" countDelta="-105" countBase="110">
<node leaf="true" package="java.lang" timeDelta="-466"
timeBase="484" countDelta="-210" countBase="220"/>
<node leaf="true" package="java.util" timeDelta="-1364"
timeBase="1426" countDelta="-630" countBase="660"/>
<node leaf="false" package="com.wideplay.warp.persist"
timeDelta="-1010558" timeBase="2282336" countDelta="-315"
countBase="330">
<node leaf="false"
package="com.wideplay.warp.persist.jpa" timeDelta="-170558"
timeBase="178050" countDelta="-210" countBase="220"/>
<node leaf="false" package="javax.servlet"
timeDelta="-834240" timeBase="2098338" countDelta="-105"
countBase="110">
<node leaf="false" package="com.google.inject.servlet"
timeDelta="-833808" timeBase="2097877" countDelta="-105"
countBase="110">
<node leaf="true"
package="java.util.concurrent.atomic" timeDelta="71" timeBase="141"
countDelta="-105" countBase="110"/>
<node leaf="true" package="java.lang"
timeDelta="-143" timeBase="160" countDelta="-105" countBase="110"/>
<node leaf="true" package="java.util"
timeDelta="-300" timeBase="338" countDelta="-210" countBase="220"/>
<node leaf="true" package="javax.servlet.http"
timeDelta="-337" timeBase="363" countDelta="-105" countBase="110"/>
<node leaf="false" package="javax.servlet"
timeDelta="-829048" timeBase="2092625" countDelta="-105"
countBase="110"/>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</tree>



On 19 juil, 13:02, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:
> I'll wager that EntityManager creation cost is negligible in any decent JPA
> implementation. My point is more about the fact that maintaining this regex
> is an unnecessary complexity.
>
> If you can demonstrate that there is a serious performance hit I'll take it
> seriously =)
>
> Dhanji.
>

Gaetan Zoritchak

unread,
Jul 19, 2010, 9:35:11 AM7/19/10
to warp-core
On 19 juil, 13:02, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:
> I'll wager that EntityManager creation cost is negligible in any decent JPA
> implementation. My point is more about the fact that maintaining this regex
> is an unnecessary complexity.
>
> If you can demonstrate that there is a serious performance hit I'll take it
> seriously =)
>
> Dhanji.
>
Reply all
Reply to author
Forward
0 new messages