confused about concurrency of writes

"Trustin Lee (이희승)" trustin at gmail.com
Mon Mar 8 05:00:00 EST 2010


Thanks David for a great answer.  Let me add just a little bit.

A write() call is atomic.  For example, if a client calls
Channel.write("ABC"), the server will never get "BCA", "BAC", "CAB", or
"CBA".

Also, FrameDecoder and ReplayingDecoder doesn't require any synchronization.

Trustin

David Alves wrote:
> Hi
> 
> 	I've been working with frame encoders and decoders for a while.
> 	That wouldn't happen normally IMHO. Here are my thoughts
> 
> 	In a non multiplexed protocol Channel is an abstraction between a single client connection and the server. Messages from that client might come fragmented but not interleaved with messages from other clients has they have their own channel
> 	- the decoder (possibly a framedecoder) decodes the message, possibly in POJO form. For each client connection there is such a decoder.
> 	- the message is the passed along and (possibly) reaches the handler, again there is one for each client connection.
> 	So in a non-multiplexed protocol (one client-server socket pair per client) there is no possibility of messages being mixed up.	
> 
> 	In a multiplexed protocol, however (multiple clients writing to the same socket) this can happen and is up to you to demux the message.
> 
> 	In that particular example proof of what I'm saying is that the handler then sends the message to the other channels (other clients), i.e. each has its own channel, decoder and handler. The decoding process (get the bytes, decode and handle) is done by a single worker thread, which does the work and is then returned to the pool.
> 
> 	In my experience there isn't much synchronization overhead for non multiplexed protocols.
> 
> Regards
> David
> 
> 	
> 
> On Feb 26, 2010, at 8:18 PM, ChickenPants wrote:
> 
>> referring to:
>> http://www.jboss.org/file-access/default/members/netty/freezone/xref/3.2/org/jboss/netty/example/securechat/SecureChatServerHandler.html
>>
>> in messageReceived(...):
>>
>> It seems like there's nothing to prevent two chats messages from getting
>> mixed together.
>>
>> I'm about to embark on a port to Netty and would like to hear people's
>> experience on how do framing without lots of synchronization overhead.
>>
>> I would not want messages interspersed together but not sure what's the
>> right thing.
>>
>> Advice?
>>
>> thanks
>> -- 
>> View this message in context: http://n2.nabble.com/confused-about-concurrency-of-writes-tp4641583p4641583.html
>> Sent from the Netty User Group mailing list archive at Nabble.com.
>> _______________________________________________
>> netty-users mailing list
>> netty-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/netty-users
> 
> 
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users

-- 
what we call human nature in actuality is human habit
http://gleamynode.net/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100308/a1d290df/attachment.bin 


More information about the netty-users mailing list