Azure / Azure/DotNetty

Question on improving perfomance of tcp server

Open
#619 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.3k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

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()
.ChildHandler(new ActionChannelInitializer(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!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.