2
votes

Everywhere i see, to disable nagle's algorithm, you can do it by service point after creating the storage account client. I have also read in several places that this only works if you do it before the first request.

In my case, my function (v2) uses bindings to storage account (both blob and table). So that means the first connection is done my the function and not my code so i'm wondering how i can disable this nagle's algorithm. Is there a setting for functions?

2

2 Answers

2
votes

The way to turn this off is by resetting the flag in ServicePointManager. The ServicePointManager is a .NET class that allows you to manage ServicePoint where each ServicePoint provides HTTP connection management. ServicePointManager also allows you to control settings like maximum connections, Expect 100, and Nagle for all ServicePoint instances. Therefore, if you want to turn Nagle off for just tables or just queues or just blobs in your application, you need to turn it off for the specific ServicePoint object in the ServicePointManager. Here is a code example for turning Nagle off for just the Queue and Table ServicePoints, but not Blob:

// 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;

For All blob/Table/Queue

you can just reset it at the very start of your application process by

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

Important Read below :

Turning Nagle off should be considered for Table and Queue (and any protocol that deals with small sized messages). For large packet segments, Nagling does not have an impact since the segments will form a full packet and will not be withheld. But as always, we suggest that you test it for your data before turning Nagle off in production.

Source : One Two

2
votes

So my finding is that we should use HariHaran's answer (section "For All blob/Table/Queue") in the function static constructor. Not sure this is the best way but it seems to have worked for me.

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

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

}