Newbie Questions

Trustin Lee tlee at redhat.com
Wed Mar 18 02:59:08 EDT 2009


Hi Henry,

Sorry that I'm late first of all.

On Wed, Mar 11, 2009 at 5:04 PM, Trang <haiyun_wang at yahoo.com> wrote:
> I am a old mina user.However,i was wondering why you vanished from mina
> until i found out you were here.It is nice to see you again.

Great that you've found Netty again! :)

> I want to start to try Netty because i saw the performance comparsion and
> the Netty api seems more neat(naming,functions) to me.Most
> important thing is,you, trustin.You always can answer peoples'question in
> detail and more hit the point.Thanks.

You made my day! ;)

> After i browse the api roughly,I had some questions before I switched from
> Mina to Netty.
>
> 1) Netty pipeline(i prefer pipeline to filter :)) has the boardcasting
> pipeline? The one can do the encode and boardcast to all the channels.
> Normally I did this in mina is do a for loop to send the same message to all
> N sessions(N times encode).

Actually ChannelHandler is the counterpart of IoFilter.
ChannelPipeline is the counterpart of IoFilterChain.  So, to rephrase
your question, it's 'does Netty has broadcasting handler?'

The answer is not yet unfortunately.  You can work around this problem
simply by encoding the message once and write the buffer to all
channels:

    EncoderEmbedder<ChannelBuffer> encoder = new
EncoderEmbedder<ChannelBuffer>(new MyEncoder());
    encoder.offer(message);
    ChannelBuffer encodedMessage = encoder.poll();

    ChannelGroup channelsToReceiveBroadcast = ...;
    channelsToReceiveBroadcast.write(encodedMessage);

(BTW, the curreht ChannelGroup implementation has a bug related with
the code above.  You will have to download the nightly build.)

For the detailed instruction on using ChannelGroup, please refer to
the user guide.

> 2) The read idle and write idle methods are really important in mina which
> could perform with heartbeat(ping) function perfectly.However,Netty's read
> timeout
> pipeline function seems only in the beta version.Is it stable?

Christian (the former MINA user, too) contributed a lot of his time
testing it, so I think it's fairly stable.

> 3) How does write time out really work in Netty?It is really important
> feature since the server must deal with the slow networking client.

Well, if you insert the WriteTimeoutHandler into the pipeline, it will
raise an exception when your write request didn't complete within a
certain amount of time, just like what usual timeout mechanisms do.
You might want to play with the WriteTimeoutHandler.

> 4) How does Netty handle the internal queue which means how to prevent from
> OOM issue and fast writing(slow networking client) or reading.

Channel.isWritable() returns false when you should stop writing.  You
will be notified with channelInterestChanged() event, and then you can
check if Channel.isWritable() still returns false.  If it returns
true, you can continue writing.

> The above questions are all based on my real case.Thanks a lot
> again.Trustin.Good job.

Thanks for the great questions.  It would have been even better if you
asked the questions one by one in a different message.  Could you if
you have a chance to ask another question? :)

— Trustin Lee, http://gleamynode.net/




More information about the netty-users mailing list