[Ace-users] Re: Leader/Follower Design Pattern Question

Peter pptaszek at autograf.pl
Mon Aug 13 08:18:21 CDT 2007


Douglas C. Schmidt wrote:
> 
>> Imagine, we have two connections open to our server, but only one of
>> them is active.  
> 
> I assume each connection has a separate socket handle in the server,
> i.e., there are two socket handles involved here, right?
Yes, you are right.

> 
>> I mean sends requests. Second connection is opened but sends no
>> requests now. Leader thread is handling first request from active
>> connection, deactivates socket from fdset. 
> 
> Just to make sure - there is still the second socket handle for the
> second connection that's still be waited for by poll(), right?
> 
Yes, these two socket handles are in fdset. Leader thread wakes up,
poll() indicates that appropriate socket in fdset is "Read Ready".
Then leader thread deactivates this socket in fdset. As I understand
until this socket is not activated, poll() will not return any new data
notification on this socket handle.

>> New leader is elected, waits for IO event. Second request from
>> active connection arrives, but leader still waits on poll(), because
>> socket related to active connection is deactivated until first
>> request is being processed.
> 
> Hum, I don't follow this - why would this occur since there should be
> two socket handles?
> 
Now, there is one deactivated socket handle (for active connection) and
active socket handle (for the second connection) in fdset. Even if new
request on active connection arrives It will not wake up new leader
thread waiting on poll(), because this socket handle is now deactivated
in fdset.

Going back to our example.
Now processing thread ends Its activities (handling first request) and 
should activate his socket handle in fdset in order to enable handling
of incoming subsequent request. But It is not able to activate his 
socket handle in fdset, because It's now acquired by leader polling
this fdset.

I assume that thread handles only one request per activation. I am not
sure If It is a valid assumption.

>> My question is, how and when this socket will be added to fdset?
>> Does It have to be delayed until data arrives to one of the sockets
>> being polled by current leader thread?
> 
> Assuming that each connection has a separate socket handle then things
> should work fine.  If you are multiplexing requests through a single
> socket hande then the second request will will not be processed until
> the first request is finished.
> 

Doug, thank you for comments.

Take care,
Peter


More information about the Ace-users mailing list