Zac*_*chB 2 azure amazon-web-services google-compute-engine google-cloud-dataflow google-cloud-dataproc
我有很多图像,我需要通过java程序来创建更多的图像文件 - 一个令人尴尬的平行案例.每个输入文件大约500 MB,在处理过程中需要大约4 GB的内存,运行需要30秒到2分钟.java程序是多线程的,但是通过并行输入文件而不是使用更多线程获得更多收益.我需要每天多次启动进程(我不想手动打开/关闭群集,也不想全天候付费).
我在各种云选项中有点迷失:
任何人都可以建议适当的解决方案吗?
您应该可以非常轻松地使用Dataflow执行此操作.管道可能看起来像(假设您的文件位于Google云端存储,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();
Run Code Online (Sandbox Code Playgroud)
这是一个常见的案例系列,其中Dataflow被用作一个令人尴尬的并行编排框架而不是数据处理框架,但它应该可以工作.
您将需要Dataflow SDK 1.2.0来使用MapElements转换(对Java 8 lambdas的支持是1.2.0中的新增功能).
| 归档时间: |
|
| 查看次数: |
340 次 |
| 最近记录: |