Code Monkey home page Code Monkey logo

Comments (15)

fanliang11 avatar fanliang11 commented on May 11, 2024

surging 使用的是netty ,netty用的socket, 我记得Socket.ReceiveBufferSize默认大小应该是1024*8字节
如果超过了netty 应该会分成多个进行传输,如果要修改传输的限制大小,可以设置netty的bootstrap.Option(ChannelOption.SoRcvbuf, 1024 * 100)
surging 下版本增加配置,会把这些选项放到配置文件中。

from surging.

daofenglg avatar daofenglg commented on May 11, 2024

收到,谢谢您

from surging.

daofenglg avatar daofenglg commented on May 11, 2024

private static Bootstrap GetBootstrap()
{
var bootstrap = new Bootstrap();
bootstrap
.Channel()
.Option(ChannelOption.SoRcvbuf, 1024 * 100)
.Option(ChannelOption.TcpNodelay, true)
.Option(ChannelOption.Allocator, PooledByteBufferAllocator.Default)
.Group(new MultithreadEventLoopGroup(1));

        return bootstrap;
    }

我将bootstrap.Option(ChannelOption.SoRcvbuf, 1024 * 100)添加后问题依旧,我请求30-40条数据时,数据大小为30+K 是可以的,数据增加到50条数据时,报请求超时,在网关处没有收到服务器返回的数据信息

异常: 捕获了异常: Surging.Core.CPlatform.dll 中的“System.OperationCanceledException”(“请求超时”). 捕获了异常: Surging.Core.CPlatform.dll 中的“System.OperationCanceledException”(“请求超时”)	202.49 秒		[17920] 工作线程 

from surging.

fanliang11 avatar fanliang11 commented on May 11, 2024

@daofenglg 是在client 端加的吗?这个文件中的代码 DotNettyTransportClientFactory

from surging.

daofenglg avatar daofenglg commented on May 11, 2024

是的 `
///


/// 基于DotNetty的传输客户端工厂。
///

public class DotNettyTransportClientFactory : ITransportClientFactory, IDisposable
{
#region Field

    private readonly ITransportMessageEncoder _transportMessageEncoder;
    private readonly ITransportMessageDecoder _transportMessageDecoder;
    private readonly ILogger<DotNettyTransportClientFactory> _logger;
    private readonly IServiceExecutor _serviceExecutor;
    private readonly ConcurrentDictionary<EndPoint, Lazy<ITransportClient>> _clients = new ConcurrentDictionary<EndPoint, Lazy<ITransportClient>>();
    private readonly Bootstrap _bootstrap;

    private static readonly AttributeKey<IMessageSender> messageSenderKey = AttributeKey<IMessageSender>.ValueOf(typeof(DotNettyTransportClientFactory), nameof(IMessageSender));
    private static readonly AttributeKey<IMessageListener> messageListenerKey = AttributeKey<IMessageListener>.ValueOf(typeof(DotNettyTransportClientFactory), nameof(IMessageListener));
    private static readonly AttributeKey<EndPoint> origEndPointKey = AttributeKey<EndPoint>.ValueOf(typeof(DotNettyTransportClientFactory), nameof(EndPoint));

    #endregion Field

    #region Constructor

    public DotNettyTransportClientFactory(ITransportMessageCodecFactory codecFactory, ILogger<DotNettyTransportClientFactory> logger)
        : this(codecFactory, logger, null)
    {
    }

    public DotNettyTransportClientFactory(ITransportMessageCodecFactory codecFactory, ILogger<DotNettyTransportClientFactory> logger, IServiceExecutor serviceExecutor)
    {
        _transportMessageEncoder = codecFactory.GetEncoder();
        _transportMessageDecoder = codecFactory.GetDecoder();
        _logger = logger;
        _serviceExecutor = serviceExecutor;
        _bootstrap = GetBootstrap();

        _bootstrap.Handler(new ActionChannelInitializer<ISocketChannel>(c =>
        {
            var pipeline = c.Pipeline;
            pipeline.AddLast(new LengthFieldPrepender(4));
            pipeline.AddLast(new LengthFieldBasedFrameDecoder(int.MaxValue, 0, 4, 0, 4));
            pipeline.AddLast(new TransportMessageChannelHandlerAdapter(_transportMessageDecoder));
            pipeline.AddLast(new DefaultChannelHandler(this));
        }));
    }

    #endregion Constructor

    #region Implementation of ITransportClientFactory

    /// <summary>
    /// 创建客户端。
    /// </summary>
    /// <param name="endPoint">终结点。</param>
    /// <returns>传输客户端实例。</returns>
    public ITransportClient CreateClient(EndPoint endPoint)
    {
        var key = endPoint;
        if (_logger.IsEnabled(LogLevel.Debug))
            _logger.LogDebug($"准备为服务端地址:{key}创建客户端。");
        try
        {
            return _clients.GetOrAdd(key
                , k => new Lazy<ITransportClient>(() =>
                {
                    var bootstrap = _bootstrap;
                    var channel = bootstrap.ConnectAsync(k).Result;
                    var messageListener = new MessageListener();
                    channel.GetAttribute(messageListenerKey).Set(messageListener);
                    var messageSender = new DotNettyMessageClientSender(_transportMessageEncoder, channel);
                    channel.GetAttribute(messageSenderKey).Set(messageSender);
                    channel.GetAttribute(origEndPointKey).Set(k);
                    var client = new TransportClient(messageSender, messageListener, _logger, _serviceExecutor);
                    return client;
                }
                )).Value;
        }
        catch
        {
            _clients.TryRemove(key, out var value);
            throw;
        }
    }

    #endregion Implementation of ITransportClientFactory

    #region Implementation of IDisposable

    /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
    public void Dispose()
    {
        foreach (var client in _clients.Values.Where(i => i.IsValueCreated))
        {
            (client.Value as IDisposable)?.Dispose();
        }
    }

    #endregion Implementation of IDisposable

    private static Bootstrap GetBootstrap()
    {
        var bootstrap = new Bootstrap();
        bootstrap
            .Channel<TcpSocketChannel>()
            .Option(ChannelOption.SoRcvbuf, 1024 * 100)
            .Option(ChannelOption.TcpNodelay, true)
            .Option(ChannelOption.Allocator, PooledByteBufferAllocator.Default)
            .Group(new MultithreadEventLoopGroup(1));

        return bootstrap;
    }

    protected class DefaultChannelHandler : ChannelHandlerAdapter
    {
        private readonly DotNettyTransportClientFactory _factory;

        public DefaultChannelHandler(DotNettyTransportClientFactory factory)
        {
            this._factory = factory;
        }

        #region Overrides of ChannelHandlerAdapter

        public override void ChannelInactive(IChannelHandlerContext context)
        {
            _factory._clients.TryRemove(context.Channel.GetAttribute(origEndPointKey).Get(), out var value);
        }

        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            var transportMessage = message as TransportMessage;

            var messageListener = context.Channel.GetAttribute(messageListenerKey).Get();
            var messageSender = context.Channel.GetAttribute(messageSenderKey).Get();
            messageListener.OnReceived(messageSender, transportMessage);
        }

        #endregion Overrides of ChannelHandlerAdapter
    }
}`

from surging.

fanliang11 avatar fanliang11 commented on May 11, 2024

你试试再设置下Socket.SendBufferSize,通过以下代码设置
.Option(ChannelOption.SoSndbuf, 1024*100)

from surging.

daofenglg avatar daofenglg commented on May 11, 2024

还是不可以,我跟了一下程序 服务端的数据已经返回大概在40K左右,但在客户端没有收到数据
断点:Surging.Core\Surging.Core.DotNetty\DotNettyTransportClientFactory.cs->ChannelRead 没有进入,程序最后在TransportClient->RegisterResultCallbackAsync->var result = await task.Task; 最后由于超时退出 WithCancellation

from surging.

fanliang11 avatar fanliang11 commented on May 11, 2024

你不要调试啊,这是异步的。你先看下能不能调用

from surging.

daofenglg avatar daofenglg commented on May 11, 2024

断点去掉,还是不可以正常返回

from surging.

daofenglg avatar daofenglg commented on May 11, 2024

我在类(DefaultChannelHandler)中添加了方法
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception) { Console.WriteLine("Exception: " + exception); context.CloseAsync(); }
捕获到的异常为negative pre-adjustment length field: -32120
at DotNetty.Codecs.LengthFieldBasedFrameDecoder.Decode(IChannelHandlerContext context, IByteBuffer input)
at DotNetty.Codecs.LengthFieldBasedFrameDecoder.Decode(IChannelHandlerContext context, IByteBuffer input, List1 output) at DotNetty.Codecs.ByteToMessageDecoder.CallDecode(IChannelHandlerContext context, IByteBuffer input, List1 output)
at DotNetty.Codecs.ByteToMessageDecoder.ChannelRead(IChannelHandlerContext context, Object message)
at DotNetty.Transport.Channels.AbstractChannelHandlerContext.InvokeChannelRead(Object msg)

from surging.

fanliang11 avatar fanliang11 commented on May 11, 2024

我晚上来测试下,明天答复您

from surging.

daofenglg avatar daofenglg commented on May 11, 2024

好的,谢谢您,您辛苦了

from surging.

fanliang11 avatar fanliang11 commented on May 11, 2024

不辛苦,有人用我非常高兴,我知道的就有几个,这几天都在提问题

from surging.

896722590 avatar 896722590 commented on May 11, 2024

@fanliang11 同样关注这个问题。我处理的是一些格点数据,经过lz4压缩后,还有4M左右。是修改
options.Limits.MaxRequestBufferSize
还是
options.Limits.MaxResponseBufferSize

还是bodyszie

from surging.

fanliang11 avatar fanliang11 commented on May 11, 2024

这是dotnetty 0.4.7版本的bug,最新版本已经修复,经过测试发送40mb可以成功,这是我之前的提问Azure/DotNetty#341

from surging.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.