You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by William Speirs <ws...@apache.org> on 2012/01/18 17:22:52 UTC

Multiple Comet Requests to the Same Server, from the Same Client

I have a basic CometProcessor servlet implemented, and everything appears
to work as expected, except for one small issue: I cannot make multiple
requests from the same client to the same server.

My servlet simply sends messages to the client as they come in (think of it
as a one-sided chat, no POST). This works fine, except when I open a second
browser to the same server from the same client, I do not see the "void
event(CometEvent event)" method being called. The browser just sits and
spins waiting to connect. However, if I connect from a second client (IP
address), then the "void event(CometEvent event)" method is called, and the
second client starts receiving messages.

It seems as though tomcat (or the comet filter) is limiting the number of
connections from the same IP address. I have not tested this yet, but that
would be an issue in NAT situations where all connections would appear to
come from the same IP address. Thoughts?

Running:
tomcat-7.0.6
servlet-api-2.5.jar
tomcat-*-7.0-SNAPSHOT

Thanks...

Bill-

Re: Multiple Comet Requests to the Same Server, from the Same Client

Posted by William Speirs <ws...@apache.org>.
On Wed, Jan 18, 2012 at 2:00 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> > Quick update... I switched the code to using Servlet 3.0 and I can
> > get streaming data from all three browsers on the same machine:
> > Chrome, FireFox, and IE.
>
> A Tomcat upgrade probably helped a lot with that.


I actually didn't upgrade Tomcat yet :-)


> > I still cannot get two tabs in Chrome or FireFox to stream data,
> > but I think that is simply because they are sharing JSESSIONIDs and
> > I can probably code around that.
>
> Instead, how about disabling the use of cookies for session-tracking?
> Or, you can disable cookies in your web browser. If you've coded your
> webapp properly, you shouldn't notice a difference.
>

I will give this a try, but it's not a huge deal for me moving forward.

Right now I'm struggling with a ServletContainerInitializer not loading :-(

Bill-

Re: Multiple Comet Requests to the Same Server, from the Same Client

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

William,

On 1/18/12 1:13 PM, William Speirs wrote:
> Quick update... I switched the code to using Servlet 3.0 and I can
> get streaming data from all three browsers on the same machine:
> Chrome, FireFox, and IE.

A Tomcat upgrade probably helped a lot with that.

> I still cannot get two tabs in Chrome or FireFox to stream data,
> but I think that is simply because they are sharing JSESSIONIDs and
> I can probably code around that.

Instead, how about disabling the use of cookies for session-tracking?
Or, you can disable cookies in your web browser. If you've coded your
webapp properly, you shouldn't notice a difference.

- -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/

iEYEARECAAYFAk8XFr0ACgkQ9CaO5/Lv0PCNDwCgk/6+wk876f+0z/6Fr6nQu5Ll
IGUAoKtcD/p4P2X7IdfsEIVI0MFOVNQj
=sEiH
-----END PGP SIGNATURE-----

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


Re: Multiple Comet Requests to the Same Server, from the Same Client

Posted by William Speirs <ws...@apache.org>.
Quick update... I switched the code to using Servlet 3.0 and I can get
streaming data from all three browsers on the same machine: Chrome,
FireFox, and IE.

I still cannot get two tabs in Chrome or FireFox to stream data, but I
think that is simply because they are sharing JSESSIONIDs and I can
probably code around that.

Thanks...

Bill-

On Wed, Jan 18, 2012 at 12:13 PM, William Speirs <ws...@apache.org> wrote:

> Thanks for the quick responses, I'll respond to both at once below:
>
> On Wed, Jan 18, 2012 at 11:56 AM, André Warnier <aw...@ice-sa.com> wrote:
>
>  really a second, different browser ? or another window/tab from the same
>> browser ?
>> (if the second case, it may be re-using the same local IP:port (or just
>> the same established connection) to "connect" to the server, and that may
>> explain why the server appears not to react.
>>
>
> Yea, Chrome & FireFox... I don't think they share sessions (cookies) or
> connections.
>
> On Wed, Jan 18, 2012 at 12:02 PM, Konstantin Kolinko <
> knst.kolinko@gmail.com> wrote:
>
>> The HTTP specification recommends to have no more than 2 active
>> connections to the same HTTP server. The web browsers usually respect
>> it.
>>
>
> This would be at the 2 connection limit though...
>
>
>> IIRC "the same server" = the same DNS name, so different names have
>> different connection limits.
>>
>> It should be already discussed elsewhere - try to search.
>
>
> Yea, I didn't find anything, but I'll keep looking...
>
>
>> > Running:
>> > tomcat-7.0.6
>>
>> Too old.
>>
>
> I will certainly upgrade to 7.0.23 and see if that fixes the issue... you
> guys move too fast for me :-)
>
>
>> > servlet-api-2.5.jar
>>
>> Where?
>>
>
> This was included in our pom.xml file as <scope>provided</scope>, which
> was blatantly stolen from an example somewhere online.
>
> > tomcat-*-7.0-SNAPSHOT
>>
>> Does not make sense.
>
>
> Agreed, but again from Googleing somewhere it stated we should include
> this in our pom.xml as required to "make it all work".
>
> On a more general level, was the Comet implementation in Tomcat simply
> a precursor to Servlet 3.0's asynchronous functionality?
>
> In looking at other examples and reading the overview of the Servlet 3.0
> spec, it seems as though it will do what I want. Why would I use the Comet
> stuff in Tomcat?
>
> My current idea is to use the latest version of Tomcat 7, Servlet 3.0 (ie
> dropping servlet-api-2.5 and adding javaee-api-6.0 to my pom.xml) and
> implementing something similar to:
> http://code.google.com/p/jquery-stream/source/browse/sub-projects/jquery-stream-servlet/trunk/src/main/java/flowersinthesand/example/ChatServlet.java Does
> this seem like a reasonable path forward?
>
> Thanks again for the quick response...
>
> Bill-
>

Re: Multiple Comet Requests to the Same Server, from the Same Client

Posted by William Speirs <ws...@apache.org>.
Thanks for the quick responses, I'll respond to both at once below:

On Wed, Jan 18, 2012 at 11:56 AM, André Warnier <aw...@ice-sa.com> wrote:

> really a second, different browser ? or another window/tab from the same
> browser ?
> (if the second case, it may be re-using the same local IP:port (or just
> the same established connection) to "connect" to the server, and that may
> explain why the server appears not to react.
>

Yea, Chrome & FireFox... I don't think they share sessions (cookies) or
connections.

On Wed, Jan 18, 2012 at 12:02 PM, Konstantin Kolinko <knst.kolinko@gmail.com
> wrote:

> The HTTP specification recommends to have no more than 2 active
> connections to the same HTTP server. The web browsers usually respect
> it.
>

This would be at the 2 connection limit though...


> IIRC "the same server" = the same DNS name, so different names have
> different connection limits.
>
> It should be already discussed elsewhere - try to search.


Yea, I didn't find anything, but I'll keep looking...


> > Running:
> > tomcat-7.0.6
>
> Too old.
>

I will certainly upgrade to 7.0.23 and see if that fixes the issue... you
guys move too fast for me :-)


> > servlet-api-2.5.jar
>
> Where?
>

This was included in our pom.xml file as <scope>provided</scope>, which
was blatantly stolen from an example somewhere online.

> tomcat-*-7.0-SNAPSHOT
>
> Does not make sense.


Agreed, but again from Googleing somewhere it stated we should include this
in our pom.xml as required to "make it all work".

On a more general level, was the Comet implementation in Tomcat simply
a precursor to Servlet 3.0's asynchronous functionality?

In looking at other examples and reading the overview of the Servlet 3.0
spec, it seems as though it will do what I want. Why would I use the Comet
stuff in Tomcat?

My current idea is to use the latest version of Tomcat 7, Servlet 3.0 (ie
dropping servlet-api-2.5 and adding javaee-api-6.0 to my pom.xml) and
implementing something similar to:
http://code.google.com/p/jquery-stream/source/browse/sub-projects/jquery-stream-servlet/trunk/src/main/java/flowersinthesand/example/ChatServlet.java
Does
this seem like a reasonable path forward?

Thanks again for the quick response...

Bill-

Re: Multiple Comet Requests to the Same Server, from the Same Client

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

Konstantin,

On 1/18/12 12:02 PM, Konstantin Kolinko wrote:
> The HTTP specification recommends to have no more than 2 active 
> connections to the same HTTP server. The web browsers usually
> respect it.

Firefox uses 6 since v3 [1]

I remember a while back a bunch of browser vendors scrambling to up
this limit so that pages would appear to load faster in their
browsers, and then I think either 6 or 8 ended up being the consensus.

[1]
http://kb.mozillazine.org/Network.http.max-persistent-connections-per-server

- -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/

iEYEARECAAYFAk8XFlAACgkQ9CaO5/Lv0PC6qwCeIx7AjebjIRJkiHIuxMMunIru
W1sAoJ8EXmahtr/lxOHQld8A3+V679YD
=pGDE
-----END PGP SIGNATURE-----

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


Re: Multiple Comet Requests to the Same Server, from the Same Client

Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/1/18 William Speirs <ws...@apache.org>:
> I have a basic CometProcessor servlet implemented, and everything appears
> to work as expected, except for one small issue: I cannot make multiple
> requests from the same client to the same server.
>
> My servlet simply sends messages to the client as they come in (think of it
> as a one-sided chat, no POST). This works fine, except when I open a second
> browser to the same server from the same client, I do not see the "void
> event(CometEvent event)" method being called. The browser just sits and
> spins waiting to connect. However, if I connect from a second client (IP
> address), then the "void event(CometEvent event)" method is called, and the
> second client starts receiving messages.

The HTTP specification recommends to have no more than 2 active
connections to the same HTTP server. The web browsers usually respect
it.

IIRC "the same server" = the same DNS name, so different names have
different connection limits.

It should be already discussed elsewhere - try to search.

>
> It seems as though tomcat (or the comet filter) is limiting the number of
> connections from the same IP address. I have not tested this yet, but that
> would be an issue in NAT situations where all connections would appear to
> come from the same IP address. Thoughts?
>
> Running:
> tomcat-7.0.6

Too old.

> servlet-api-2.5.jar

Where?

> tomcat-*-7.0-SNAPSHOT

Does not make sense.

>
> Thanks...
>
> Bill-

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


Re: Multiple Comet Requests to the Same Server, from the Same Client

Posted by André Warnier <aw...@ice-sa.com>.
William Speirs wrote:
> I have a basic CometProcessor servlet implemented, and everything appears
> to work as expected, except for one small issue: I cannot make multiple
> requests from the same client to the same server.
> 
> My servlet simply sends messages to the client as they come in (think of it
> as a one-sided chat, no POST). This works fine, except when I open a second
> browser 

really a second, different browser ? or another window/tab from the same browser ?
(if the second case, it may be re-using the same local IP:port (or just the same 
established connection) to "connect" to the server, and that may explain why the server 
appears not to react.

Just a thought..  before digging further.

Note: I use "connect" between quotes, because I don't really know what would happen in 
such a scenario.  If in fact the second window just listens for received messages on that 
same connection, but the first window grabs everything already, something may get confused 
there... just like me for now.



to the same server from the same client, I do not see the "void
> event(CometEvent event)" method being called. The browser just sits and
> spins waiting to connect. However, if I connect from a second client (IP
> address), then the "void event(CometEvent event)" method is called, and the
> second client starts receiving messages.
> 
> It seems as though tomcat (or the comet filter) is limiting the number of
> connections from the same IP address. I have not tested this yet, but that
> would be an issue in NAT situations where all connections would appear to
> come from the same IP address. Thoughts?
> 
> Running:
> tomcat-7.0.6
> servlet-api-2.5.jar
> tomcat-*-7.0-SNAPSHOT
> 
> Thanks...
> 
> Bill-
> 


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


Re: Multiple Comet Requests to the Same Server, from the Same Client

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

William,

On 1/18/12 11:22 AM, William Speirs wrote:
> It seems as though tomcat (or the comet filter) is limiting the
> number of connections from the same IP address.

Have you discarded the browser as one of the components making these
kinds of decisions?

What does a tcp trace show 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/

iEYEARECAAYFAk8XFFMACgkQ9CaO5/Lv0PDMSgCeKeOWf+aP53AAUWfCWyQluA8m
t9UAn3XuLEAriJ3S597VHz8WH85jwxWb
=O3tn
-----END PGP SIGNATURE-----

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