Azure / DotNetty

DotNetty project – a port of netty, event-driven asynchronous network application framework
Other
4.07k stars 971 forks source link

Question on improving perfomance of tcp server #619

Open adampolyanskiy opened 8 months ago

adampolyanskiy commented 8 months ago

Hello DotNetty Team,

I am experiencing an issue with delayed message sending when attempting to write to a TCP channel from a separate UDP listener thread in my application. The setup involves a DotNetty TCP server and a UDP listener running on different threads. The UDP listener is designed to receive messages and then send them through the TCP channel.

context.Channel.EventLoop.Execute(() =>
{
    context.WriteAndFlushAsync(Unpooled.WrappedBuffer(recvBuffer));
});

Attempts to Resolve:

I am trying to send live audio, so 5-10 seconds delay, which I am experiencing are not acceptable. I know that when writing is done on other thread than eventloop's, it is scheduled and not done immediately. Is there a way to make something here?

Here is the way I boostrap the server.

var bootstrap = new ServerBootstrap()
    .Group(acceptorGroup, workerGroup)
    .Channel<TcpServerSocketChannel>()
    .ChildHandler(new ActionChannelInitializer<ISocketChannel>(channel =>
    {
        var handler = new ChannelHandler(
            _loggerFactory,
            _listenerOptions.DeviceRegistry,
            _listenerOptions.CallHostOptions,
            _messageFactory);

        channel.Pipeline.AddLast(handler);
    }))
    .ChildOption(ChannelOption.TcpNodelay, true);

Thank you for your time and help!