Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question on improving perfomance of tcp server #619

Open
adampolyanskiy opened this issue Dec 26, 2023 · 0 comments
Open

Question on improving perfomance of tcp server #619

adampolyanskiy opened this issue Dec 26, 2023 · 0 comments

Comments

@adampolyanskiy
Copy link

adampolyanskiy commented Dec 26, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant