使用云服务的并行文件处理
Parallel file processing using cloud services
我有许多图像需要 运行 通过 java 程序来创建更多图像文件 -- 一个令人尴尬的并行案例。每个输入文件大约 500 MB,在处理过程中需要大约 4 GB 的内存,需要 30 秒到 2 分钟才能 运行。 java 程序是多线程的,但与使用更多线程相比,对输入文件进行并行处理可以获得更多收益。我需要每天多次启动流程(我不想手动打开 on/off 集群,也不想全天候 24/7 付费)。
我有点迷失在各种云选项中:
- 亚马逊lambda系统资源不足(内存不足)。
- Google Cloud DataFlow,看来我必须编写自己的管道源才能使用他们的 Cloud Storage 存储桶。很好,但如果这不是一个合适的解决方案(可能是这样,我还不能确定),我不想浪费时间这样做。
- Amazon data pipeline 看起来相当于 Google Cloud DataFlow。 (为了完整性在编辑中添加。)
- Google Cloud Dataproc,这不是 map/reduce hadoop-y 情况,但可能仍然有效。不过,我宁愿不管理自己的集群。
- Google 计算引擎或具有自动缩放功能的 AWS,我只是为机器上的每个内核启动进程。我提供更多管理,但没有 API 可学。
- Microsoft Data Lake 尚未发布,看起来是 hadoop-y。
- Microsoft Batch 似乎很合适(但我问是因为我对其他选项仍然感到好奇)。
任何人都可以建议对此有什么合适的解决方案吗?
您应该能够使用 Dataflow 轻松完成此操作。管道可能类似于(假设您的文件位于 Google Cloud Storage,GCS):
class ImageProcessor {
public static void process(GcsPath path) {
// Open the image, do the processing you want, write
// the output to where you want.
// You can use GcsUtil.open() and GcsUtil.create() for
// reading and writing paths on GCS.
}
}
// This will work fine until a few tens of thousands of files.
// If you have more, let me know.
List<GcsPath> filesToProcess = GcsUtil.expand(GcsPath.fromUri("..."));
p.apply(Create.of(filesToProcess))
.apply(MapElements.via(ImageProcessor::process)
.withOutputType(new TypeDescriptor<Void>() {}));
p.run();
这是 Dataflow 被用作令人尴尬的并行编排框架而不是数据处理框架的常见案例之一,但它应该可以工作。
您需要 Dataflow SDK 1.2.0 才能使用 MapElements 转换(对 Java 8 lambda 的支持是 1.2.0 中的新增功能)。
我有许多图像需要 运行 通过 java 程序来创建更多图像文件 -- 一个令人尴尬的并行案例。每个输入文件大约 500 MB,在处理过程中需要大约 4 GB 的内存,需要 30 秒到 2 分钟才能 运行。 java 程序是多线程的,但与使用更多线程相比,对输入文件进行并行处理可以获得更多收益。我需要每天多次启动流程(我不想手动打开 on/off 集群,也不想全天候 24/7 付费)。
我有点迷失在各种云选项中:
- 亚马逊lambda系统资源不足(内存不足)。
- Google Cloud DataFlow,看来我必须编写自己的管道源才能使用他们的 Cloud Storage 存储桶。很好,但如果这不是一个合适的解决方案(可能是这样,我还不能确定),我不想浪费时间这样做。
- Amazon data pipeline 看起来相当于 Google Cloud DataFlow。 (为了完整性在编辑中添加。)
- Google Cloud Dataproc,这不是 map/reduce hadoop-y 情况,但可能仍然有效。不过,我宁愿不管理自己的集群。
- Google 计算引擎或具有自动缩放功能的 AWS,我只是为机器上的每个内核启动进程。我提供更多管理,但没有 API 可学。
- Microsoft Data Lake 尚未发布,看起来是 hadoop-y。
- Microsoft Batch 似乎很合适(但我问是因为我对其他选项仍然感到好奇)。
任何人都可以建议对此有什么合适的解决方案吗?
您应该能够使用 Dataflow 轻松完成此操作。管道可能类似于(假设您的文件位于 Google Cloud Storage,GCS):
class ImageProcessor {
public static void process(GcsPath path) {
// Open the image, do the processing you want, write
// the output to where you want.
// You can use GcsUtil.open() and GcsUtil.create() for
// reading and writing paths on GCS.
}
}
// This will work fine until a few tens of thousands of files.
// If you have more, let me know.
List<GcsPath> filesToProcess = GcsUtil.expand(GcsPath.fromUri("..."));
p.apply(Create.of(filesToProcess))
.apply(MapElements.via(ImageProcessor::process)
.withOutputType(new TypeDescriptor<Void>() {}));
p.run();
这是 Dataflow 被用作令人尴尬的并行编排框架而不是数据处理框架的常见案例之一,但它应该可以工作。
您需要 Dataflow SDK 1.2.0 才能使用 MapElements 转换(对 Java 8 lambda 的支持是 1.2.0 中的新增功能)。