我有很多图像,我需要通过java程序来创建更多的图像文件--这是一个令人尴尬的平行案例。每个输入文件大约是500 mb,在处理过程中需要大约4GB的内存,运行需要30秒到2分钟。java程序是多线程的,但是更多的好处来自于对输入文件的并行化,而不是使用更多的线程。我需要每天启动几次进程(我不想手动打开/关闭集群,也不想24/7支付费用)。
我有点迷失在云端的各种选择中:
有人能建议如何解决这个问题吗?
发布于 2015-10-09 21:26:36
您应该能够很容易地使用Dataflow来完成这个任务。该管道看起来可能类似于(假设您的文件位于谷歌云存储,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被用作一个令人难堪的并行编排框架,而不是一个数据处理框架,但它应该能够工作。
您将需要DataFlowSDK1.2.0来使用MapElements转换(对Java8lambdas的支持在1.2.0中是新的)。
https://stackoverflow.com/questions/33046724
复制相似问题