You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andrey Ilyin <an...@db.com> on 2010/03/18 15:22:36 UTC

Always load balance to same box with different tomcat contexts

Hi,

I am having a quite serious problem for which I could not find solution.
Tried to ask this question on couple apache forum and was adviced to ask it
on tomcat forums.

The configuration:

Apache: 2.2 serving as load balancer

workers.properties
worker.list=balancer

worker.engine1.port=10001
worker.engine1.host=localhost
worker.engine1.type=ajp13
worker.engine1.lbfactor=1

#worker.engine2.port=10002
#worker.engine2.host=localhost
#worker.engine2.type=ajp13
#worker.engine2.lbfactor=1

#worker.engine3.port=10003
#worker.engine3.host=localhost
#worker.engine3.type=ajp13
#worker.engine3.lbfactor=1

worker.balancer.type=lb
worker.balancer.sticky_session=1
worker.balancer.sticky_session_force=1
worker.balancer.balance_workers=engine1,engine2,engine3

3 Tomcat 6 instances with ajp connector with two webapps without session
serialization e.g.

<Connector
port="10001"
redirectPort="10011"
connectionTimeout="-1"
protocol="AJP/1.3">
</Connector>

<Context path="/webapp1" distributable="false">
</Context>
<Context path="/webapp2" distributable="false">
</Context>

Also it's setup as cluster with Clustered SSO Valve:

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<Valve
className="org.apache.catalina.ha.authenticator.ClusterSingleSignOn"/>

The problem is that once user logs in into webapp1 and goes to link to
webapp2, it's not guarantied that he will go to same box as webapp 1. This
results in session lost and sometimes Principal is not correctly propagated
between webapp1/webapp2 (). Using session serialization is not an option
because sessions used in webapp1/webapp2 are very heavy and it results in
awfull performance.

Is there a way to force apache to always rebalance to same box for different
tomcat contexts?

Thanks,
Andrey. 
-- 
View this message in context: http://old.nabble.com/Always-load-balance-to-same-box-with-different-tomcat-contexts-tp27946266p27946266.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by Andrey Ilyin <an...@db.com>.
Hi Mark, Gregor,

Thank you for your kind explanations - I think I understand how it works
now. This is working exactly as I wanted, as for your concerns:
1) We dont use full clustering (distributable flag is set to false on
contexts) - due to heavy sessions in webapp and fixing them is a big hassle.
2) The reason for clustering is that we use clustered sso - that's all we
need cluster for
3) However due to there was no guarantee that user will be loadbalanced to
same node for different context - this resulted in Ajax/Flex errors as for
some reason user principal was not always created correctly on different
node (always happened for Flex channels and sometimes for Ajax requests).

Thanks,
Andrey.


-- 
View this message in context: http://old.nabble.com/Always-load-balance-to-same-box-with-different-tomcat-contexts-tp27946266p27984292.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by 2smart4u <rc...@googlemail.com>.
Guys,

On Fri, Mar 19, 2010 at 5:12 PM, Mark Thomas <ma...@apache.org> wrote:
> On 19/03/2010 12:16, 2smart4u wrote:
>
> As per the thread title the OP wanted to:
> "Always load balance to same box with different tomcat contexts"
>

I understood it that way that he always wanted to loadbalance the same
sessions to the same box: Maybe I misunderstood that, but I don't see
any sense in loadbalancing every request independent of any session-
data to the same box: Why then use a loadbalancer anyways? But I guess
I'm missing something here

I guess this is a communication-(language?)-problem: A lot of ppl here
are not native speakers, so things got & will get mixed up.

Anyways, I guess the OP now has a whole bunch of information where he
can pick the most suitiable from

>
> That's the thing with e-mail, no-one can tell what tone of voice you are
> using or see the smile on your face as you type it. Particularly on
> mailing lists where people don't know each other, recipients have to
> reply soley on the text they see in front of them. What seems humerous
> to one person can appear completely differently to someone else. To me,
> "2smart4u" comes across as arrogant rather than funny.
>
Well, I really do hope that I don't appear  - apart from 2smart4u,
what's more or less a joke - arrogant, especially not within my posts.
If so, let me know since that's really, really not my intention.

And maybe you remember Amsterdam 2009, where we had a few beer and, if
I get it right, some mongolean food together ;)

I just didn't like my real name to show up in the lists any more since
I got mails from too many ppl asking nonsense (esp. headhunters
looking for cheap Tomcat-Admins).

Ok, I'll call it a weekend now and I'll be off for a
premier-league-football-match here in Cologne: I'm afraid we'll loose
that one anyways, but I rather watch my favourite team loose a match
than bumping around in the office ;)

Cheers!

Gregor
-- 
just because you're paranoid, don't mean they're not after you...
gpgp-fp: 79A84FA526807026795E4209D3B3FE028B3170B2
gpgp-key available
@ http://pgpkeys.pca.dfn.de:11371
@ http://pgp.mit.edu:11371/
skype:rc46fi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by Mark Thomas <ma...@apache.org>.
On 19/03/2010 12:16, 2smart4u wrote:
> On Fri, Mar 19, 2010 at 12:46 PM, Mark Thomas <ma...@apache.org> wrote:
> 
>> The question was how to make session stickiness apply to all applications on
>> a host. Clustering was mentioned but isn't relevant to this question (and
>> the OP's original post seemed to suggest they were having issues with
>> session replication).
> 
> Hm, either my English is too bad to understand the OP's question, or
> you might have missed something. The OP wrote:
> 
>> Also it's setup as cluster with Clustered SSO Valve:
> 
> So to my understanding it *is* about clustering and different hosts -
> or am I wrong here?

As per the thread title the OP wanted to:
"Always load balance to same box with different tomcat contexts"

Clustering appears to be giving them some difficulties as they said:

"Using session serialization is not an option because sessions used in
webapp1/webapp2 are very heavy and it results in awfull performance."

That suggests to me that there is something else not quite right with
either their app or their setup but given that fixing clustering wasn't
what they were asking about, I left it alone and dealt with the OP's
session stickiness question which, now they have that working, means
they can do load-balancing without session replication.

The OP's follow up question was about sharing sessions between contexts
on the same host, not about the consequences of session replciation. The
OP was deliberately trying to avoid using session replication due to the
issues they noted in their first post. I suspect that this question was
triggered by the fact that with a cookie path of "/", the session looks
like it might be shared between contexts on the same host since the same
session ID is used in all contexts. However, that is not the case and
the session objects for each context remain completely independent.

>> As an aside, have you considered using a less arrogant e-mail address?
> 
> First off, I don't see the email-adress as arrogent (since it's
> rc46fi). However, I'm owning a domain 2smart4u, and since I stopped
> using my real name in public emails (thanks to seach-engines and
> spam), I'm using it as a name, but I'm using it with a wink in my
> eyes.

That's the thing with e-mail, no-one can tell what tone of voice you are
using or see the smile on your face as you type it. Particularly on
mailing lists where people don't know each other, recipients have to
reply soley on the text they see in front of them. What seems humerous
to one person can appear completely differently to someone else. To me,
"2smart4u" comes across as arrogant rather than funny.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by 2smart4u <rc...@googlemail.com>.
Mark,

had a bad day?

On Fri, Mar 19, 2010 at 12:46 PM, Mark Thomas <ma...@apache.org> wrote:

> The question was how to make session stickiness apply to all applications on
> a host. Clustering was mentioned but isn't relevant to this question (and
> the OP's original post seemed to suggest they were having issues with
> session replication).

Hm, either my English is too bad to understand the OP's question, or
you might have missed something. The OP wrote:

> Also it's setup as cluster with Clustered SSO Valve:

So to my understanding it *is* about clustering and different hosts -
or am I wrong here?

> As an aside, have you considered using a less arrogant e-mail address?

First off, I don't see the email-adress as arrogent (since it's
rc46fi). However, I'm owning a domain 2smart4u, and since I stopped
using my real name in public emails (thanks to seach-engines and
spam), I'm using it as a name, but I'm using it with a wink in my
eyes.

Sorry if this might have insulted you or others.

Cheers

Gregor
-- 
just because you're paranoid, don't mean they're not after you...
gpgp-fp: 79A84FA526807026795E4209D3B3FE028B3170B2
gpgp-key available
@ http://pgpkeys.pca.dfn.de:11371
@ http://pgp.mit.edu:11371/
skype:rc46fi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by Mark Thomas <ma...@apache.org>.
On 19/03/2010 12:38, 2smart4u wrote:
> I think you might be missing something here.
>
> If I got the OP correct, it's not only about loadbalancing but also
> about maintaing the session between different Tomcat instances.
The question was how to make session stickiness apply to all 
applications on a host. Clustering was mentioned but isn't relevant to 
this question (and the OP's original post seemed to suggest they were 
having issues with session replication).

> When you want to loadbalance between two or more Tomcat
> instances where those instances don't know from each other, each
> instance will create it's very own session-cookie (at least this is
> how it shows up in our setup).
>
> So to my understanding the only solution to maintain
> session-information between multiple loadbalanced Tomcat instances is
> to run them within a cluster.
>
> Please correct me if I'm wrong.
Correct but not relevant to the OP's question.

> Gregor
As an aside, have you considered using a less arrogant e-mail address?

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by 2smart4u <rc...@googlemail.com>.
On Fri, Mar 19, 2010 at 11:54 AM, Mark Thomas <ma...@apache.org> wrote:
>
>> 2) There is cookie in browser - it will loadbalance to engine which
>> already
>> has session - since cookie has no context path
>
> Correct.
>

Mark, I think you might be missing something here.

If I got the OP correct, it's not only about loadbalancing but also
about maintaing the session between different Tomcat instances.

Given that, when you want to loadbalance between two or more Tomcat
instances where those instances don't know from each other, each
instance will create it's very own session-cookie (at least this is
how it shows up in our setup).

So to my understanding the only solution to maintain
session-information between multiple loadbalanced Tomcat instances is
to run them within a cluster.

Please correct me if I'm wrong.

Cheers

Gregor


> Mark
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>



-- 
just because you're paranoid, don't mean they're not after you...
gpgp-fp: 79A84FA526807026795E4209D3B3FE028B3170B2
gpgp-key available
@ http://pgpkeys.pca.dfn.de:11371
@ http://pgp.mit.edu:11371/
skype:rc46fi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by Mark Thomas <ma...@apache.org>.
On 19/03/2010 11:05, Andrey Ilyin wrote:
> Does this mean that session/servletContext is shared between contexts?
No.

> E.g.
> if I have some attribute in session/application contexts in webapp1 would it
> be accesible in webapp2?
No. Each webapp will have its own session object although they will all 
have the same session ID.

> So my understanding how it works:
>
> 1) There is no cookie in browser - it will loadbalance to any engine
Correct.

> 2) There is cookie in browser - it will loadbalance to engine which already
> has session - since cookie has no context path
Correct.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by 2smart4u <rc...@googlemail.com>.
On Fri, Mar 19, 2010 at 11:05 AM, Andrey Ilyin <an...@db.com> wrote:
>
>
> Does this mean that session/servletContext is shared between contexts? E.g.
> if I have some attribute in session/application contexts in webapp1 would it
> be accesible in webapp2?
>

when the context is dropped from a Cookie-path, the cookie is valid
for any context on that host

> So my understanding how it works:
>
> 1) There is no cookie in browser - it will loadbalance to any engine

you'll loose the session without a cookie, unless you're using
url-rewriting to store the session-information.
best practise is to use a cookie, though

> 2) There is cookie in browser - it will loadbalance to engine which already
> has session - since cookie has no context path

nope. actually the cookie can now be shared between various contexts
on the same engine (machine).
when having multiple instances of tomcat running where you want to
share the session-information, IMHO you'll need to setup a
tomcat-cluster.

hth

gregor
-- 
just because you're paranoid, don't mean they're not after you...
gpgp-fp: 79A84FA526807026795E4209D3B3FE028B3170B2
gpgp-key available
@ http://pgpkeys.pca.dfn.de:11371
@ http://pgp.mit.edu:11371/
skype:rc46fi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by Andrey Ilyin <an...@db.com>.


2smart4u wrote:
> 
> More or less, it drops the context from the Cookie-path, meaning the
> cookie is valid for all contexts.
> 

Hi Gregor,

Does this mean that session/servletContext is shared between contexts? E.g.
if I have some attribute in session/application contexts in webapp1 would it
be accesible in webapp2?

So my understanding how it works:

1) There is no cookie in browser - it will loadbalance to any engine
2) There is cookie in browser - it will loadbalance to engine which already
has session - since cookie has no context path

Thank you,
Andrey.

-- 
View this message in context: http://old.nabble.com/Always-load-balance-to-same-box-with-different-tomcat-contexts-tp27946266p27950926.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by 2smart4u <rc...@googlemail.com>.
>From the docs:

= [cut] =

If set to true, all paths for session cookies will be set to /. This
can be useful for portlet specification implementations. If not
specified, this attribute is set to false.

= [cut] =

More or less, it drops the context from the Cookie-path, meaning the
cookie is valid for all contexts.

Cheers

Gregor
-- 
just because you're paranoid, don't mean they're not after you...
gpgp-fp: 79A84FA526807026795E4209D3B3FE028B3170B2
gpgp-key available
@ http://pgpkeys.pca.dfn.de:11371
@ http://pgp.mit.edu:11371/
skype:rc46fi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by Andrey Ilyin <an...@db.com>.


markt-2 wrote:
> 
> On 18/03/2010 15:22, Andrey Ilyin wrote:
>> Is there a way to force apache to always rebalance to same box for
>> different
>> tomcat contexts?
> 
> You can try setting emptySessionPath="true" on the connector.
> 
> Mark
> 
> 
> Hi Mark,
> 
> Thank you, this works perfectly. Can you elaborate what this flag actually
> do and why does it fix it?
> I've read flag's description on apache tomcat site but I dont quite
> understand and I need to know if there any risks/downsides of enabling
> this flag.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Always-load-balance-to-same-box-with-different-tomcat-contexts-tp27946266p27948041.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Always load balance to same box with different tomcat contexts

Posted by Mark Thomas <ma...@apache.org>.
On 18/03/2010 15:22, Andrey Ilyin wrote:
> Is there a way to force apache to always rebalance to same box for different
> tomcat contexts?

You can try setting emptySessionPath="true" on the connector.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org