The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » GlassFish

Thread: How to set jvmRoute for AJP/mod_jk load balancing

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 30 - Last Post: Nov 12, 2007 10:59 AM by: jluehe
jess_holle

Posts: 33
How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 23, 2007 7:14 AM
  Click to reply to this thread Reply

When using Glassfish with Apache via the AJP protocol (i.e. with mod_jk or mod_proxy_ajp), how can I achieve the equivalent of Tomcat's "jvmRoute" setting so as to obtain sticky-session load balancing?

For sticky-session load balancing mod_jk and mod_proxy_ajp expect that each servlet engine they're load balancing over has a unique id, "jvmRoute". Each servlet engine is expected to append this id (with a separator in between, ":" or ".", I forget which offhand) to the end of all session ids they generate. How do I make Glassfish do this?

I looked through the documentation and can find no mention of such an approach nor any clues as to how to specify a "session id suffix" or such either.

[This is a critical enabling capability to incrementally move from Apache + load-balanced Tomcats to Apache + load-balanced Glassfishes. Having to switch out Apache at the same time makes moving in this direction substantively harder.]

Jeanfrancois Ar...
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 23, 2007 10:26 AM   in response to: jess_holle
  Click to reply to this thread Reply


Hi Jess,

happy to see you here :-) ;-)

glassfish@javadesktop.org wrote:
> When using Glassfish with Apache via the AJP protocol (i.e. with mod_jk or mod_proxy_ajp), how can I achieve the equivalent of Tomcat's "jvmRoute" setting so as to obtain sticky-session load balancing?
>
> For sticky-session load balancing mod_jk and mod_proxy_ajp expect that each servlet engine they're load balancing over has a unique id, "jvmRoute". Each servlet engine is expected to append this id (with a separator in between, ":" or ".", I forget which offhand) to the end of all session ids they generate. How do I make Glassfish do this?
>
> I looked through the documentation and can find no mention of such an approach nor any clues as to how to specify a "session id suffix" or such either.
>
> [This is a critical enabling capability to incrementally move from Apache + load-balanced Tomcats to Apache + load-balanced Glassfishes. Having to switch out Apache at the same time makes moving in this direction substantively harder.]
> [Message sent by forum member 'jess_holle' (jess_holle)]

Just add, in domain.xml:

<jvm-options>jvmRoute=....</jvm-options>

I didn't test it but it should works.

Thanks

-- Jeanfrancois

>
> http://forums.java.net/jive/thread.jspa?messageID=241670
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


jakemann

Posts: 5
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 23, 2007 1:58 PM   in response to: Jeanfrancois Ar...
  Click to reply to this thread Reply

I am also tasked with load-balancing glassfish through apache (to gradually replace tomcat)

I tried adding to domain.xml:
<jvm-options>jvmRoute=glassfish1</jvm-options>
But I get the following error when starting the domain:
Exception in thread "main" java.lang.NoClassDefFoundError: jvmRoute=glassfish1

I also tried the following in domain.xml:
<jvm-options>-jvmRoute=glassfish1</jvm-options>
But I get an error with that as well:
Unrecognized option: -jvmRoute=glassfish1

Do you have any other suggestions?

Jeanfrancois Ar...
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 23, 2007 1:58 PM   in response to: jakemann
  Click to reply to this thread Reply


Hi,

glassfish@javadesktop.org wrote:
> I am also tasked with load-balancing glassfish through apache (to gradually replace tomcat)

Cool :-)

>
> I tried adding to domain.xml:
> <jvm-options>jvmRoute=glassfish1</jvm-options>
> But I get the following error when starting the domain:
> Exception in thread "main" java.lang.NoClassDefFoundError: jvmRoute=glassfish1
>
> I also tried the following in domain.xml:
> <jvm-options>-jvmRoute=glassfish1</jvm-options>
> But I get an error with that as well:
> Unrecognized option: -jvmRoute=glassfish1

I've made a typo:

<jvm-options>-DjvmRoute=glassfish1</jvm-options>

(add -D )

Thanks

-- Jeanfrancois

>
> Do you have any other suggestions?
> [Message sent by forum member 'jakemann' (jakemann)]
>
> http://forums.java.net/jive/thread.jspa?messageID=241748
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


jakemann

Posts: 5
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 23, 2007 2:21 PM   in response to: Jeanfrancois Ar...
  Click to reply to this thread Reply

Thanks for the quick response!

I changed it to a "-DjvmRoute=glassfish1" and the domain starts, however I still do not see "glassfish1" appended to JSESSIONID

Is there some other option that I need to turn on in order for this to happen?


Thanks again!

jess_holle

Posts: 33
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 23, 2007 6:34 PM   in response to: jakemann
  Click to reply to this thread Reply

Hmmm.... I just tried as well.

I do note that the "Engine" MBean in jconsole shows the appropriate jvmRoute.

That said, when I access the web app via the built-in web server (not via AJP yet as this was a quick test) I don't see any jvmRoute suffix. Is the necessary session suffix addition only enabled when the accessed via AJP? That would be fine (and I'll test that soon), but it does seem somewhat unlikely...

Jeanfrancois Ar...
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 24, 2007 7:07 AM   in response to: jess_holle
  Click to reply to this thread Reply

Hi,

for a reason I can't explain, the code for processing jvmRoute is
commented out in GlassFish (probably it was conflicting with the
HA/Session replication). I've just filled issue:

https://glassfish.dev.java.net/issues/show_bug.cgi?id=3796

to track the issue.

Thanks

-- Jeanfrancois

glassfish@javadesktop.org wrote:
> Hmmm.... I just tried as well.
>
> I do note that the "Engine" MBean in jconsole shows the appropriate jvmRoute.
>
> That said, when I access the web app via the built-in web server (not via AJP yet as this was a quick test) I don't see any jvmRoute suffix. Is the necessary session suffix addition only enabled when the accessed via AJP? That would be fine (and I'll test that soon), but it does seem somewhat unlikely...
> [Message sent by forum member 'jess_holle' (jess_holle)]
>
> http://forums.java.net/jive/thread.jspa?messageID=241790
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


jess_holle

Posts: 33
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 24, 2007 8:36 AM   in response to: Jeanfrancois Ar...
  Click to reply to this thread Reply

Thanks, Jean.

I'd really like to see an official patch sooner than later and would encourage that this be backported into updates to V2, not just fixed in V3 (else everyone needing to do Apache-based load-balancing will have to patch this themselves).

Jeanfrancois Ar...
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 24, 2007 10:06 AM   in response to: jess_holle
  Click to reply to this thread Reply



glassfish@javadesktop.org wrote:
> Thanks, Jean.
>
> I'd really like to see an official patch sooner than later and would encourage that this be backported into updates to V2, not just fixed in V3 (else everyone needing to do Apache-based load-balancing will have to patch this themselves).
> [Message sent by forum member 'jess_holle' (jess_holle)]

Agree. I will make sure it is fixed fir v2 ur1, and will produce a patch
for v2 FCS.

Thanks!

-- Jeanfrancois

>
> http://forums.java.net/jive/thread.jspa?messageID=241910
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


bjornsvenson

Posts: 2
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 26, 2007 12:57 PM   in response to: Jeanfrancois Ar...
  Click to reply to this thread Reply

oh my gosh! this is so awesome ... i experienced the exact same thing a few months ago. I tried and tried to get the load balancing to work, and even went as far as downloading the source and saw the commented out code you referred to. i just figured i was doing something wrong because everyone from the list said it worked just fine.

i'm glad you have requested a fix for it. yay!

colin

jess_holle

Posts: 33
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 23, 2007 11:26 AM   in response to: jess_holle
  Click to reply to this thread Reply

Thanks for the information!

jluehe

Posts: 281
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 24, 2007 10:30 AM   in response to: jess_holle
  Click to reply to this thread Reply

Hi Jess, appending the jvmRoute to the JSESSIONID can be easily achieved, but can you explain how the jvmRoute is used by mod_jk and mod_proxy_ajp if the instance on which a particular session has been created (and whose jvmRoute was appended to the session's JSESSIONID) has gone down, and the request fails over to a different instance?

You would expect that once the request has failed over to a different instance, you would want it to remain sticky to this new instance, but the jvmRoute that was appended to the JSESSIONID cannot be "updated" (and would continue to point to the "old" instance).

Thanks,

Jan

jess_holle

Posts: 33
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 24, 2007 12:27 PM   in response to: jluehe
  Click to reply to this thread Reply

First off, when all instances are up and running, mod_jk/mod_proxy_ajp load balancing is straightforward. Each servlet engine appends its jvmRoute suffix to its sessions. When mod_jk/mod_proxy_ajp balancer is in sticky session mode it sends requests with jvmRoute suffixes to the worker of the same name (i.e. jvmRoute=worker name).

All that said I am honestly not 100% certain what happens when a given worker is down and mod_jk/mod_proxy_ajp receives a request that is supposed to be handled by it.

jluehe

Posts: 281
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 24, 2007 1:54 PM   in response to: jess_holle
  Click to reply to this thread Reply

OK, so the jvmRoute seems to be useful only as long as all instances in the cluster are healthy.

To be honest, I don't think this is very useful :-). It doesn't mean we won't support it, but it would help if you could do some research on how the jvmRoute is used during a failover. I'm afraid there may be more to this than just appending the jvmRoute to the JSESSIONID.

The information used by the loadbalancer to preserve stickiness of a session needs to be dynamic, i.e., there must be a way for it to be updated (to point to the new instance) after a failover situation. This also means it really should not be encoded as part of the JSESSIONID, which makes it immutable.

Various other loadbalancers support a sticky flag that is updated after a failover. Again, if you could help us understand how the jvmRoute is used after a failover, that would help.

Jan

jess_holle

Posts: 33
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 24, 2007 2:08 PM   in response to: jluehe
  Click to reply to this thread Reply

It may be that Apache will send the request elsewhere if the servlet engine associated with it is dead and further it may be the session will be essentially renamed with a new jvmRoute. I must admit that I do not know all of these details, though I suspect the latter portion can be gleaned fairly easily from the Tomcat source code -- that's the analogous role for Glassfish obviously irrespective of what Apache does at this moment.

Clearly I'd like to see the sessions be "migratable" when a servlet engine dies but a shared persistent backup of the session data exists. Just having the load balanced over multiple JVMs without any additional availability gains is still something, though.

I may or may not be able to find time to comb through the Tomcat sources for such information in the near future. Eventually I suspect I'll be looking to get full migratability in place, but that does not have to be part of step 1.

jakemann

Posts: 5
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 24, 2007 3:10 PM   in response to: jluehe
  Click to reply to this thread Reply

From the research I have done on other sites about mod_jk and my own experience testing mod_jk with Glassfish and Tomcat, I have determined the following:

mod_jk does not keep a store of session ids. It merely looks at the .jvmRoute extension that is appended to the sessionid to determine which worker to send the request to. It was implemented this way so that multiple apache servers could load balance the same set of tomcat servers. (for apache fail-over purposes) If it did keep a store of session ids and what worker created them, then we would not be having this discussion!

In Tomcat, the workers still keep track of the session via the base sessionid. The .jvmRoute seems to be added for mod_jk's benefit only. If sessions are replicated, they are replicated using the base "jsessionid" and not "jsessionid.jvmroute"

In Apache, if a worker is unavailable, mod_jk will pick a fail-over worker based on how mod_jk is configured. When this happens, there are two possible outcomes:

a) If the original worker is a Tomcat worker and the session data is replicated to other Tomcat workers, then the fail-over worker finds the base sessionid in its store and carries on replacing the original worker's .jvmRoute with its own.

b) the session data is not replicated to the other workers, and the fail-over worker starts a new session and the previous session is lost. (usually resulting the user having to log back into the application)

I believe the interest here is in allowing for a gradual transition from Tomcat to Glassfish and/or maintaining Apache as a load balancing front-end.

It is my opinion that best way to enable this would be to append the .jvmRoute to the sessionid when sending it to the client; Also parsing the sessionid sent back by the client to remove the decimal point and everything after it when it is sent back to the server. The .jvmRoute part sould not be considered part of the sessionid on the server end and therefore would not be immutable.

Message was edited by: jakemann
(to revise and expound on my final paragraph)

jluehe

Posts: 281
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 24, 2007 10:11 PM   in response to: jakemann
  Click to reply to this thread Reply

OK, I found some useful info at:

http://tomcat.apache.org/tomcat-6.0-doc/config/cluster-valve.html

which mentions:

In case of a mod_jk failover, the JvmRouteBinderValve will replace the
jvmWorker attribute in the session Id, to make future requests stick
to this node. If you want failback capability, don't enable this
valve, but if you want your failover to stick, and for mod_jk not to
have to keep probing the node that went down, you use this valve.

I've checked the source code of the

createSession(String sessionId)

method of org/apache/catalina/session/ManagerBase in Tomcat 6, and found
this:

if (sessionId == null) {
sessionId = generateSessionId();
// FIXME WHy we need no duplication check?
/*
synchronized (sessions) {
while (sessions.get(sessionId) != null) { // Guarantee
// uniqueness
duplicates++;
sessionId = generateSessionId();
}
}
*/

// FIXME: Code to be used in case route replacement is needed
/*
} else {
String jvmRoute = getJvmRoute();
if (getJvmRoute() != null) {
String requestJvmRoute = null;
int index = sessionId.indexOf(".");
if (index > 0) {
requestJvmRoute = sessionId
.substring(index + 1, sessionId.length());
}
if (requestJvmRoute != null && !requestJvmRoute.equals(jvmRoute)) {
sessionId = sessionId.substring(0, index) + "." + jvmRoute;
}
}
*/
}

Looks like this code used to be responsible for updating the jvmRoute of a JSESSIONID to point to the new instance after a failover, so that the session would remain sticky to this new instance on subsequent requests.

I guess this functionality is now handled by the JvmRouteBinderValve described above.

I'm afraid that even if we added a jvmRoute to a JSESSIONID in GlassFish under certain conditions, this would not be of much use unless we also supported the entire org.apache.catalina.ha package and its cluster related valves (including the valve mentioned above), which would be a challenge by itself, since the valve interface in GlassFish differs from that in Tomcat.

Notice that GlassFish lets you configure your own sessionId generation algorithm, specified as the value of the session-id-generator-classname attribute of the <manager-properties> element in domain.xml. The specified class must implement the com.sun.enterprise.util.uuid.UuidGenerator interface. Theoretically, you could have your sessionId generation algorithm piggyback on the default GlassFish sessionId generation impl and append the jvmRoute to the result, if needed.


Jan

jess_holle

Posts: 33
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 25, 2007 6:15 AM   in response to: jluehe
  Click to reply to this thread Reply

Okay, so the difference here appears to be that Tomcat 6 gives you the choice as to whether to rename the session on failover, whereas previously route replacement was assumed.

I don't see an issue with simply assuming route replacement by default when jvmRoute is used, documenting this, and the potential to override this through custom session id generator.

Jeanfrancois Ar...
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 25, 2007 7:37 AM   in response to: jluehe
  Click to reply to this thread Reply

Hi Jan,

glassfish@javadesktop.org wrote:
> OK, I found some useful info at:
>
> http://tomcat.apache.org/tomcat-6.0-doc/config/cluster-valve.html
>
> which mentions:
>
> In case of a mod_jk failover, the JvmRouteBinderValve will replace the
> jvmWorker attribute in the session Id, to make future requests stick
> to this node. If you want failback capability, don't enable this
> valve, but if you want your failover to stick, and for mod_jk not to
> have to keep probing the node that went down, you use this valve.
>
> I've checked the source code of the
>
> createSession(String sessionId)
>
> method of org/apache/catalina/session/ManagerBase in Tomcat 6, and found
> this:
>
> if (sessionId == null) {
> sessionId = generateSessionId();
> // FIXME WHy we need no duplication check?
> /*
> synchronized (sessions) {
> while (sessions.get(sessionId) != null) { // Guarantee
> // uniqueness
> duplicates++;
> sessionId = generateSessionId();
> }
> }
> */
>
> // FIXME: Code to be used in case route replacement is needed
> /*
> } else {
> String jvmRoute = getJvmRoute();
> if (getJvmRoute() != null) {
> String requestJvmRoute = null;
> int index = sessionId.indexOf(".");
> if (index > 0) {
> requestJvmRoute = sessionId
> .substring(index + 1, sessionId.length());
> }
> if (requestJvmRoute != null && !requestJvmRoute.equals(jvmRoute)) {
> sessionId = sessionId.substring(0, index) + "." + jvmRoute;
> }
> }
> */
> }
>
> Looks like this code used to be responsible for updating the jvmRoute of a JSESSIONID to point to the new instance after a failover, so that the session would remain sticky to this new instance on subsequent requests.
>
> I guess this functionality is now handled by the JvmRouteBinderValve described above.
>
> I'm afraid that even if we added a jvmRoute to a JSESSIONID in GlassFish under certain conditions, this would not be of much use unless we also supported the entire org.apache.catalina.ha package and its cluster related valves (including the valve mentioned above), which would be a challenge by itself, since the valve interface in GlassFish differs from that in Tomcat.
>

I think we need to focus on 5.0.x, not 5.5/6 where the cluster code was
introduced....Need to refresh our memory with 5.0.x :-)

A+

-- Jeanfrancois

> Notice that GlassFish lets you configure your own sessionId generation algorithm, specified as the value of the session-id-generator-classname attribute of the <manager-properties> element in domain.xml. The specified class must implement the com.sun.enterprise.util.uuid.UuidGenerator interface. Theoretically, you could have your sessionId generation algorithm piggyback on the default GlassFish sessionId generation impl and append the jvmRoute to the result, if needed.
>
>
> Jan
> [Message sent by forum member 'jluehe' (jluehe)]
>
> http://forums.java.net/jive/thread.jspa?messageID=242022
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


jluehe

Posts: 281
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 25, 2007 6:10 PM   in response to: Jeanfrancois Ar...
  Click to reply to this thread Reply

Hi Jess,

we've had some internal discussions on how to support AJP/mod_jk load balancing without impacting the session management code in GlassFish.

To summarize our discussion, we will strip any jvmRoute from a session id "on the way in", and we will append a jvmRoute to the session id "on the way out".

More specifically:

- On the way in, we strip any jvmRoute (if present) from the
session id, whether it was supplied as a cookie or encoded
in the request URL.

- When creating a new session, we append the jvmRoute at the time when
we add the JSESSIONID cookie to the response, or at the time when the
session id is encoded in the response.

- On the way out (right when the response is about to be committed),
if cookies are supported, and the response does not yet contain any
Set-Cookie header, but a session has been active in the request,
we add a JSESSIONID cookie to the response, whose value is the session
id with the jvmRoute appended to it.

- A jvmRoute is added only if the "jvmRoute" system property has been
set in domain.xml, e.g., by adding:

<jvm-options>-DjvmRoute=<instance-name></jvm-options>

- With this approach, a session will *always* be sticky to the new instance after a
failover (since we never preserve the jvmRoute that was passed in), but you
mentioned that this would be acceptable as a first approximation.

I'm about to attach a patch (in the form of a JAR file) to

https://glassfish.dev.java.net/issues/show_bug.cgi?id=3796

To activate it, you must add its location to the classpath-prefix attribute of the <java-config> element in your domain.xml, like this:

<java-config classpath-prefix="<path-to-jar>" ...

Please try out the patch when it is available, and let us know.

Thanks,

Jan

jess_holle

Posts: 33
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 25, 2007 6:30 PM   in response to: jluehe
  Click to reply to this thread Reply

This sounds great. I'll try to test this out soon!

jess_holle

Posts: 33
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 26, 2007 1:15 PM   in response to: jess_holle
  Click to reply to this thread Reply

Given that jakemann has tested this and that I don't yet have the load balanced instances configured to give this a test, I'm going to take his word on it for now.

jakemann

Posts: 5
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 26, 2007 6:43 AM   in response to: jluehe
  Click to reply to this thread Reply

The patch works in my stand-alone instances. Apache/mod_jk now routes existing glassfish sessions back to the same worker like I need it to.

Thanks!

jluehe

Posts: 281
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Oct 28, 2007 2:16 PM   in response to: jakemann
  Click to reply to this thread Reply

Thanks for confirming the patch works, at least for the standalone case.

Can someone in the forum verify the patch in a cluster environment as well? I don't see why it would fail there, but having verified it in a cluster env would certainly increase our confidence level in the patch.

Soft Code Freeze for SJSAS9.1 Update 1 is targeted for 10/30, 11:59pm (PDT), so if we could get any test results in before that time, I'd appreciate it.

Thanks,

Jan

javahack

Posts: 1
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Nov 1, 2007 12:12 PM   in response to: jakemann
  Click to reply to this thread Reply

Hi guys, I'm not able to get the patch to work for some reason. jakemann, can you run through the steps of exactly how you set this up on your machine? Any help would be greatly appreciated.

I've been through a long list of blogs trying to configure this correctly, and still keep coming up short. For some reason, mod_jk is having trouble communicating with GlassFish.

If I check the server.log for my domain, I get the following message, which seems like things are ok:
[#|2007-11-01T11:37:05.751-0500|INFO|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=10;_ThreadName=main;|Apache mod_jk/jk2 attached to virtual-server server listening on port: 8009|#]

I installed the hello.war, and when I try to hit it with Apache\mod_jk, it seems like things start out ok:
Connected socket 840 to (127.0.0.1:8009)
sending to ajp13 pos=4 len=702 max=8192

But later, I get the following errors in the mod_jk.log:
[Thu Nov 01 12:38:38.997 2007] [5684:2232] [error] jk_ajp_common.c (1658): (worker1) Tomcat is down or refused connection. No response has been sent to the client (yet)
[Thu Nov 01 12:38:38.997 2007] [5684:2232] [info] jk_ajp_common.c (2046): (worker1) receiving from tomcat failed, recoverable operation attempt=1
[Thu Nov 01 12:38:38.997 2007] [5684:2232] [info] jk_ajp_common.c (2085): (worker1) sending request to tomcat failed, recoverable operation attempt=2
[Thu Nov 01 12:38:38.997 2007] [5684:2232] [error] jk_ajp_common.c (2097): (worker1) Connecting to tomcat failed. Tomcat is probably not started or is listening on the wrong port

I'm just not sure what is going on here.

Thanks!!

jakemann

Posts: 5
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Nov 1, 2007 2:46 PM   in response to: javahack
  Click to reply to this thread Reply

I have installed Glassfish in "/usr/glassfish" if your installation path is different, change any references to "/usr/glassfish" to point to your installation path. My Apache config files are in "/etc/httpd/conf" ... same disclaimer applies. I am running the latest stable version of Glassfish and the version of Apache that comes with Fedora Core 6.

1) I downloaded the patch and put it into /usr/glassfish/lib and renamed it to "jvmroute_patch.jar"

2) I modified my domain.xml file which was located in /usr/glassfish/domains/domain1/config:
2a) The line that beings with '<java-config classpath-suffix="" '' ) I placed the following two lines:
<jvm-options>-Dcom.sun.enterprise.web.connector.enableJK=8009</jvm-options>
<jvm-options>-DjvmRoute=glassfish1</jvm-options>

3) I have a Glassfish worker on port 8009 and a Tomcat worker listening on 8010. I created the following file as /etc/httpd/conf/workers.properties :
#=======================================
#Define workers using ajp13
worker.list=glassfish1, tomcat1, lb1

# ----------------------
# first glassfish worker
# ----------------------
worker.glassfish1.type=ajp13
worker.glassfish1.host=localhost.localdomain
worker.glassfish1.port=8009
worker.glassfish1.lbfactor=50
worker.glassfish1.socket_keepalive=1
worker.glassfish1.socket_timeout=300
# ----------------------
# first tomcat worker
# ----------------------
worker.tomcat1.type=ajp13
worker.tomcat1.host=localhost.localdomain
worker.tomcat1.port=8010
worker.tomcat1.lbfactor=50
worker.tomcat1.socket_keepalive=1
worker.tomcat1.socket_timeout=300
# ----------------------
# First Load Balancer worker
# ----------------------
worker.lb1.type=lb
worker.lb1.balance_workers=glassfish1,tomcat1
worker.lb1.sticky_session=true
#=======================================

4) Modified my /etc/httpd/conf/httpd.conf file and added the following at the end of the loadmodule section:
#=========================================
LoadModule jk_module /usr/lib/httpd/modules/mod_jk.so
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk logs
JkLogFile /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

# Each application needs to be routed through to the
# workers. So each application would get its own line.
# Send all app1 requests to the load balancer
JkMount /app1/* lb1
#==========================================

5.) Restart Glassfish, then restart Apache. If Apache's connection with a worker is broken, Apache will wait longer and longer between attempts to reconnect with the worker, so in a test environment the best thing is to just restart Apache so communication starts again right away.

Message was edited by: jakemann

oagostinho

Posts: 7
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Nov 9, 2007 4:33 AM   in response to: jakemann
  Click to reply to this thread Reply

Hi,

I've been followed these instructions, but it doesn't work. I have glassfish-installer-v2-b58g.jar installed on my computer with Win XP Professional.

What else Can I do?

Thanks a lot!
Orlando

Message was edited by: oagostinho

oagostinho

Posts: 7
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Nov 9, 2007 5:05 AM   in response to: oagostinho
  Click to reply to this thread Reply

Hi,

Everyone, Finally I did it!

That was the case:

1) I copied the patch.jar to GLASSFISHOME\lib, and doesn't worked!!
2) Then, I specified tha patch.jar in the <java-config classpath-prefix="PathToPatchFile" >
and, It's worked 100%

Anyway, I would like to Know, why I have this issue?

Thanks a lot!
Orlando Agostinho
Lisbon/Portugal

Message was edited by: oagostinho

Message was edited by: oagostinho

jluehe

Posts: 281
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Nov 9, 2007 12:02 PM   in response to: oagostinho
  Click to reply to this thread Reply

Hi Orlando, thanks for confirming that the patch finally worked for you! The reason it did not work for you when you added the patch.jar to GLASSFISHOME\lib is that the class files in patch.jar are also present in appserv-rt.jar, but with an older ("unpatched") version. In this case, the unpatched class files in appserv-rt.jar took precedence over those in patch.jar.

By explicitly placing patch.jar on your classpath-prefix, you ensure that the class files in patch.jar take precedence over any class files with the same name in any of the JAR files under GLASSFISHOME\lib.

oagostinho

Posts: 7
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Nov 12, 2007 10:54 AM   in response to: jluehe
  Click to reply to this thread Reply

Hi, Again

I've just tried to configure AJP/mod_jk with Cluster in Glassfish, but without any success!
:-(

Do you have any idea, about how can i do this?

Thanks a lot!
Orlando

jluehe

Posts: 281
Re: How to set jvmRoute for AJP/mod_jk load balancing
Posted: Nov 12, 2007 10:59 AM   in response to: oagostinho
  Click to reply to this thread Reply

Please follow step-by-step instructions posted by jakemann above.

Thanks,

Jan




 XML java.net RSS