Re: non blocking Websockets?

2012-06-03 Thread Christian Finckler

thank you mark. that was a great answer.

Am 03.06.2012 22:49, schrieb Mark Thomas:

On 03/06/2012 21:26, Christian Finckler wrote:

Am 03.06.2012 19:50, schrieb Mark Thomas:

On 31/05/2012 18:45, Christian Finckler wrote:

Am 31.05.2012 11:09, schrieb Mark Thomas:

On 31/05/2012 10:02, Christian Finckler wrote:

Hello,
as far I understood, the websocket implementation of tomcat is
using one
thread per client.
Is there also a possibility to configure it to use non blocking IO?

No. That has not yet been implemented. It shouldn't be too hard
provided
that non-blocking is used between messages and blocking is used during
messages. Obviously, the BIO connector will always use blocking.

Whoops. My bad. I implemented this already. NIO and APR/native will be
non-blocking between messages and have been since the first Tomcat
release to include WebSocket support. Note that all connectors will
block between the point the upgrade is started and the first message is
sent.

This was on my to-do list for a while and I simply forgot I had actually
implemented. Had I looked at the code first (like I just did) it would
have been clear that this was implemented.

Sorry for the mis-information.

Mark

Hello Mark,
you have confused me a bit. So there isn't one thread for each websocket
client used?

For the BIO connector it is always one thread<==>  one connection. You
cannot do non-blocking IO with the blocking IO connector.

For NIO and APR/native is:
  - as many connections as you like up to maxConnections
  - one thread<==>  WebSocket frame

The threads are taken from the connector's connection pool and are
returned once the WebSocket frame has been read.

Reads are non-blocking between frames but blocking during a frame (to
save having track detailed state between reads)

Writes are always blocking.

In short, if the client isn't sending any data, Tomcat doesn't allocate
a thread to read it. The poller monitors the connection and passes it to
a thread when there is a message to read.


If not. What are the configuration possibilities for that?

maxThreads, maxConnections on the connector just like HTTP.


And how to do it?

Use the NIO or APR/native connector and it just works.


Perhaps you can describe more deeply how you handle websockets in regard
of blocking/non blocking and thread handling?

See above. If you want more detail, look at the source code. I am not
going to translate that into pseudo code for you.

Mark

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




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



Re: non blocking Websockets?

2012-06-03 Thread Mark Thomas
On 03/06/2012 21:26, Christian Finckler wrote:
> Am 03.06.2012 19:50, schrieb Mark Thomas:
>> On 31/05/2012 18:45, Christian Finckler wrote:
>>>
>>> Am 31.05.2012 11:09, schrieb Mark Thomas:
 On 31/05/2012 10:02, Christian Finckler wrote:
> Hello,
> as far I understood, the websocket implementation of tomcat is
> using one
> thread per client.
> Is there also a possibility to configure it to use non blocking IO?
 No. That has not yet been implemented. It shouldn't be too hard
 provided
 that non-blocking is used between messages and blocking is used during
 messages. Obviously, the BIO connector will always use blocking.
>> Whoops. My bad. I implemented this already. NIO and APR/native will be
>> non-blocking between messages and have been since the first Tomcat
>> release to include WebSocket support. Note that all connectors will
>> block between the point the upgrade is started and the first message is
>> sent.
>>
>> This was on my to-do list for a while and I simply forgot I had actually
>> implemented. Had I looked at the code first (like I just did) it would
>> have been clear that this was implemented.
>>
>> Sorry for the mis-information.
>>
>> Mark
> Hello Mark,
> you have confused me a bit. So there isn't one thread for each websocket
> client used?

For the BIO connector it is always one thread <==> one connection. You
cannot do non-blocking IO with the blocking IO connector.

For NIO and APR/native is:
 - as many connections as you like up to maxConnections
 - one thread <==> WebSocket frame

The threads are taken from the connector's connection pool and are
returned once the WebSocket frame has been read.

Reads are non-blocking between frames but blocking during a frame (to
save having track detailed state between reads)

Writes are always blocking.

In short, if the client isn't sending any data, Tomcat doesn't allocate
a thread to read it. The poller monitors the connection and passes it to
a thread when there is a message to read.

> If not. What are the configuration possibilities for that?

maxThreads, maxConnections on the connector just like HTTP.

> And how to do it?

Use the NIO or APR/native connector and it just works.

> Perhaps you can describe more deeply how you handle websockets in regard
> of blocking/non blocking and thread handling?

See above. If you want more detail, look at the source code. I am not
going to translate that into pseudo code for you.

Mark

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



Re: non blocking Websockets?

2012-06-03 Thread Christian Finckler

Am 03.06.2012 19:50, schrieb Mark Thomas:

On 31/05/2012 18:45, Christian Finckler wrote:


Am 31.05.2012 11:09, schrieb Mark Thomas:

On 31/05/2012 10:02, Christian Finckler wrote:

Hello,
as far I understood, the websocket implementation of tomcat is using one
thread per client.
Is there also a possibility to configure it to use non blocking IO?

No. That has not yet been implemented. It shouldn't be too hard provided
that non-blocking is used between messages and blocking is used during
messages. Obviously, the BIO connector will always use blocking.

Whoops. My bad. I implemented this already. NIO and APR/native will be
non-blocking between messages and have been since the first Tomcat
release to include WebSocket support. Note that all connectors will
block between the point the upgrade is started and the first message is
sent.

This was on my to-do list for a while and I simply forgot I had actually
implemented. Had I looked at the code first (like I just did) it would
have been clear that this was implemented.

Sorry for the mis-information.

Mark

Hello Mark,
you have confused me a bit. So there isn't one thread for each websocket 
client used? If not. What are the configuration possibilities for that? 
And how to do it?
Perhaps you can describe more deeply how you handle websockets in regard 
of blocking/non blocking and thread handling?


Thank you,
Chris


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



Re: non blocking Websockets?

2012-06-03 Thread Mark Thomas
On 31/05/2012 18:45, Christian Finckler wrote:
> 
> 
> Am 31.05.2012 11:09, schrieb Mark Thomas:
>> On 31/05/2012 10:02, Christian Finckler wrote:
>>> Hello,
>>> as far I understood, the websocket implementation of tomcat is using one
>>> thread per client.
>>> Is there also a possibility to configure it to use non blocking IO?
>> No. That has not yet been implemented. It shouldn't be too hard provided
>> that non-blocking is used between messages and blocking is used during
>> messages. Obviously, the BIO connector will always use blocking.

Whoops. My bad. I implemented this already. NIO and APR/native will be
non-blocking between messages and have been since the first Tomcat
release to include WebSocket support. Note that all connectors will
block between the point the upgrade is started and the first message is
sent.

This was on my to-do list for a while and I simply forgot I had actually
implemented. Had I looked at the code first (like I just did) it would
have been clear that this was implemented.

Sorry for the mis-information.

Mark


>>
>> Mark
>>
>> -
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
> 
> Ok, if that is so easy, it should be done. I am developing an online
> game, in which the player dont send messages very often (max: ten
> messages per minute), but is is very important to get the messages of
> other players very fast. Thats why I want to use websockets. But now it
> would be sad, if I need multiple tomcat instances only for connection
> handling although the process handling itself is not very complicated
> (cpu and memory intensive).
> 
> Thank you,
> Chris
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 


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



RE: non blocking Websockets?

2012-05-31 Thread Filip Hanik (mailing lists)
You can achieve that right now. Use the NIO connector, And then set up the
write buffer:

 -Original Message-
> From: Christian Finckler [mailto:christian.finck...@gmx.de]
> Sent: Thursday, May 31, 2012 11:45 AM
> To: Tomcat Users List
> Subject: Re: non blocking Websockets?
> 
> 
> 
> Am 31.05.2012 11:09, schrieb Mark Thomas:
> > On 31/05/2012 10:02, Christian Finckler wrote:
> >> Hello,
> >> as far I understood, the websocket implementation of tomcat is using
> one
> >> thread per client.
> >> Is there also a possibility to configure it to use non blocking IO?
> > No. That has not yet been implemented. It shouldn't be too hard
> provided
> > that non-blocking is used between messages and blocking is used during
> > messages. Obviously, the BIO connector will always use blocking.
> >
> > Mark
> >
> > -
> > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> > For additional commands, e-mail: users-h...@tomcat.apache.org
> 
> Ok, if that is so easy, it should be done. I am developing an online
> game, in which the player dont send messages very often (max: ten
> messages per minute), but is is very important to get the messages of
> other players very fast. Thats why I want to use websockets. But now it
> would be sad, if I need multiple tomcat instances only for connection
> handling although the process handling itself is not very complicated
> (cpu and memory intensive).
> 
> Thank you,
> Chris
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org



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



Re: non blocking Websockets?

2012-05-31 Thread Christian Finckler



Am 31.05.2012 11:09, schrieb Mark Thomas:

On 31/05/2012 10:02, Christian Finckler wrote:

Hello,
as far I understood, the websocket implementation of tomcat is using one
thread per client.
Is there also a possibility to configure it to use non blocking IO?

No. That has not yet been implemented. It shouldn't be too hard provided
that non-blocking is used between messages and blocking is used during
messages. Obviously, the BIO connector will always use blocking.

Mark

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


Ok, if that is so easy, it should be done. I am developing an online 
game, in which the player dont send messages very often (max: ten 
messages per minute), but is is very important to get the messages of 
other players very fast. Thats why I want to use websockets. But now it 
would be sad, if I need multiple tomcat instances only for connection 
handling although the process handling itself is not very complicated 
(cpu and memory intensive).


Thank you,
Chris

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



Re: non blocking Websockets?

2012-05-31 Thread Mark Thomas
On 31/05/2012 10:02, Christian Finckler wrote:
> Hello,
> as far I understood, the websocket implementation of tomcat is using one
> thread per client.
> Is there also a possibility to configure it to use non blocking IO?

No. That has not yet been implemented. It shouldn't be too hard provided
that non-blocking is used between messages and blocking is used during
messages. Obviously, the BIO connector will always use blocking.

Mark

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