Multiple Producer for Netty + Disruptor game server

1,252 views
Skip to first unread message

Abraham Menacherry

unread,
May 29, 2012, 9:54:06 AM5/29/12
to lmax-di...@googlegroups.com
I have open sourced the following multiplayer game server which uses Netty. For event dispatch to player sessions, I would like to use disruptor. However I have the following queries.  
1) Netty has multiple worker threads which will decode the network message and send it to a player session. The sessions event dispatcher will take it and dispatch it to the appropriate event handler. If I use disruptor for event dispatch, then each worker thread becomes a producer. Are multiple producers allowed in disruptor? Are there any code samples showing multiple producers?   
2) If multiple producers are an anti-pattern, does anybody know how to make it single for Netty? I really dont want to write my own nio code.
3) Does anybody have code which uses Netty with disruptor so that I can use it for reference? Did you run into any perf issues that I should be aware of?
 
b.t.w awesome library! Thanks for opensourcing!

Toby DiPasquale

unread,
May 29, 2012, 12:39:04 PM5/29/12
to lmax-di...@googlegroups.com
You might have an issue combining the two since Netty uses different
IPC mechanisms underneath that would conflict with the Disruptor. What
might be better is to extend Netty itself to use Disruptor as its IPC
mechanism.

--
Toby DiPasquale

Michael Barker

unread,
May 29, 2012, 4:39:31 PM5/29/12
to lmax-di...@googlegroups.com
> 1) Netty has multiple worker threads which will decode the network message
> and send it to a player session. The sessions event dispatcher will take it
> and dispatch it to the appropriate event handler. If I use disruptor for
> event dispatch, then each worker thread becomes a producer. Are multiple
> producers allowed in disruptor? Are there any code samples showing multiple
> producers?

Multiple producers are allowed in the Disruptor. We have the
MultiThreadedClaimStrategy specifically for this purpose. This is the
default strategy, so you don't need to do anything special in order to
support multiple producers.

> 2) If multiple producers are an anti-pattern, does anybody know how to make
> it single for Netty? I really dont want to write my own nio code.

It's not an anti-pattern, however the SingleThreadedClaimStrategy does
performance better due to reduced contention. Unfortunately I don't
know enough about Netty in order to make it run with a single thread.

I'm currently working on some changes to improve the performance of
the multi producer case which should be included in the next release.

Mike.

Toby DiPasquale

unread,
May 29, 2012, 5:50:17 PM5/29/12
to lmax-di...@googlegroups.com
On Tue, May 29, 2012 at 4:39 PM, Michael Barker <mik...@gmail.com> wrote:
>> 2) If multiple producers are an anti-pattern, does anybody know how to make
>> it single for Netty? I really dont want to write my own nio code.
>
> It's not an anti-pattern, however the SingleThreadedClaimStrategy does
> performance better due to reduced contention.  Unfortunately I don't
> know enough about Netty in order to make it run with a single thread.
>
> I'm currently working on some changes to improve the performance of
> the multi producer case which should be included in the next release.

Its possible to run Netty with a single thread by setting both the
boss and worker executors to the same value, a fixedThreadPool of size
1. How this will actually work in practice, I don't know, since I no
of no one who's tried it ;-)

--
Toby DiPasquale

Abraham Menacherry

unread,
May 30, 2012, 2:34:50 AM5/30/12
to lmax-di...@googlegroups.com
Mike, Toby,
 
Thanks for the quick replies. Since multiple producers are allowed in Disruptor, I think Netty + Disruptor will not cause any issue. I will publish one to github and post it to group.
Toby pointed out that Netty has its own IPC, which is correct, I wouldnt want to mess around with that stuff, since it is supposedly the fastest NIO kid on the block, it should be fast enough for most usecases.

Ron King

unread,
Jul 16, 2012, 10:20:54 AM7/16/12
to lmax-di...@googlegroups.com

Ron King

unread,
Jul 16, 2012, 10:21:37 AM7/16/12
to lmax-di...@googlegroups.com
What's the license for your game server ? Apache, BSD?


On Tuesday, May 29, 2012 8:54:06 AM UTC-5, Abraham Menacherry wrote:
Reply all
Reply to author
Forward
0 new messages