Where does Jetty dispatch to worker thread happens.

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Where does Jetty dispatch to worker thread happens.

Monish Gandhi
I am trying to understand Jetty's Connector implementation which uses multiple acceptor/selectors to have non blocking implementation. I saw a post from Simone where its explained very clearly http://dev.eclipse.org/mhonarc/lists/jetty-users/msg04751.html 

I could see the Jetty's  SelectorManager, AbstractConnector, ServerConnector implementing the same where we have n acceptor and m selector threads started. The acceptors are blocking on the ServerSocketChannels accept() call, each time when the socket connects, acceptor takes the socket and registers the channel with selector and submits the job to selector (ManagedSelector' ConcurrentArrayQueue) selector threads would poll the queue and run the changes. However i am somehow missing one thing, where is the actual dispatch happening to the Worker threads (the actual Server threads in QueuedThreadPool). Also let me know if I got some of above incorrectly

Thanks
Monish

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Where does Jetty dispatch to worker thread happens.

Simone Bordet-2
Hi,

On Fri, Oct 17, 2014 at 8:15 AM, Monish Gandhi <[hidden email]> wrote:

> I am trying to understand Jetty's Connector implementation which uses
> multiple acceptor/selectors to have non blocking implementation. I saw a
> post from Simone where its explained very clearly
> http://dev.eclipse.org/mhonarc/lists/jetty-users/msg04751.html
>
> I could see the Jetty's  SelectorManager, AbstractConnector, ServerConnector
> implementing the same where we have n acceptor and m selector threads
> started. The acceptors are blocking on the ServerSocketChannels accept()
> call, each time when the socket connects, acceptor takes the socket and
> registers the channel with selector and submits the job to selector
> (ManagedSelector' ConcurrentArrayQueue) selector threads would poll the
> queue and run the changes. However i am somehow missing one thing, where is
> the actual dispatch happening to the Worker threads (the actual Server
> threads in QueuedThreadPool). Also let me know if I got some of above
> incorrectly

The dispatch happens when calling SelectChannelEndPoint.onSelected()
-> getFillInterest().fillable().
This goes back to the callback that the Connection registered with the
EndPoint, AbstractConnection.ReadCallback.
Here, the state goes (typically) from FILL_INTERESTED to FILLING, and
AbstractConnection.FillingState is where the dispatch happens, calling
Connection.onFillable() in the dispatched thread.

--
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Where does Jetty dispatch to worker thread happens.

Monish Gandhi
Thanks Simone ! Also could you please confirm that the when socket connects and acceptor thread accepts the same, when does it go back to accepting new connections. Is it after registering ServerSocketChannel with selector and submitting to Selector queue (_changes.offer in SelectorManager.submit()). I assume the state in this SelectorManager.submit() in such case would be "PROCESS" and hence should come out immediately. 

 Is it ever possible that if my selectors are busy then my acceptor thread won't go back to accepting new connections?
Regards
Monish



On Friday, October 17, 2014 3:11 PM, Simone Bordet <[hidden email]> wrote:


Hi,

On Fri, Oct 17, 2014 at 8:15 AM, Monish Gandhi <[hidden email]> wrote:

> I am trying to understand Jetty's Connector implementation which uses
> multiple acceptor/selectors to have non blocking implementation. I saw a
> post from Simone where its explained very clearly
> http://dev.eclipse.org/mhonarc/lists/jetty-users/msg04751.html
>
> I could see the Jetty's  SelectorManager, AbstractConnector, ServerConnector
> implementing the same where we have n acceptor and m selector threads
> started. The acceptors are blocking on the ServerSocketChannels accept()
> call, each time when the socket connects, acceptor takes the socket and
> registers the channel with selector and submits the job to selector
> (ManagedSelector' ConcurrentArrayQueue) selector threads would poll the
> queue and run the changes. However i am somehow missing one thing, where is
> the actual dispatch happening to the Worker threads (the actual Server
> threads in QueuedThreadPool). Also let me know if I got some of above
> incorrectly

The dispatch happens when calling SelectChannelEndPoint.onSelected()
-> getFillInterest().fillable().
This goes back to the callback that the Connection registered with the
EndPoint, AbstractConnection.ReadCallback.
Here, the state goes (typically) from FILL_INTERESTED to FILLING, and
AbstractConnection.FillingState is where the dispatch happens, calling
Connection.onFillable() in the dispatched thread.

--
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.




_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Where does Jetty dispatch to worker thread happens.

Simone Bordet-2
Hi,

On Fri, Oct 17, 2014 at 5:39 PM, Monish Gandhi <[hidden email]> wrote:
> Thanks Simone ! Also could you please confirm that the when socket connects
> and acceptor thread accepts the same, when does it go back to accepting new
> connections. Is it after registering ServerSocketChannel with selector and
> submitting to Selector queue (_changes.offer in SelectorManager.submit()). I
> assume the state in this SelectorManager.submit() in such case would be
> "PROCESS" and hence should come out immediately.

When a connection is accepted, it is passed to
SelectorManager.accept(), that returns immediately so that a new
connection may be accepted.
The number of acceptors can be configured, and those will all compete
to accept connections (although only one will succeed).

>  Is it ever possible that if my selectors are busy then my acceptor thread
> won't go back to accepting new connections?

No, it's not possible.

--
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Where does Jetty dispatch to worker thread happens.

Monish Gandhi
Thanks Simone, I am trying to understand how does configuring more acceptor help. Suggested number is equal to number of cores. The Either ways multiple acceptor threads would compete but only one would succeed. Which means all acceptor threads would be in BLOCKED state (waiting to lock) and only one would be RUNNABLE.  
  
Regards
Monish



On Monday, October 20, 2014 6:16 PM, Simone Bordet <[hidden email]> wrote:


Hi,

On Fri, Oct 17, 2014 at 5:39 PM, Monish Gandhi <[hidden email]> wrote:
> Thanks Simone ! Also could you please confirm that the when socket connects
> and acceptor thread accepts the same, when does it go back to accepting new
> connections. Is it after registering ServerSocketChannel with selector and
> submitting to Selector queue (_changes.offer in SelectorManager.submit()). I
> assume the state in this SelectorManager.submit() in such case would be
> "PROCESS" and hence should come out immediately.

When a connection is accepted, it is passed to
SelectorManager.accept(), that returns immediately so that a new
connection may be accepted.
The number of acceptors can be configured, and those will all compete
to accept connections (although only one will succeed).

>  Is it ever possible that if my selectors are busy then my acceptor thread
> won't go back to accepting new connections?

No, it's not possible.


--
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.



_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Where does Jetty dispatch to worker thread happens.

Simone Bordet-2
Hi,

On Mon, Nov 3, 2014 at 9:23 PM, Monish Gandhi <[hidden email]> wrote:
> Thanks Simone, I am trying to understand how does configuring more acceptor
> help. Suggested number is equal to number of cores.

More acceptors are only useful for a very high rate of short lived connections.
Typically suggested number is 1, not the number of cores.
Don't confuse acceptors and selectors.

> The Either ways multiple
> acceptor threads would compete but only one would succeed. Which means all
> acceptor threads would be in BLOCKED state (waiting to lock) and only one
> would be RUNNABLE.

Correct.

--
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Where does Jetty dispatch to worker thread happens.

Monish Gandhi
Thanks Simone!
 I read the Jetty doc which suggests to keep acceptors equal to "one per cpu on a machine"

Either ways like you mentioned for high rate of short lived connections its good to have higher acceprtors (my case is such) and this really helps.

Regards
Monish


On Tuesday, November 4, 2014 3:30 AM, Simone Bordet <[hidden email]> wrote:


Hi,

On Mon, Nov 3, 2014 at 9:23 PM, Monish Gandhi <[hidden email]> wrote:
> Thanks Simone, I am trying to understand how does configuring more acceptor
> help. Suggested number is equal to number of cores.

More acceptors are only useful for a very high rate of short lived connections.
Typically suggested number is 1, not the number of cores.
Don't confuse acceptors and selectors.

> The Either ways multiple
> acceptor threads would compete but only one would succeed. Which means all
> acceptor threads would be in BLOCKED state (waiting to lock) and only one
> would be RUNNABLE.

Correct.


--
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.



_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users