我们创建了一些样本lambda来测试SQS插入性能。 最初,我们使用128MB lambdas,插入7KB数据包的平均时间为40ms。 当我们将lambda升级到256MB时,我们获得了20ms的平均时间;当我们升级到512MB时,我们甚至获得了11ms的平均插入时间。
我们想知道为什么更大的lambda内存/ cpu在SQS上获得更好的插入速度,因为我们认为sqs插入不应与内存或CPU容量相关。总结:sqs客户端发送操作中是否有任何需要良好CPU /内存才能更好执行的操作?
谢谢!
这是我们的测试代码: 公共类功能 {
public async Task<string> FunctionHandler(ILambdaContext context)
{
var client = new AmazonSQSClient();
var request = new SendMessageRequest
{
MessageAttributes = new Dictionary<string, MessageAttributeValue>(),
MessageBody = "7kbyte String here...",
QueueUrl = "https://our_account/sqs-test-queue "
};
//Just desconsidering the first 2 sent messages, to desconsider the initial connection overhead
var elapsed00 = await SendMessageResponse(client, request, -2);
var elapsed0 = await SendMessageResponse(client, request, -1);
double totalTime = 0;
const int totalIterations = 1000;
for (int j = 0; j < totalIterations; j++)
{
var elapsed = await SendMessageResponse(client, request, j);
totalTime += elapsed;
}
Console.WriteLine("$$$$$AVERAGE:" + ((double)(totalTime / totalIterations)));
return "End test";
}
private async Task<long> SendMessageResponse(AmazonSQSClient client, SendMessageRequest request, int i)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var response = await client.SendMessageAsync(request);
stopwatch.Stop();
//Console.WriteLine("&&&#####" + i + "Elapsed ms:" + stopwatch.ElapsedMilliseconds + ". For message ID '" +
// response.MessageId + "':");
i++;
return stopwatch.ElapsedMilliseconds;
}
}
答案 0 :(得分:1)
SQS的lambda大小没有什么不同,您在Lambda中运行的代码正在根据分配的内存/ CPU改变其性能。