Discussion:
How can I prevent Quartz multiple execution after tomcat restart
zlzc2000
2009-10-23 07:28:16 UTC
Permalink
hallo,

we have problem with Quartz and Tomcat.
Im using tomcat 5.5
i using 'localhost' to deploy a Spring project on server.
after deploy run Quartz the job once time. this is right.
but after restart tomcat, execute the same jobs twice at the same time.
(project new deploy then no problem, only after tomcat stop->start or
restart, then comming problem)
(2 quartz instanz created and started)

in server.xml i use two <Host> tags 1: <Host name="localhost" ...> 2:<Host
name="XXX.com"...> if i use only one host, for example only <Host
name="XXX.com"...>, then no problem., but by which i can not use interface
of tomcat.

a strange thing: in tomcat management interface i have stoped project, but
even though, in catalina.out can ich see, there is still one quartz job run.
I CANT UNDERSTAND!

how can i prevent it?
follow code are our server.xml code


<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false">
</Host>

<Host name="XXX.com"
unpackWARs="true" autoDeploy="false" deployOnStartup="false"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>www.XXX.com</Alias>
<Context path=""
docBase="/var/lib/tomcat55/webapps/xxx"
reloadable="true">
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.postgresql.Driver"
connectionURL="jdbcostgresql://localhost:5432/xxx"
connectionName="postgres" connectionPassword="" userTable="users_password"
userNameCol="userid" userCredCol="password"
userRoleTable="user_role" roleNameCol="rolename"
digest="MD5"/>
</Context>
</Host>
...

follow code are configuration of Quartz in applicationContex.xml

<bean id="robotSearchSwapper"
class="org.springframework.scheduling.quartz.Metho
dInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="swapperService" />
</property>
<property name="targetMethod">
<value>robotSearch</value>
</property>
<property name="concurrent" value="false" />
</bean>

<bean id="robotSearchTrigger"
class="org.springframework.scheduling.quartz.Simpl eTriggerBean">
<property name="jobDetail" ref="robotSearchSwapper"/>

<property name="startDelay">
<value>180000</value>
</property>
<property name="repeatInterval">
<value>300000</value>
</property>
</bean>
<bean id="scheduler" class="org.springframework.scheduling.quartz.Sched
ulerFactoryBean">
<property name="quartzProperties">
<props>
<prop key="org.quartz.threadPool.class">org.quartz.simpl
.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadCount">1</prop>
<prop key="org.quartz.threadPool.threadPriority">1</prop>
<prop key="org.quartz.threadPool.threadsInheritContextCl
assLoaderOfInitializingThread">true</prop>
</props>
</property>

<property name="triggers">
<list>
<ref local="robotSearchTrigger"/>
</list>
</property>
</bean>
--
View this message in context: http://www.nabble.com/How-can-I-prevent-Quartz-multiple-execution-after-tomcat-restart-tp26021949p26021949.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
Pid
2009-10-23 08:30:29 UTC
Permalink
Post by zlzc2000
hallo,
we have problem with Quartz and Tomcat.
Im using tomcat 5.5
i using 'localhost' to deploy a Spring project on server.
after deploy run Quartz the job once time. this is right.
but after restart tomcat, execute the same jobs twice at the same time.
(project new deploy then no problem, only after tomcat stop->start or
restart, then comming problem)
(2 quartz instanz created and started)
in server.xml i use two<Host> tags 1:<Host name="localhost" ...> 2:<Host
name="XXX.com"...> if i use only one host, for example only<Host
name="XXX.com"...>, then no problem., but by which i can not use interface
of tomcat.
a strange thing: in tomcat management interface i have stoped project, but
even though, in catalina.out can ich see, there is still one quartz job run.
I CANT UNDERSTAND!
I don't know how Quartz works with Spring, but at a guess, I'd say that
you're probably adding/configuring jobs when the app starts, but not
removing them when the app stops.

Thus, for each start (or restart) you're getting an additional job(s).

Probably a question for the Quartz/Spring community, you're more likely
to get accurate answers there - it's unlikely to be anything to do with
Tomcat or its respective config.


p
Post by zlzc2000
how can i prevent it?
follow code are our server.xml code
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="XXX.com"
unpackWARs="true" autoDeploy="false" deployOnStartup="false"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>www.XXX.com</Alias>
<Context path=""
docBase="/var/lib/tomcat55/webapps/xxx"
reloadable="true">
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.postgresql.Driver"
connectionURL="jdbcostgresql://localhost:5432/xxx"
connectionName="postgres" connectionPassword="" userTable="users_password"
userNameCol="userid" userCredCol="password"
userRoleTable="user_role" roleNameCol="rolename"
digest="MD5"/>
</Context>
</Host>
...
follow code are configuration of Quartz in applicationContex.xml
<bean id="robotSearchSwapper"
class="org.springframework.scheduling.quartz.Metho
dInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="swapperService" />
</property>
<property name="targetMethod">
<value>robotSearch</value>
</property>
<property name="concurrent" value="false" />
</bean>
<bean id="robotSearchTrigger"
class="org.springframework.scheduling.quartz.Simpl eTriggerBean">
<property name="jobDetail" ref="robotSearchSwapper"/>
<property name="startDelay">
<value>180000</value>
</property>
<property name="repeatInterval">
<value>300000</value>
</property>
</bean>
<bean id="scheduler" class="org.springframework.scheduling.quartz.Sched
ulerFactoryBean">
<property name="quartzProperties">
<props>
<prop key="org.quartz.threadPool.class">org.quartz.simpl
.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadCount">1</prop>
<prop key="org.quartz.threadPool.threadPriority">1</prop>
<prop key="org.quartz.threadPool.threadsInheritContextCl
assLoaderOfInitializingThread">true</prop>
</props>
</property>
<property name="triggers">
<list>
<ref local="robotSearchTrigger"/>
</list>
</property>
</bean>
Elli Albek
2009-10-23 09:00:13 UTC
Permalink
Where is your spring configuration file? Is it inside the war file?

When you have two hosts, do you have the war file in both? If this is he case you may deploy the entire war file twice. Generally a deployed war file can run only in one host. If you run it in two hosts, you are deploying the entire war file twice. This will create two instances of your quartz object.

If all you need is multiple domains mapped to the same application, try replacing

<Host name="localhost" ...>...</Host>
<Host name="XXX.com"...>...</Host>

With:
<Host name="localhost" ...>
<Alias>XXX.com</Alias>
...</Host>

E

----- Original Message -----
From: zlzc2000 <***@hotmail.com>
To: ***@tomcat.apache.org
Sent: Fri, 23 Oct 2009 00:28:16 -0700 (PDT)
Subject: How can I prevent Quartz multiple execution after tomcat restart


hallo,

we have problem with Quartz and Tomcat.
Im using tomcat 5.5
i using 'localhost' to deploy a Spring project on server.
after deploy run Quartz the job once time. this is right.
but after restart tomcat, execute the same jobs twice at the same time.
(project new deploy then no problem, only after tomcat stop->start or
restart, then comming problem)
(2 quartz instanz created and started)

in server.xml i use two <Host> tags 1: <Host name="localhost" ...> 2:<Host
name="XXX.com"...> if i use only one host, for example only <Host
name="XXX.com"...>, then no problem., but by which i can not use interface
of tomcat.

a strange thing: in tomcat management interface i have stoped project, but
even though, in catalina.out can ich see, there is still one quartz job run.
I CANT UNDERSTAND!

how can i prevent it?
follow code are our server.xml code


<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false">
</Host>

<Host name="XXX.com"
unpackWARs="true" autoDeploy="false" deployOnStartup="false"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>www.XXX.com</Alias>
<Context path=""
docBase="/var/lib/tomcat55/webapps/xxx"
reloadable="true">
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.postgresql.Driver"
connectionURL="jdbcostgresql://localhost:5432/xxx"
connectionName="postgres" connectionPassword="" userTable="users_password"
userNameCol="userid" userCredCol="password"
userRoleTable="user_role" roleNameCol="rolename"
digest="MD5"/>
</Context>
</Host>
...

follow code are configuration of Quartz in applicationContex.xml

<bean id="robotSearchSwapper"
class="org.springframework.scheduling.quartz.Metho
dInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="swapperService" />
</property>
<property name="targetMethod">
<value>robotSearch</value>
</property>
<property name="concurrent" value="false" />
</bean>

<bean id="robotSearchTrigger"
class="org.springframework.scheduling.quartz.Simpl eTriggerBean">
<property name="jobDetail" ref="robotSearchSwapper"/>

<property name="startDelay">
<value>180000</value>
</property>
<property name="repeatInterval">
<value>300000</value>
</property>
</bean>
<bean id="scheduler" class="org.springframework.scheduling.quartz.Sched
ulerFactoryBean">
<property name="quartzProperties">
<props>
<prop key="org.quartz.threadPool.class">org.quartz.simpl
.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadCount">1</prop>
<prop key="org.quartz.threadPool.threadPriority">1</prop>
<prop key="org.quartz.threadPool.threadsInheritContextCl
assLoaderOfInitializingThread">true</prop>
</props>
</property>

<property name="triggers">
<list>
<ref local="robotSearchTrigger"/>
</list>
</property>
</bean>
--
View this message in context: http://www.nabble.com/How-can-I-prevent-Quartz-multiple-execution-after-tomcat-restart-tp26021949p26021949.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Pid
2009-10-23 11:02:31 UTC
Permalink
Post by Elli Albek
Where is your spring configuration file? Is it inside the war file?
When you have two hosts, do you have the war file in both? If this is he case you may deploy the entire war file twice. Generally a deployed war file can run only in one host. If you run it in two hosts, you are deploying the entire war file twice. This will create two instances of your quartz object.
Actually, now that Elli points that out...
Post by Elli Albek
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="XXX.com"
unpackWARs="true" autoDeploy="false" deployOnStartup="false"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>www.XXX.com</Alias>
<Context path="" docBase="/var/lib/tomcat55/webapps/xxx" reloadable="true">
...
Post by Elli Albek
</Context>
</Host>
The Host XXX.com doesn't have an appBase defined, so it might be using
the default - which may mean that you're deploying the app twice, once
as the ROOT application, and once under it's actual name.

You can check this by requesting: http://www.XXX.com/xxx, where "xxx" is
the actual name of your app.

Either way, setting the Context in server.xml is _strongly_ discouraged.

You should:

1. set an appBase attribute in the XXX.com Host definition.

2. Remove the Context definition from server.xml

3. Remove the path & docBase attributes from the Context definition

4. Add a file "META-INF/context.xml" containing the Context definition
to your web application.

5. rename your application directory "ROOT".


... and then let us know if the problem still occurs.

p
Karthik Nanjangude
2009-10-26 14:26:50 UTC
Permalink
Hi

Try Load on startup in web.xml configuration for Quartz .

I have done the same and have good results

The configuration is as PER QUARTZ API


<servlet>
<servlet-name>
QuartzInitializer
</servlet-name>
<display-name>
Quartz Initializer Servlet
</display-name>
<servlet-class>
org.quartz.ee.servlet.QuartzInitializerServlet
</servlet-class>
<load-on-startup>
1
</load-on-startup>
<init-param>
<param-name>config-file</param-name>
<param-value>/some/path/my_quartz.properties</param-value>
</init-param>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</init-param>
</servlet>


With regards
karthik

-----Original Message-----
From: Pid [mailto:***@pidster.com]
Sent: Friday, October 23, 2009 4:33 PM
To: Tomcat Users List
Subject: Re: How can I prevent Quartz multiple execution after tomcat restart
Post by Elli Albek
Where is your spring configuration file? Is it inside the war file?
When you have two hosts, do you have the war file in both? If this is he case you may deploy the entire war file twice. Generally a deployed war file can run only in one host. If you run it in two hosts, you are deploying the entire war file twice. This will create two instances of your quartz object.
Actually, now that Elli points that out...
Post by Elli Albek
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="XXX.com"
unpackWARs="true" autoDeploy="false" deployOnStartup="false"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>www.XXX.com</Alias>
<Context path="" docBase="/var/lib/tomcat55/webapps/xxx" reloadable="true">
...
Post by Elli Albek
</Context>
</Host>
The Host XXX.com doesn't have an appBase defined, so it might be using
the default - which may mean that you're deploying the app twice, once
as the ROOT application, and once under it's actual name.

You can check this by requesting: http://www.XXX.com/xxx, where "xxx" is
the actual name of your app.

Either way, setting the Context in server.xml is _strongly_ discouraged.

You should:

1. set an appBase attribute in the XXX.com Host definition.

2. Remove the Context definition from server.xml

3. Remove the path & docBase attributes from the Context definition

4. Add a file "META-INF/context.xml" containing the Context definition
to your web application.

5. rename your application directory "ROOT".


... and then let us know if the problem still occurs.

p

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Caldarale, Charles R
2009-10-23 12:56:11 UTC
Permalink
Subject: Re: How can I prevent Quartz multiple execution after
tomcatrestart
If all you need is multiple domains mapped to the same application, try replacing
<Host name="localhost" ...>...</Host>
<Host name="XXX.com"...>...</Host>
<Host name="localhost" ...>
<Alias>XXX.com</Alias>
...</Host>
Note that if you have only one <Host>, <Alias> elements are completely superfluous.

- Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all comp
André Warnier
2009-10-23 13:27:04 UTC
Permalink
Post by Caldarale, Charles R
Subject: Re: How can I prevent Quartz multiple execution after
tomcatrestart
If all you need is multiple domains mapped to the same application, try replacing
<Host name="localhost" ...>...</Host>
<Host name="XXX.com"...>...</Host>
<Host name="localhost" ...>
<Alias>XXX.com</Alias>
...</Host>
Note that if you have only one <Host>, <Alias> elements are completely superfluous.
But maybe still useful, from a documentation point of view. ;-)
Caldarale, Charles R
2009-10-23 13:58:29 UTC
Permalink
Subject: RE: How can I prevent Quartz multiple execution after
tomcatrestart
Post by Caldarale, Charles R
Note that if you have only one <Host>, <Alias> elements are
completely superfluous.
But maybe still useful, from a documentation point of view. ;-)
Better handled by comments, rather than configuration elements that can mislead someone into thinking something useful is being accomplished.

- Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its atta
André Warnier
2009-10-23 14:25:51 UTC
Permalink
Post by Caldarale, Charles R
Subject: RE: How can I prevent Quartz multiple execution after
tomcatrestart
Post by Caldarale, Charles R
Note that if you have only one <Host>, <Alias> elements are
completely superfluous.
But maybe still useful, from a documentation point of view. ;-)
Better handled by comments, rather than configuration elements that can mislead someone into thinking something useful is being accomplished.
Well, let's get to the bottom of this.
When Tomcat gets a request, does it :
1) figure immediately that it has only one Host, and thus not even look
at the "Host:" header, and respond with the one and only default Host ?
or
2) first look at the Host header, try to find a matching Host or Alias,
and only default to the default Host if it has /not/ found a matching
Host name or Alias ?

Hmm ?
Pid
2009-10-23 14:42:53 UTC
Permalink
Post by André Warnier
Post by Caldarale, Charles R
Subject: RE: How can I prevent Quartz multiple execution after
tomcatrestart
Post by Caldarale, Charles R
Note that if you have only one <Host>, <Alias> elements are
completely superfluous.
But maybe still useful, from a documentation point of view. ;-)
Better handled by comments, rather than configuration elements that
can mislead someone into thinking something useful is being accomplished.
Well, let's get to the bottom of this.
1) figure immediately that it has only one Host, and thus not even look
at the "Host:" header, and respond with the one and only default Host ?
or
2) first look at the Host header, try to find a matching Host or Alias,
and only default to the default Host if it has /not/ found a matching
Host name or Alias ?
I'd guess 2.

p
Post by André Warnier
Hmm ?
---------------------------------------------------------------------
Mark Thomas
2009-10-23 15:01:39 UTC
Permalink
Post by Pid
Post by André Warnier
Well, let's get to the bottom of this.
1) figure immediately that it has only one Host, and thus not even look
at the "Host:" header, and respond with the one and only default Host ?
or
2) first look at the Host header, try to find a matching Host or Alias,
and only default to the default Host if it has /not/ found a matching
Host name or Alias ?
I'd guess 2.
p
Post by André Warnier
Hmm ?
Gee, if only you could look at the source code to find out...

Hint:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java?view=annotate

Mark
André Warnier
2009-10-23 21:36:12 UTC
Permalink
Post by Mark Thomas
Post by Pid
Post by André Warnier
Well, let's get to the bottom of this.
1) figure immediately that it has only one Host, and thus not even look
at the "Host:" header, and respond with the one and only default Host ?
or
2) first look at the Host header, try to find a matching Host or Alias,
and only default to the default Host if it has /not/ found a matching
Host name or Alias ?
I'd guess 2.
p
Post by André Warnier
Hmm ?
Gee, if only you could look at the source code to find out...
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java?view=annotate
Sorry Mark, I did just now, and figure that it must be happening
somewhere around line 600 of that piece of art, but my Java knowledge is
too limited to figure out what exactly it is doing.
I get the feeling it's (2), but then..
So come on, tell us : (1) or (2) ?

If it happened to be (2), then one could argue that adding an <Alias>
matching the real "Host:" of the calls, is actually slightly faster than
not doing so.
One would just love to catch Chuck some time..
Christopher Schultz
2009-10-26 15:01:46 UTC
Permalink
André,
Post by André Warnier
Sorry Mark, I did just now, and figure that it must be happening
somewhere around line 600 of that piece of art, but my Java knowledge is
too limited to figure out what exactly it is doing.
It's not too hard. Starting from line 600, you have:

600 int pos = findIgnoreCase(hosts, host);

This method (presumably) locates the index into the 'hosts' array that
the given host matches. findIgnoreCase calls findIgnoreCase (overloaded
to take different parameters) and this happens:

1031 int b = map.length - 1;
1032
1033 // Special cases: -1 and 0
1034 if (b == -1) {
1035 return -1;
1036 }
1037 if (compareIgnoreCase(name, start, end, map[0].name) < 0 ) {
1038 return -1;
1039 }
1040 if (b == 0) {
1041 return 0;
1042 }

So, if there are no hosts (oops) or only one host and it's name doesn't
match the requested host, -1 is returned. If the requested host matches
the only defined host, 0 is returned.

Back to the internalMap method:

601 if ((pos != -1) && (host.equalsIgnoreCase(hosts[pos].name))) {
602 mappingData.host = hosts[pos].object;
603 contexts = hosts[pos].contextList.contexts;
604 nesting = hosts[pos].contextList.nesting;
605 } else {
606 if (defaultHostName == null) {
607 return;
608 }
609 pos = find(hosts, defaultHostName);
610 if ((pos != -1) && (defaultHostName.equals(hosts[pos].name))) {
611 mappingData.host = hosts[pos].object;
612 contexts = hosts[pos].contextList.contexts;
613 nesting = hosts[pos].contextList.nesting;
614 } else {
615 return;
616 }
617 }

The variable pos is either -1 (if no host matched) or 0. If it's zero
and the hostname matches (again), it takes the first branch. Otherwise,
it takes the second branch and you get the default host (which has to be
located in the array by looking up its hostname).

So, to answer your question, the hostname is always looked-up in the
list of <Host> elements defined. If it doesn't match, the default
hostname is located in the same list and used.

The logic evaluates a bit more quickly if:

1. You define only a single host.
2. You define it to be the hostname you actually expect clients to use
(that is, there is a slight performance hit if you just use
"localhost" like I usually recommend).

I see some potential performance improvements, here, such as the following:

1. Cache a reference to the default <Host>: why bother looking it up for
every single request? It should never change!

2. Short-circuit all this logic when there is only one host and it is
the default host. There's no need to ever do all this mapping work when
that happens.

3. Use more search logic to determine whether the host you matches is an
exact match or a default match at the same time. It looks like
findIgnoreCase does half the work and then internalMap re-checks for
string equality. Presumably, the string equality check has occurred once
already, and need not be repeated.

4. Use a hash to locate matching <Host> (or alias) elements, rather than
the binary-search currently being used. I suspect that, unless /many/
hosts and aliases are defined, searches versus hashes are comparable, so
this may be more trouble than it's worth.
Post by André Warnier
If it happened to be (2), then one could argue that adding an <Alias>
matching the real "Host:" of the calls, is actually slightly faster than
not doing so.
If you look at the addHost method in Mapper.java, you'll see that, for
each <Alias> for a <Host>, the <Host>'s data is copied into the array
used for <Host> elements. Searching a large array is (somewhat) slower
than searching a small array, so you'd actually be making things go more
slowly by adding superfluous <Alias> elements.
Post by André Warnier
One would just love to catch Chuck some time..
I'll bet he's quick: you'd better wear cleats and gloves.

- -chris
André Warnier
2009-10-26 15:52:17 UTC
Permalink
Christopher,

thanks for the masterful analysis.
I'll pick out just one aspect :

Christopher Schultz wrote:
...
Post by Christopher Schultz
Post by André Warnier
If it happened to be (2), then one could argue that adding an <Alias>
matching the real "Host:" of the calls, is actually slightly faster than
not doing so.
My point exactly.

...
Post by Christopher Schultz
Post by André Warnier
One would just love to catch Chuck some time..
I'll bet he's quick: you'd better wear cleats and gloves.
Yes, but this time..
Assuming there is a single (and default) Host, like this :
<Host name="locahost" ...>
<Alias name="somealias.company.com">
</Host>

and multiple requests comes in with a header
Host: somealias.company.com

then indeed the fact of having this Alias, would be faster than not
having it, wouldn't it ?
And in such a case, Chuck's comment that
"Note that if you have only one <Host>, <Alias> elements are completely
superfluous."
would be, in fact, incorrect. Ha !

(I do mention "multiple requests", because one could also argue that if
the number of requests addressing that particular "alias" is low, then
the additional overhead of creating the alias-related Hosts array entry
in the first place, may negate the subsequent efficiency gain.)
We need one of these nice graphs showing the respective gains here..
Don't you feel tempted ?

About your optimisation suggestions, I see another possible one :
If this is a keep-alive connection, then the same Tomcat thread will
handle subsequent browser requests over that same connection.
As far as I know, there isn't really a case where a browser will issue
multiple requests over the same connection, if not addressed to the same
Host. So the thread could also cache a pointer to the Host entry
obtained in the first request of the connection, and re-use it without
lookup for subsequent requests over the same connection. Not so ?
(To make this more certain, one could also cache the Host's name and
check, but that might not even be necessary).
Caldarale, Charles R
2009-10-26 16:07:30 UTC
Permalink
Subject: Re: How can I prevent Quartz multiple execution after
tomcatrestart
<Host name="locahost" ...>
<Alias name="somealias.company.com">
</Host>
and multiple requests comes in with a header
Host: somealias.company.com
then indeed the fact of having this Alias, would be faster than not
having it, wouldn't it ?
And in such a case, Chuck's comment that
"Note that if you have only one <Host>, <Alias> elements are completely
superfluous."
would be, in fact, incorrect. Ha !
Nope, it's still superfluous, since it does not affect the operation. To optimize performance, you would change the defaultHost attribute of the <Engine> to "somealias.company.com" (or whatever the most commonly used host name is), and change the name attribute of the single <Host> to the same. Adding the <Alias> will slow it down.

- Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete
Christopher Schultz
2009-10-26 16:26:10 UTC
Permalink
André,
Post by André Warnier
<Host name="locahost" ...>
<Alias name="somealias.company.com">
</Host>
and multiple requests comes in with a header
Host: somealias.company.com
then indeed the fact of having this Alias, would be faster than not
having it, wouldn't it ?
In the case of a single default <Host> with no aliases, you'll get:

1 string compare in findIgnoreCase (compares requested hostname)
1 string compare in find (compares default hostname)
1 string compare in internalMap (compares default hostname to itself)

In the case of a single <Host> with the <Alias>, you'll get:

Hmm. Re-reading the code for findIgnoreCase, line 1037 is making me
frown a bit. It seems that the requested hostname is /always/ compared
to the first <Host> element. If the requested hostname is "inferior" to
the name of the first <Host>, then -1 is returned and the default host
is used.
Post by André Warnier
And in such a case, Chuck's comment that
"Note that if you have only one <Host>, <Alias> elements are completely
superfluous."
would be, in fact, incorrect. Ha !
I'm still undecided until I see an explanation of the line of code above.
Post by André Warnier
We need one of these nice graphs showing the respective gains here..
Don't you feel tempted ?
No, but I'll happily look at your graph once completed ;)
Post by André Warnier
If this is a keep-alive connection, then the same Tomcat thread will
handle subsequent browser requests over that same connection.
There's a check for an existing previously-chosen host at the top of
internalMap. I suspect that this is already handled once the first of
several keep-alive requests is handled.
Post by André Warnier
As far as I know, there isn't really a case where a browser will issue
multiple requests over the same connection, if not addressed to the same
Host.
It would certainly break a lot of clients and servers if the above
weren't true: there would be no guarantee that all the "Host" headers
would resolve to the same IP address, so the connection might be
invalid. On the other hand, issuing a different Host in the middle of a
series of keep-alive requests might actually confuse certain components
of the server if they all expect the Host to remain constant.
Post by André Warnier
So the thread could also cache a pointer to the Host entry
obtained in the first request of the connection, and re-use it without
lookup for subsequent requests over the same connection.
Yeah, I think this is already being done. See above.

- -chris

Loading...