The SDK is now the bottleneck in several of our systems, the dotnet ecosystem kept getting faster, fleshing out this issue more and more.
We are writing some custom implementations of the clients because the performance of the SDK is not acceptable for some of our workloads, greatly increasing the cost to use AWS services.
I propose that performance tests be included in your development pipeline.
Here is a sample trace from the S3 client as an exemple of the problems that permeate the SDK:
You can see that 20% of the CPU time spent sending this get request is at:
public static bool IsAmazonS3Endpoint(Uri uri)
{
Match match = !(uri == (Uri) null) ? new Regex("^(.+\\.)?s3[.-]([a-z0-9-]+)\\.").Match(uri.Host) : throw new ArgumentNullException(nameof (uri));
return (uri.Host.EndsWith("amazonaws.com", StringComparison.OrdinalIgnoreCase) || uri.Host.EndsWith("amazonaws.com.cn", StringComparison.OrdinalIgnoreCase)) && match.Success;
}
Every request runs this code.
Thinking about this, few things to try:
Regex
as a constant field in AmazonS3Uri
RegexOptions.Compilex
or Regex.CompileToAssembly
(Best Practicies)IsAmazonS3Endpoint
with MethodImplOptions.AggressiveInlining
And looking further up the stack at AmazonS3KmsHandler.EvaluateIfSigV4Required
, looks like we parses the request
twice? We first check AmazonS3Uri.IsAmazonS3Endpoint(request)
and then call new AmazonS3Uri(request)
which repeats the Regex match.
We may be able to rework AmazonS3KmsHandler.EvaluateIfSigV4Required
to reduce the duplicate match?
public class AmazonS3KmsHandler
{
// try and reduce duplicate input checking
internal static void EvaluateIfSigV4Required(IRequest request)
{
// Skip this for S3-compatible storage provider endpoints
if (request.OriginalRequest is S3.Model.GetObjectRequest &&
AmazonS3Uri.TryParseAmazonS3Uri(request.Endpoint, out var amazonS3Uri)) &&
amazonS3Uri.Region != RegionEndpoint.USEast1)
{
request.UseSigV4 = true;
}
}
}
Though, looking at AmazonS3Uri.TryParseAmazonS3Uri
, that also will end up running a Regex check twice; but that feels like the better place to fix that problem.
We've run into similar issues, and found that using pre-signed urls have alleviated a lot of the issues in case that helps @Rodrigo-Andrade
Regards,
Indy
Performance improvements are available in AWSSDK.S3 3.5.1.9
Most helpful comment
Performance improvements are available in
AWSSDK.S3 3.5.1.9