2

在我看到的任何地方,要禁用 nagle 的算法,您可以在创建存储帐户客户端后通过服务点执行此操作。我还在几个地方读到,只有在你第一次请求之前这样做才有效。

就我而言,我的函数 (v2) 使用与存储帐户(blob 和表)的绑定。所以这意味着第一个连接是由我的函数而不是我的代码完成的,所以我想知道如何禁用这个 nagle 的算法。有功能设置吗?

4

2 回答 2

2

关闭它的方法是重置ServicePointManager. ServicePointManager 是一个 .NET 类,它允许您管理 ServicePoint,其中每个 ServicePoint 都提供 HTTP 连接管理。ServicePointManager 还允许您控制所有 ServicePoint 实例的最大连接数、Expect 100 和 Nagle 等设置。因此,如果您只想为应用程序中的表、队列或 blob 关闭 Nagle,则需要为 ServicePointManager 中的特定 ServicePoint 对象关闭它。以下是仅针对队列和表服务点(而不是 Blob)关闭 Nagle 的代码示例:

// cxnString = "DefaultEndpointsProtocol=http;AccountName=myaccount;AccountKey=mykey"
CloudStorageAccount account = CloudStorageAccount.Parse(cxnString);
ServicePoint tableServicePoint = ServicePointManager.FindServicePoint(account.TableEndpoint);
tableServicePoint.UseNagleAlgorithm = false;
ServicePoint queueServicePoint = ServicePointManager.FindServicePoint(account.QueueEndpoint);
queueServicePoint.UseNagleAlgorithm = false;

对于所有 blob/表/队列

您可以在申请流程开始时通过以下方式重置它

// This sets it globally for all new ServicePoints
ServicePointManager.UseNagleAlgorithm = false; 

重要阅读如下:

对于表和队列(以及任何处理小型消息的协议),应考虑关闭 Nagle。对于大数据包段,Nagling 没有影响,因为这些段将形成一个完整的数据包并且不会被保留。但与往常一样,我们建议您在生产环境中关闭 Nagle 之前测试您的数据。

来源一二

于 2019-09-19T04:23:19.700 回答
2

所以我的发现是我们应该在函数静态构造函数中使用 HariHaran 的答案(“For All blob/Table/Queue”部分)。不确定这是最好的方法,但它似乎对我有用。

public static class SampleFunction
{
    static SampleFunction()
    {
        ServicePointManager.UseNagleAlgorithm = false;
    }

    [FunctionName("SampleFunctionOperation1")]
    public static async Task<IActionResult> Operation1...

}
于 2019-09-19T13:20:39.647 回答