It is difficult to give performance tuning guidelines that will be generally applicable. Results may vary greatly depending on many factors such as bandwidth, latency, client version, and much more. As always with performance tuning: Measure, don't assume.
The Amazon SQS transport uses HTTPS connections to send and receive messages from AWS services. Network latency between the endpoint and SQS affects transport performance.
Parallel message retrieval
It is possible to increase the maximum concurrency to increase the throughput of a single endpoint. For more information about how to tune the endpoint message processing, consult the tuning guide.
The transport automatically adjusts receive parallelism based on the maximum concurrency. Each receive request fetches up to ten messages, limited by the maximum concurrency:
NumberOfMessagesToFetch = min(MaxConcurrency, 10)
DegreeOfReceiveParallelism = ceiling(MaxConcurrency / NumberOfMessagesToFetch)
In this formula, ceiling rounds the result of the division up to the nearest integer. The following examples illustrate how the formula applies to different concurrency limits:
MaxConcurrency | DegreeOfReceiveParallelism | NumberOfMessagesToFetch |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 1 | 3 |
| 4 | 1 | 4 |
| 5 | 1 | 5 |
| 6 | 1 | 6 |
| 7 | 1 | 7 |
| 8 | 1 | 8 |
| 9 | 1 | 9 |
| 10 | 1 | 10 |
| 19 | 2 | 10 |
| 21 | 3 | 10 |
| 100 | 10 | 10 |
Each parallel message retrieval requires one long polling connection.
Changing the maximum concurrency will influence the total number of operations against SQS and can result in higher costs.
Number of connections
A single endpoint requires multiple connections. The HTTP client infrastructure pools and reuses these connections. If requests exceed the connection limit, they wait for an available connection, which can reduce throughput.
Connection settings depend on the .NET runtime and AWS SDK HTTP implementation. Configure the SQS client or the SNS client as needed.
.NET Framework
On .NET Framework, the AWS SDK client configuration exposes the ConnectionLimit property, which defaults to 50. Alternatively, set ServicePointManager. during process startup.
During message handling an endpoint is expected to be able to connect to external resources, such as remote services via HTTP.
If the endpoint is hosted in a process outside IIS, such as a Windows Service, by default the .NET Framework allows 2 concurrent outgoing HTTP requests per process. This can be a limitation on the overall throughput of the endpoint itself that ends up having outgoing HTTP requests queued and, as a consequence, a limitation in its ability to process incoming messages.
It is possible to change the default connection limit of a process via the static DefaultConnectionLimit property of the ServicePointManager class, as in the following sample:
ServicePointManager.DefaultConnectionLimit = 10;
The above code can be placed in the process startup.
See ServicePointManager on MSDN for more information.
The preceding guidance applies to .NET Framework. On modern .NET, configure the HTTP handler used by the AWS SDK instead of relying on ServicePointManager.
Sending small messages
On .NET Framework, if the endpoint sends many small messages, it might be beneficial to disable Nagle's algorithm. Measure the effect before applying this change.
To disable Nagle's algorithm for a specific endpoint URI, use:
using System;
using System.Net;
var servicePoint = ServicePointManager.FindServicePoint(new Uri("sqs-endpoint-uri"));
servicePoint.UseNagleAlgorithm = false;
Replace sqs-endpoint-uri with the endpoint's absolute HTTPS URI. To find the endpoint URIs, consult the AWS Regions and Endpoints documentation.
To disable Nagle's algorithm for the application domain, use:
using System.Net;
ServicePointManager.UseNagleAlgorithm = false;
Known Limitations
The transport uses a single client for all operations on SQS. Its connection limit can therefore constrain endpoint throughput.