LoginSignup
0
1

More than 1 year has passed since last update.

AWS LambdaでPythonコード並列処理

Last updated at Posted at 2023-05-12

はじめに

ある日のことAWS Lambdaで並列処理して処理速度向上を図りたいとなりまして。。。

その際に四苦八苦して得た知見を備忘録としてアウトプットしておきたいと思います。

前提

まずAWS Lambdaでは

  • 設定メモリに応じてvCPU数が増減する
  • pythonのmultiprocessingのPoolが使えない

らしいです。

個人的にmultiprocessingのPoolを使い慣れていたので困ったもんだなぁと。

方法

Lambdaでの並列処理のやり方を色々調べたのですが、並列化したい処理に戻り値がない場合の解説ばかりでした。

そしてたどり着いたのが以下リポジトリ。

pip installもできるようですが、main.pyをコピペするだけで十分です。

使い方はmaltiprocessingのPoolのような感じで以下のように実装すれば並列処理をすることができます。

from lambda_multiprocessing import Pool

with Pool() as p;
    results = p.map(function, iterator)

上記例では、main.pyをlambda_multiprocessing.pyとリネームしております。

最後に

ここまで読んでいただきありがとうございます。

大雑把な内容となっておりますが誰かのためになれば幸いです。

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1