Spring 在 Kubernetes 中批处理 运行

Spring Batch running in Kubernetes

我有一个 Spring 批处理,它在线程池中划分为“从属步骤”和 运行,这里是配置:

我想在 Kubernetes 中 运行 这个 Spring 批处理作业。我检查了这个 post:@MAHMOUD BEN HASSINE 的 https://spring.io/blog/2021/01/27/spring-batch-on-kubernetes-efficient-batch-processing-at-scale

来自 post,段落:

  1. Choosing the Right Kubernetes Job Concurrency Policy As I pointed out earlier, Spring Batch prevents concurrent job executions of the same job instance. So, if you follow the “Kubernetes job per Spring Batch job instance” deployment pattern, setting the job’s spec.parallelism to a value higher than 1 does not make sense, as this starts two pods in parallel and one of them will certainly fail with a JobExecutionAlreadyRunningException. However, setting a spec.parallelism to a value higher than 1 makes perfect sense for a partitioned job. In this case, partitions can be executed in parallel pods. Correctly choosing the concurrency policy is tightly related to which job pattern is chosen (As explained in point 3).

查看我的批处理作业,如果我启动 2 个或更多 pods,听起来 one/more pods 会失败,因为它会尝试启动相同的作业。但另一方面,听起来更多 pods 将 运行 并行,因为我正在使用分区作业。

我的 Spring 批次似乎与 https://kubernetes.io/docs/tasks/job/fine-parallel-processing-work-queue/

这样说,正确的做法是什么?我应该在我的部署中设置多少 pods? partition/threads 会 运行 在 separate/different pods 上,还是线程会 运行 在一个 pod 中? 在并行性中,我在哪里定义它?还有并行度,应该和线程数一样吧?

谢谢!马库斯.

一个 JVM 中的线程 运行,它 运行 在容器中,而容器又是 运行 在 Pod 中。所以谈论在不同的 Pods.

上使用不同的线程 运行ning 是没有意义的

SpringBatch 中的分区技术可以是本地的(同一 JVM 中的多个线程,其中每个线程处理不同的分区)或远程的(多个 JVM 处理不同的分区)。本地分区需要一个 JVM,因此您只需要一个 Pod。远程分区需要多个JVM,所以需要多个Pods.

I have a Spring Batch that partitions into "Slave Steps" and run in a thread pool

由于您使用工作线程池实现了本地分区,因此您只需要一个 Pod 即可 运行 您的分区作业。