简体   繁体   English

计算并发Lambda函数执行的次数

[英]Counting the number of concurrent Lambda function executions

Based on what the AWS documentation says, by default each account can have 1000 concurrent Lambda functions executed at a time. 根据AWS文档的说明,默认情况下,每个帐户一次可以执行1000个并发Lambda函数。 Granted that this is a soft limitation and can be changed per request. 当然,这是一个软限制,可以根据请求进行更改。

Now, my question is how can you monitor your concurrent Lambda function executions anyway? 现在,我的问题是无论如何您如何监视并发的Lambda函数执行?

I'm assuming this should be done (somehow) using CloudWatch. 我假设这应该(使用某种方式)使用CloudWatch完成。 In the Metrics section of the CloudWatch, following this path: 在CloudWatch的“ 指标”部分中,遵循以下路径:

All > Lambda > Across All Functions

You can find a metric by the name ConcurrentExecutions . 您可以通过名称ConcurrentExecutions查找度量。 My bets are on this one but at the same time, I'm not getting the numbers based on the test I've done. 我敢打赌,但与此同时,我没有根据我做过的测试得出数字。 Before we get there, the values shown on the graph for this metric are not integers so I'm guessing I'm missing something here. 在我们到达那里之前,该指标在图表上显示的值不是整数,因此我想我在这里遗漏了一些东西。 But that's fine. 但这很好。 Let me tell you about the test I've conducted. 让我告诉您我已经进行的测试。

I have created a simple NodeJs script on an EC2 instance like this: 我在这样的EC2实例上创建了一个简单的NodeJs脚本:

const AWS = require('aws-sdk');
const https = require('https');

const sslAgent = new https.Agent({
    keepAlive: true,
    maxSockets: 200,
    rejectUnauthorized: true,
});
sslAgent.setMaxListeners(0);

AWS.config.update({
    region: 'us-east-1',
    httpOptions: {
        agent: sslAgent,
    },
});


const lambda = new AWS.Lambda();

function call() {
    return lambda.invoke({
        FunctionName: "test",
        Payload: JSON.stringify({
            wait: 5000,
        }),
    }).promise();
}

(async () => {
  let start = Date.now();
  const promises = [...Array(200).keys()].map(i => {
    return call(new Date(Date.now()).toISOString())
      .then(data => {
        console.log(`Success (${i})`);
      })
      .catch(err => {
        console.log(`Error (${i}): ${err}`);
      });
  });
  await Promise.all(promises);
  let end = Date.now();
  console.log((new Date(end - start).toISOString()).substr(11, 12));
})();

This script will call a Lambda function (called test ) 200 times without waiting for the individual calls to return. 该脚本将调用Lambda函数(称为test )200次,而无需等待单个调用返回。 On the server side, I have this code in a Lambda function: 在服务器端,我在Lambda函数中具有以下代码:

exports.handler = async (event, context, callback) => {
    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!'),
    };
    return new Promise((resolve) => {
        setTimeout(() => {
            callback(null, response);
            resolve();
        }, event.wait);
    });
};

This Lambda function will keep the caller hanging for the time passed as the input (in this case 5 seconds). 此Lambda函数将使调用者在输入所经过的时间中保持挂起状态(在这种情况下为5秒)。 I ran this test and verified that there were 200 instances of the Lambda function running at the same time. 我运行了此测试,并验证了同时运行200个Lambda函数实例。 And I verified this by going to CloudWatch and looking into generated logs and there were 200 Log Streams generated (each execution has a separate Log Stream). 我通过转到CloudWatch并查看生成的日志来验证了这一点,并生成了200个日志流(每个执行都有一个单独的日志流)。

But when I go the mentioned Metric, the graph shows only a 68.7 which first of all is a bizarre number to show and secondly, it's not 200. So what is this number and where can I find my 200? 但是,当我提到上述Metric时,该图仅显示68.7 ,首先显示的是一个奇异的数字,其次不是200。那么这个数字是什么,我在哪里可以找到200?

By asking AWS support the same question, I've got the answer. 通过向AWS支持人员询问相同的问题,我得到了答案。 In CloudWatch, when you select a metric, it will look something like this: 在CloudWatch中,当您选择一个指标时,它将看起来像这样:

在此处输入图片说明

Previously, I had completely missed the Statistic column for a metric. 以前,我完全错过了指标的“统计”列。 Apparently, you have different options here and the one that helped me find the concurrent number of executions was Maximum . 显然,您在这里有不同的选择,可以帮助我找到并发执行次数的选择是Maximum

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何使用 boto3 在 AWS lambda 中获得最大并发执行数、最小值和平均值 - How do i get the maximum number of concurrent executions,minimum and average in AWS lambda using boto3 有没有人在 lambda 中不得不超过 1000 个并发执行? - Has anyone ever had to exceed 1000 concurrent executions in lambda? 如何以秒为单位监控 Lambda 并发执行(或找到更好的解决方案来限制 Lambda 并发执行)? - How Could I Monitor Lambda Concurrent Executions on a Second-by-Second Basis (or Find a Better Solution to Limit Lambda ConcurrentExecutions)? 如何执行N个Lambda函数的并发实例 - How to execute N concurrent instances of a lambda function 每个事件触发器的 Lambda 函数并发调用 - Lambda function concurrent invocation per event trigger AWS lambda function 实施中的 Concurrent.futures - Concurrent.futures in AWS lambda function implementation 限制AWS Data Pipeline上的并发执行 - Limit concurrent executions on AWS Data Pipeline lambda function 的 RAM 是用于一次调用还是所有并发调用? - Is the RAM for a lambda function for one invocation or all concurrent invocations? 如何在并发 AWS lambda 函数中管理 Postgres 连接? - How to manage Postgres connection in concurrent AWS lambda function? AWS Lambda /tmp 文件夹不在执行之间共享 - AWS Lambda /tmp folder is not shared between executions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM