Skip to content

Question on improving perfomance of tcp server #619

@adampolyanskiy

Description

@adampolyanskiy

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.

  • The TCP server is set up using the ServerBootstrap class.
  • Upon receiving a message on the UDP socket, I use the following method to write to the TCP channel:
context.Channel.EventLoop.Execute(() =>
{
    context.WriteAndFlushAsync(Unpooled.WrappedBuffer(recvBuffer));
});
  • Expected Behavior: The messages should be sent to the TCP channel without significant delay.
  • Actual Behavior: The messages are experiencing delays, sometimes being sent only once every few seconds and by batches, which is much slower than expected.

Attempts to Resolve:

  • Ensured that WriteAndFlushAsync is called within the channel's event loop using Execute.
  • Checked for blocking operations and system resource constraints.

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions