使用 AWS Lambda 进行并行处理时等待工作人员的好方法是什么?
What is a good way to wait for workers when using AWS Lambda for parallel processing?
问题
我有一个优化问题,我正在使用多个 AWS Lambda 实例来并行 运行 优化算法,每个实例都有不同的参数。我需要等待所有这些工人完成 运行ning,然后检查所有结果以选择最好的。
注意:我使用的是完全无服务器架构。
第一个想法
我的第一个想法是使用另一个 Lambda 函数启动所有工作程序,等待它们,然后收集结果。但是,我觉得这种同步方式比较不方便,因为它要求主函数在整个过程中都处于 运行ning 状态,而实际上并没有做任何有用的工作。理想情况下,我会有一个功能来启动工作人员,第二个功能来收集结果,只有在所有工作人员完成后才会触发。
问题
在触发对其结果起作用的代码之前等待所有 Lambda worker 完成的好方法是什么?
您可以使用 Step Functions:
Step Functions is a serverless orchestration service that lets you combine AWS Lambda functions and other AWS services to build business-critical applications.
具体来说,Step Functions 支持 Parallel 状态:
A Parallel state causes AWS Step Functions to execute each branch, starting with the state named in that branch's StartAt field, as concurrently as possible, and wait until all branches terminate (reach a terminal state) before processing the Parallel state's Next field.
或者,考虑 Map 状态:
The Map state can be used to run a set of steps for each element of an input array. While the Parallel state executes multiple branches of steps using the same input, a Map state will execute the same steps for multiple entries of an array in the state input.
因此,Map支持动态并行,而Parallel支持预定义的静态并行。
问题
我有一个优化问题,我正在使用多个 AWS Lambda 实例来并行 运行 优化算法,每个实例都有不同的参数。我需要等待所有这些工人完成 运行ning,然后检查所有结果以选择最好的。
注意:我使用的是完全无服务器架构。
第一个想法
我的第一个想法是使用另一个 Lambda 函数启动所有工作程序,等待它们,然后收集结果。但是,我觉得这种同步方式比较不方便,因为它要求主函数在整个过程中都处于 运行ning 状态,而实际上并没有做任何有用的工作。理想情况下,我会有一个功能来启动工作人员,第二个功能来收集结果,只有在所有工作人员完成后才会触发。
问题
在触发对其结果起作用的代码之前等待所有 Lambda worker 完成的好方法是什么?
您可以使用 Step Functions:
Step Functions is a serverless orchestration service that lets you combine AWS Lambda functions and other AWS services to build business-critical applications.
具体来说,Step Functions 支持 Parallel 状态:
A Parallel state causes AWS Step Functions to execute each branch, starting with the state named in that branch's StartAt field, as concurrently as possible, and wait until all branches terminate (reach a terminal state) before processing the Parallel state's Next field.
或者,考虑 Map 状态:
The Map state can be used to run a set of steps for each element of an input array. While the Parallel state executes multiple branches of steps using the same input, a Map state will execute the same steps for multiple entries of an array in the state input.
因此,Map支持动态并行,而Parallel支持预定义的静态并行。