You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Gregory Werner <gr...@gmail.com> on 2012/02/15 17:11:37 UTC

Application Scope Replication in 6.0.x

I saw an email back in 2007 which went unanswered.  Currently, I have load
balancer running for a 2 Tomcat setup and session replication works as
expected with the Tomcat 6.0.x documentation.  How does one go about
implementing application scope replication with Tomcat.  If the answer is
any better, a Tomcat 7.0.x answer would also be appreciated.

-Greg

Re: Application Scope Replication in 6.0.x

Posted by Pid <pi...@pidster.com>.
On 16/02/2012 15:55, Gregory Werner wrote:
> In-line responses.  Thanks for the ideas, I really do appreciate it.
> 
> On Thu, Feb 16, 2012 at 10:43 AM, Christopher Schultz <
> chris@christopherschultz.net> wrote:
> 
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Gregory,
>>
>> On 2/16/12 10:34 AM, Gregory Werner wrote:
>>> I didn't know that either.  It is simply a case of looking for the
>>> wrong keywords.  I said application score replication they said
>>> context attribute replication.  I gotta learn how to speak their
>>> language.
>>>
>>> Even after I put <Context
>>> className="*org.apache.catalina.ha.context.ReplicatedContext*"> in
>>> my context.xml
>>>
>>> and make sure that my application's web.xml has *<distributable
>>> />* * * the following:
>>>
>>> 1. Map<String, Date> userCache = (Map<String, Date>)
>>> context.getAttribute("userCache"); 2.
>>> userCache.remove(remoteUserName);
>>>
>>> returns a null userCache object (context is set in the
>>> ServletContextAware method, setServletContext).
>>
>> Is this all on the same server, or are you setting the attribute in
>> one context and watching for it's value to be available in a different
>> (replicated) one?
>>
>>
> In this case it is a test environment.  We are trying to emulate two
> distinct physical servers/load-balancing (which is the real case) on a
> single physical machine with one Tomcat instance.  Looking at the logs we
> can see some requests going to A and some going to B so it is load
> balancing, but in the end I am only placing a single war file and starting
> a single tomcat instance.

Huh?  One instance, what use is that?


p


>> Just trying to understand the test case, here.
>>
>>> When I enumerate through all the context attributes, I cannot see
>>> the stuff I am putting in it, just like the default entries which
>>> wind up there.  Too weird.
>>
>> Remember that it's not magic replication: Tomcat doesn't know when you
>> modify the object itself. I suspect that if you modify the object
>> itself (say, by adding elements to the cache) you'll have to do this:
>>
>> context.setAttribute("userCache", userCache);
>>
> 
> I do, that would be my next line.  I just stopped there because the
> userCache I retrieve from the context is null so I get a
> NullPointerException crashing things before I get an opportunity to put it
> back in the cache.
> 
> 
>>
>> You might want to consider using something like memcached or even a
>> traditional database to share this kind of information: IMO they are
>> much better equipped to do the kinds of things you want to do (and
>> they are separated from the servlet API, which can either be a good
>> thing or a bad thing for you).
>>
>> - -chris
>>
> 


-- 

[key:62590808]


Re: Application Scope Replication in 6.0.x

Posted by Gregory Werner <gr...@gmail.com>.
On Thu, Feb 16, 2012 at 11:15 AM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Gregory,
>
> On 2/16/12 10:55 AM, Gregory Werner wrote:
> > In this case it is a test environment.  We are trying to emulate
> > two distinct physical servers/load-balancing (which is the real
> > case) on a single physical machine with one Tomcat instance.
> > Looking at the logs we can see some requests going to A and some
> > going to B so it is load balancing, but in the end I am only
> > placing a single war file and starting a single tomcat instance.
>
> So, you have a single Tomcat instance with a single webapp deployed,
> but your load balancer has two separate connections to the single
> instance? What are you using for your load-balancer (it doesn't
> matter, I'm just curious).
>
> >> Remember that it's not magic replication: Tomcat doesn't know
> >> when you modify the object itself. I suspect that if you modify
> >> the object itself (say, by adding elements to the cache) you'll
> >> have to do this:
> >>
> >> context.setAttribute("userCache", userCache);
> >
> > I do, that would be my next line.  I just stopped there because
> > the userCache I retrieve from the context is null so I get a
> > NullPointerException crashing things before I get an opportunity to
> > put it back in the cache.
>
> Gotcha.
>
> So, when are you actually putting a UserCache *into* the servlet
> context? I'm wondering if you can't find anything in the servlet
> context because you've never put anything there :)
>
>
Yeah, ok, I think we can end this thread now.  A particular problem that
does not occur in my dev where context works great, but does occur in my
test.  It is difficult to describe, but basically because of an access
control list error in the test setup, it never does make it to that
particular item, so I can see it is likely not entered into the context.

-Greg

Re: Application Scope Replication in 6.0.x

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gregory,

On 2/16/12 10:55 AM, Gregory Werner wrote:
> In this case it is a test environment.  We are trying to emulate
> two distinct physical servers/load-balancing (which is the real
> case) on a single physical machine with one Tomcat instance.
> Looking at the logs we can see some requests going to A and some
> going to B so it is load balancing, but in the end I am only
> placing a single war file and starting a single tomcat instance.

So, you have a single Tomcat instance with a single webapp deployed,
but your load balancer has two separate connections to the single
instance? What are you using for your load-balancer (it doesn't
matter, I'm just curious).

>> Remember that it's not magic replication: Tomcat doesn't know
>> when you modify the object itself. I suspect that if you modify
>> the object itself (say, by adding elements to the cache) you'll
>> have to do this:
>> 
>> context.setAttribute("userCache", userCache);
> 
> I do, that would be my next line.  I just stopped there because
> the userCache I retrieve from the context is null so I get a 
> NullPointerException crashing things before I get an opportunity to
> put it back in the cache.

Gotcha.

So, when are you actually putting a UserCache *into* the servlet
context? I'm wondering if you can't find anything in the servlet
context because you've never put anything there :)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk89K7YACgkQ9CaO5/Lv0PC2KgCgpJQQ/xxpcz2rQPY/Q3x98myB
AO8AoIGshggKxO0op7ps4VbnroADEVw7
=KJti
-----END PGP SIGNATURE-----

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


Re: Application Scope Replication in 6.0.x

Posted by Gregory Werner <gr...@gmail.com>.
In-line responses.  Thanks for the ideas, I really do appreciate it.

On Thu, Feb 16, 2012 at 10:43 AM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Gregory,
>
> On 2/16/12 10:34 AM, Gregory Werner wrote:
> > I didn't know that either.  It is simply a case of looking for the
> > wrong keywords.  I said application score replication they said
> > context attribute replication.  I gotta learn how to speak their
> > language.
> >
> > Even after I put <Context
> > className="*org.apache.catalina.ha.context.ReplicatedContext*"> in
> > my context.xml
> >
> > and make sure that my application's web.xml has *<distributable
> > />* * * the following:
> >
> > 1. Map<String, Date> userCache = (Map<String, Date>)
> > context.getAttribute("userCache"); 2.
> > userCache.remove(remoteUserName);
> >
> > returns a null userCache object (context is set in the
> > ServletContextAware method, setServletContext).
>
> Is this all on the same server, or are you setting the attribute in
> one context and watching for it's value to be available in a different
> (replicated) one?
>
>
In this case it is a test environment.  We are trying to emulate two
distinct physical servers/load-balancing (which is the real case) on a
single physical machine with one Tomcat instance.  Looking at the logs we
can see some requests going to A and some going to B so it is load
balancing, but in the end I am only placing a single war file and starting
a single tomcat instance.


> Just trying to understand the test case, here.
>
> > When I enumerate through all the context attributes, I cannot see
> > the stuff I am putting in it, just like the default entries which
> > wind up there.  Too weird.
>
> Remember that it's not magic replication: Tomcat doesn't know when you
> modify the object itself. I suspect that if you modify the object
> itself (say, by adding elements to the cache) you'll have to do this:
>
> context.setAttribute("userCache", userCache);
>

I do, that would be my next line.  I just stopped there because the
userCache I retrieve from the context is null so I get a
NullPointerException crashing things before I get an opportunity to put it
back in the cache.


>
> You might want to consider using something like memcached or even a
> traditional database to share this kind of information: IMO they are
> much better equipped to do the kinds of things you want to do (and
> they are separated from the servlet API, which can either be a good
> thing or a bad thing for you).
>
> - -chris
>

Re: Application Scope Replication in 6.0.x

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gregory,

On 2/16/12 10:34 AM, Gregory Werner wrote:
> I didn't know that either.  It is simply a case of looking for the
> wrong keywords.  I said application score replication they said
> context attribute replication.  I gotta learn how to speak their
> language.
> 
> Even after I put <Context
> className="*org.apache.catalina.ha.context.ReplicatedContext*"> in
> my context.xml
> 
> and make sure that my application's web.xml has *<distributable
> />* * * the following:
> 
> 1. Map<String, Date> userCache = (Map<String, Date>) 
> context.getAttribute("userCache"); 2.
> userCache.remove(remoteUserName);
> 
> returns a null userCache object (context is set in the
> ServletContextAware method, setServletContext).

Is this all on the same server, or are you setting the attribute in
one context and watching for it's value to be available in a different
(replicated) one?

Just trying to understand the test case, here.

> When I enumerate through all the context attributes, I cannot see
> the stuff I am putting in it, just like the default entries which
> wind up there.  Too weird.

Remember that it's not magic replication: Tomcat doesn't know when you
modify the object itself. I suspect that if you modify the object
itself (say, by adding elements to the cache) you'll have to do this:

context.setAttribute("userCache", userCache);

...in order to trigger a re-replication across the cluster.

You might want to consider using something like memcached or even a
traditional database to share this kind of information: IMO they are
much better equipped to do the kinds of things you want to do (and
they are separated from the servlet API, which can either be a good
thing or a bad thing for you).

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk89JAwACgkQ9CaO5/Lv0PA4RQCfR7uhnaYwJyE6eHrINKmWS0EJ
mbAAnA+7E3GV2CHgpvSnikQkfypDcCIc
=+iC3
-----END PGP SIGNATURE-----

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


Re: Application Scope Replication in 6.0.x

Posted by Gregory Werner <gr...@gmail.com>.
I didn't know that either.  It is simply a case of looking for the wrong
keywords.  I said application score replication they said context attribute
replication.  I gotta learn how to speak their language.

Even after I put
<Context className="*org.apache.catalina.ha.context.ReplicatedContext*">
in my context.xml

and make sure that my application's web.xml has
*<distributable />*
*
*
the following:

   1. Map<String, Date> userCache = (Map<String, Date>)
   context.getAttribute("userCache");
   2. userCache.remove(remoteUserName);

returns a null userCache object (context is set in the ServletContextAware
method, setServletContext).  When I enumerate through all the context
attributes, I cannot see the stuff I am putting in it, just like the
default entries which wind up there.  Too weird.

-Greg

On Thu, Feb 16, 2012 at 9:59 AM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Chuck,
>
> On 2/15/12 4:21 PM, Caldarale, Charles R wrote:
> >> From: Gregory Werner [mailto:grjasewe@gmail.com] Subject: Re:
> >> Application Scope Replication in 6.0.x
> >
> >> Common data definitions which are used over and over and over
> >> again and don't change.  After the first time they are loaded, I
> >> want the info to be remembered for all users to access until
> >> Tomcat is brought down again.
> >
> > So why don't you do that in a ServletContextListener?
>
> +1
>
> If you need data available to the context, I would argue that it is
> more efficient to load and manage it locally than to replicate it
> across a cluster.
>
> Then again, I don't like clustering in the first place.
>
> (Sorry for pointing you in the wrong direction earlier).
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk89GeMACgkQ9CaO5/Lv0PBjWwCcDavF339v1cAhCrw0XKbr39Y9
> 1kMAniUurW8Sz3M4Xb/Q9c77fUszkIFI
> =OCY1
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Application Scope Replication in 6.0.x

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

On 2/15/12 4:21 PM, Caldarale, Charles R wrote:
>> From: Gregory Werner [mailto:grjasewe@gmail.com] Subject: Re:
>> Application Scope Replication in 6.0.x
> 
>> Common data definitions which are used over and over and over
>> again and don't change.  After the first time they are loaded, I
>> want the info to be remembered for all users to access until
>> Tomcat is brought down again.
> 
> So why don't you do that in a ServletContextListener?

+1

If you need data available to the context, I would argue that it is
more efficient to load and manage it locally than to replicate it
across a cluster.

Then again, I don't like clustering in the first place.

(Sorry for pointing you in the wrong direction earlier).

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk89GeMACgkQ9CaO5/Lv0PBjWwCcDavF339v1cAhCrw0XKbr39Y9
1kMAniUurW8Sz3M4Xb/Q9c77fUszkIFI
=OCY1
-----END PGP SIGNATURE-----

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


RE: Application Scope Replication in 6.0.x

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Gregory Werner [mailto:grjasewe@gmail.com] 
> Subject: Re: Application Scope Replication in 6.0.x

> Common data definitions which are used over and over and over again and
> don't change.  After the first time they are loaded, I want the info to be
> remembered for all users to access until Tomcat is brought down again.

So why don't you do that in a ServletContextListener?

 - 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 computers.


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


Re: Application Scope Replication in 6.0.x

Posted by Gregory Werner <gr...@gmail.com>.
Common data definitions which are used over and over and over again and
don't change.  After the first time they are loaded, I want the info to be
remembered for all users to access until Tomcat is brought down again.

-Greg

On Wed, Feb 15, 2012 at 3:32 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Gregory,
>
> On 2/15/12 11:11 AM, Gregory Werner wrote:
> > I saw an email back in 2007 which went unanswered.  Currently, I
> > have load balancer running for a 2 Tomcat setup and session
> > replication works as expected with the Tomcat 6.0.x documentation.
> > How does one go about implementing application scope replication
> > with Tomcat.  If the answer is any better, a Tomcat 7.0.x answer
> > would also be appreciated.
>
> Tomcat doesn't have any application-scope replication built-in: you'll
> have to roll this yourself.
>
> What is it that you want to replicate between webapps? Generally
> speaking, the webapp should being itself up consistently, not depend
> on another webapp running somewhere else to configure it.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk88FmMACgkQ9CaO5/Lv0PCUFACfU7xec1ebt1lZnKHiuYEgm6qx
> j28AnidfV5aWH50bl8CHcPMVwCjp9g2f
> =KWs4
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Application Scope Replication in 6.0.x

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pid,

On 2/15/12 4:56 PM, Pid * wrote:
> On 15 Feb 2012, at 20:33, Christopher Schultz 
> <ch...@christopherschultz.net> wrote:
> 
> Gregory,
> 
> On 2/15/12 11:11 AM, Gregory Werner wrote:
>>>> I saw an email back in 2007 which went unanswered.
>>>> Currently, I have load balancer running for a 2 Tomcat setup
>>>> and session replication works as expected with the Tomcat
>>>> 6.0.x documentation. How does one go about implementing
>>>> application scope replication with Tomcat.  If the answer is
>>>> any better, a Tomcat 7.0.x answer would also be appreciated.
> 
> Tomcat doesn't have any application-scope replication built-in:
> you'll have to roll this yourself.
> 
>> That's not entirely true.

I would say it was entirely untrue. :(

Thanks,

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk89GYUACgkQ9CaO5/Lv0PBBEACZAZCglRYGbVHCtA/sIHLmiiCL
nr0AoJaCDfjgilQUo8d9JE67mNORTp+O
=gAhy
-----END PGP SIGNATURE-----

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


Re: Application Scope Replication in 6.0.x

Posted by Pid * <pi...@pidster.com>.
On 15 Feb 2012, at 20:33, Christopher Schultz
<ch...@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Gregory,
>
> On 2/15/12 11:11 AM, Gregory Werner wrote:
>> I saw an email back in 2007 which went unanswered.  Currently, I
>> have load balancer running for a 2 Tomcat setup and session
>> replication works as expected with the Tomcat 6.0.x documentation.
>> How does one go about implementing application scope replication
>> with Tomcat.  If the answer is any better, a Tomcat 7.0.x answer
>> would also be appreciated.
>
> Tomcat doesn't have any application-scope replication built-in: you'll
> have to roll this yourself.

That's not entirely true.

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


p



>
> What is it that you want to replicate between webapps? Generally
> speaking, the webapp should being itself up consistently, not depend
> on another webapp running somewhere else to configure it.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk88FmMACgkQ9CaO5/Lv0PCUFACfU7xec1ebt1lZnKHiuYEgm6qx
> j28AnidfV5aWH50bl8CHcPMVwCjp9g2f
> =KWs4
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

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


Re: Application Scope Replication in 6.0.x

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gregory,

On 2/15/12 11:11 AM, Gregory Werner wrote:
> I saw an email back in 2007 which went unanswered.  Currently, I
> have load balancer running for a 2 Tomcat setup and session
> replication works as expected with the Tomcat 6.0.x documentation.
> How does one go about implementing application scope replication
> with Tomcat.  If the answer is any better, a Tomcat 7.0.x answer
> would also be appreciated.

Tomcat doesn't have any application-scope replication built-in: you'll
have to roll this yourself.

What is it that you want to replicate between webapps? Generally
speaking, the webapp should being itself up consistently, not depend
on another webapp running somewhere else to configure it.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk88FmMACgkQ9CaO5/Lv0PCUFACfU7xec1ebt1lZnKHiuYEgm6qx
j28AnidfV5aWH50bl8CHcPMVwCjp9g2f
=KWs4
-----END PGP SIGNATURE-----

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