Azure / Azure/DotNetty

The number of threads has been increasing and will not be released

Open
#448 11 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

I tried to use Netty as DTU TCP Server, but in the process of using it found that the number of threads has been slowly increasing with the running time, but at this time the number of online devices is very small, only about 1-5, why,
My configuration code is as follows

`public void Init(ServerOptions options,Func handler)
{
_options = options;
if (options.EventLoopCount > 0)
{
bossGroup = new MultithreadEventLoopGroup(options.EventLoopCount);
}
else
{
bossGroup = new MultithreadEventLoopGroup();
}
workerGroup = new MultithreadEventLoopGroup();
bootstrap = new ServerBootstrap();
bootstrap.Group(bossGroup, workerGroup);
bootstrap.Channel();

bootstrap.Option(ChannelOption.SoBacklog, _options.SoBacklog);
bootstrap.ChildOption(ChannelOption.RcvbufAllocator,new AdaptiveRecvByteBufAllocator(64,1048,65536));
bootstrap.Option(ChannelOption.TcpNodelay, true);
bootstrap.ChildOption(ChannelOption.SoKeepalive, false);
bootstrap.ChildHandler(new ActionChannelInitializer(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
//pipeline.AddLast(new IdleStateHandler(300, 300, 0));
if (options.ReadTimeout > 0)
{
pipeline.AddLast("ReadTimeout", new ReadTimeoutHandler(options.ReadTimeout));
}

pipeline.AddLast(handler());
}));
}`

Handler code :
` ///
/// socket字节流处理对象
///
public class SocketByteHandler: ChannelHandlerAdapter
{

readonly bool autoRelease;

public SocketByteHandler() : this(true)
{
}

protected SocketByteHandler(bool autoRelease)
{
this.autoRelease = autoRelease;
}

public bool AcceptInboundMessage(object msg) => msg is IByteBuffer;

public override void ChannelRead(IChannelHandlerContext ctx, object msg)
{
bool release = true;
try
{
if (this.AcceptInboundMessage(msg))
{
IByteBuffer imsg = (IByteBuffer)msg;
byte[] result = new byte[imsg.ReadableBytes];
imsg.ReadBytes(result);
this.ChannelRead0(ctx, result);
}
else
{
release = false;
ctx.FireChannelRead(msg);
}
}
finally
{
if (autoRelease && release)
{
ReferenceCountUtil.Release(msg);
}
}
}

protected virtual void ChannelRead0(IChannelHandlerContext ctx,byte[] msg)
{

}
public override void UserEventTriggered(IChannelHandlerContext context, object evt)
{
if(evt is IdleStateEvent)
{
Console.WriteLine(evt.ToString());
IdleStateEvent _event = (IdleStateEvent)evt;
if(_event.State== IdleState.AllIdle)
{
}
}
}
}`

![image](https://user-images.githubusercontent.com/9816794/49751850-83959d00-fce9-11e8-8348-d82623df8aeb.png)

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.