简体   繁体   English

Google Cloud Functions和AWS Lambda上的超时问题

[英]Timeout issues on Google Cloud Functions and AWS Lambda

We are using NodeJS to process long transcripts using the Google Speech-to-Text API. 我们使用NodeJS使用Google Speech-to-Text API处理长成绩单。 Many of the functions take over 10 minutes to process. 许多功能需要10多分钟才能完成。 The usual ratio of processing/audio time is around 50%. 通常的处理/音频时间比率约为50%。 So a 20 minute FLAC audio file takes around 10 minutes to process (therefore failing on Google Cloud Functions, max time is 540 seconds or 9 minutes) and anything over 29 minutes fails at AWS Lambda. 因此,20分钟的FLAC音频文件需要大约10分钟才能处理(因此Google云端功能失败,最长时间为540秒或9分钟),AWS Lambda的任何超过29分钟的失败都会失败。

Which service is available on each platform to process audio files over 20/30 minutes, which also allows event data to be sent and invoke the application? 每个平台上有哪些服务可以在20/30分钟内处理音频文件,这也允许发送事件数据并调用应用程序? Hoew can I use a mix of cloud functions and another platform to process transcripts? Hoew可以使用云功能和另一个平台来处理成绩单吗?

I don't know another cloud provider than AWS, so I'll answer based on AWS. 我不知道另一个云提供商而不是AWS,所以我将基于AWS回答。 I always use AWS Lambda whenever I can except when the running time is greater than 15 minutes. 除非运行时间超过15分钟,否则我总是尽可能使用AWS Lambda。 In this case, I use AWS Batch ( AWS Batch – Run Batch Computing Jobs on AWS ). 在这种情况下,我使用AWS BatchAWS Batch - 在AWS上运行批量计算作业 )。

You can also use AWS Fargate , but you'll have to configure clusters and a docker image. 您也可以使用AWS Fargate ,但您必须配置群集和泊坞窗图像。

EDIT 1: 编辑1:

Batch can be sent events via API Gateway like you would to Lambda I assume? 批处理可以通过API网关发送事件,就像我认为Lambda一样?

I've never triggered a Batch Job via API Gateway directly (I don't know if this is possible). 我从未直接通过API网关触发批处理作业(我不知道这是否可行)。 I've always used API Gateway to trigger a Lambda and Lambda trigger Batch (check out this workflow , please, to have a better idea). 我一直使用API​​网关来触发Lambda和Lambda触发器批处理(请查看此工作流程 ,以便更好地了解)。

Also, you may use AWS CloudWatch events to trigger an AWS Batch Job. 此外,您可以使用AWS CloudWatch事件来触发AWS Batch作业。 For instance, if you upload a file to S3 before transcript, you may trigger AWS Batch Job by S3 events (check out this step by step , please). 例如,如果您在成绩单之前将文件上传到S3,则可以通过S3事件触发AWS Batch Job(请逐步查看此步骤 )。

How simple is it to convert a zipped Lambda function to a AWS Fargate image? 将压缩的Lambda函数转换为AWS Fargate图像有多简单?

It's no so difficult if you know about Docker, AWS ECR and ECS clusters. 如果您了解Docker,AWS ECR和ECS集群,那就不那么困难了。

  1. First, you need to create a Docker image with your source code. 首先,您需要使用源代码创建Docker镜像。 Check out this step by step , please. 一步一步查看。 Basically, you'll unzip your code, copy to the docker image, run npm install and run a command in a Dockerfile. 基本上,您将解压缩代码,复制到docker镜像,运行npm install并在Dockerfile中运行命令。

  2. After that, you may create an AWS ECR in which you'll upload your Docker image. 之后,您可以创建一个AWS ECR,在其中上传Docker镜像。

  3. Create an AWS ECS cluster 创建AWS ECS群集

  4. Create an AWS Fargate task 创建AWS Fargate 任务

  5. Finally, run the task via Lambda. 最后,通过Lambda运行任务。

If you don't have experience with Docker and AWS Fargate, AWS Batch is easier to implement. 如果您没有使用Docker和AWS Fargate的经验,AWS Batch更容易实现。

You might take a look at Architecture for using Cloud Pub/Sub for long-running tasks and Cloud Speech-to-Text as part of Google solutions. 您可以查看架构,以便将Cloud Pub / Sub用于长期运行的任务 ,将Cloud Speech-to-Text用作Google解决方案的一部分。

In the first link explains the architecture and workflow for how to use Cloud Pub/Sub as a queuing system for processing potentially long-running tasks (automatic transcription of audio files as an example). 在第一个链接中解释了如何使用Cloud Pub / Sub作为排队系统来处理可能长时间运行的任务(作为示例的自动转录音频文件)的体系结构和工作流程。

Talking about Cloud Speech-to-Text, enables easy integration of Google speech recognition technologies into developer applications. 谈论云语音到文本,可以轻松地将Google语音识别技术集成到开发人员应用程序中。 Send audio and receive a text transcription from the Speech-to-Text API service. 发送音频并从Speech-to-Text API服务接收文本转录。

Use asynchronous requests instead of synchronous ones. 使用异步请求而不是同步请求。 Your current workflow involves requesting a speech-to-text task and then blocking until the API responds. 您当前的工作流程涉及请求语音到文本任务,然后阻止,直到API响应。 On top of the timeout problem you've outlined there's a problem of extra costs: you end up paying for Lambda invocation time for however long the speech-to-text API spends processing your request, ie, you're paying for Lambda doing essentially nothing. 除了超时问题之外,您已经概述了存在额外成本的问题:无论语音到文本API花费多长时间处理您的请求,您最终都要为Lambda调用时间付费,也就是说,您正在为Lambda支付基本费用没有。

In an asynchronous workflow you send a request and the API responds right away with an operation identifier. 在异步工作流程中,您发送请求,API会立即响应操作标识符。 The Lambda function can terminate at this point while the speech-to-text API proceeds processing your task in the background. Lambda函数可以在此时终止,而语音到文本API继续在后台处理您的任务。 Now you can either use the operation identifier to poll for task completion (using a scheduled Cloud Function , for example), or in case of AWS Polly use the SnsTopicArn or OutputS3BucketName properties to fire off another Lambda upon task completion. 现在,您可以使用操作标识符轮询任务完成(例如,使用计划的云功能 ),或者在AWS Polly的情况下使用SnsTopicArnOutputS3BucketName属性在任务完成时触发另一个Lambda。

Check the AWS and GCP API docs on asynchronous requests for more info. 有关更多信息,请查看有关异步请求的AWSGCP API文档。 Also, AWS provides more in-depth docs on asynchronous audio processing here and here . 此外,AWS提供异步音频处理更深入的文档在这里这里

In the case of AWS, use AWS Batch with AWS Lambda and API Gateway. 对于AWS,请将AWS Batch与AWS Lambda和API Gateway一起使用。

If you want to go on Docker and want to stay serverless, use AWS Fargate . 如果您想继续使用Docker并希望保持无服务器,请使用AWS Fargate

You can also use AWS CodeBuild with AWS Lambda and API Gateway as a serverless execution service as it gives 8 hours of the timeout but that is not recommended as it is an exploitation of the service. 您还可以将AWS CodeBuild与AWS Lambda和API Gateway一起用作无服务器执行服务,因为它提供了8小时的超时,但不建议这样做,因为它是对服务的利用。

I guess for this particuallar problem is the easiest solution really to split the file in nodejs to sentences. 我想这个特殊问题是将nodejs中的文件拆分成句子的最简单的解决方案。 Send these sentences step by step to the lambda function. 将这些句子逐步发送到lambda函数。 And play the results behind each other or combine the result. 并将结果发挥到彼此之后或结合结果。 The Problem here is that breaks between sentences or words ( depends on split) and things like that can be lost. 这里的问题是句子或单词之间的断裂(取决于分裂)和类似的东西可能会丢失。 So there is some logik necessary how to split them. 所以有一些logik必须如何拆分它们。 The advantage is that you can get faster an result. 优点是您可以更快地获得结果。 So the first part can be played while the last is still loading. 所以第一部分可以在最后一个仍在加载时播放。

Of course the batch job suggestion will also work. 当然批处理作业建议也可以。 But than you need the way back async to nodeJS after 20/30 min. 但是你需要在20/30分钟后返回与nodeJS同步的方式。 Or you store it on s3 and just request it from s3 when needed after the batch job is somewhen finished. 或者您将它存储在s3上,只需在批处理作业完成后在需要时从s3请求它。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM