[zh-cn] Improve fine-parallel-processing-work-queue.md

This commit is contained in:
windsonsea
2022-07-06 09:47:33 +08:00
parent b88ef078f1
commit 7d9c9c7aa2
@@ -25,7 +25,7 @@ from a task queue, processes it, and repeats until the end of the queue is reach
Here is an overview of the steps in this example: Here is an overview of the steps in this example:
--> -->
在这个例子中,当每个pod被创建时,它会从一个任务队列中获取一个工作单元,处理它,然后重复,直到到达队列的尾部。 在这个例子中,当每个 Pod 被创建时,它会从一个任务队列中获取一个工作单元,处理它,然后重复,直到到达队列的尾部。
下面是这个示例的步骤概述: 下面是这个示例的步骤概述:
@@ -106,11 +106,13 @@ Start a temporary interactive pod for running the Redis CLI.
现在,让我们往队列里添加一些 “任务”。在这个例子中,我们的任务是一些将被打印出来的字符串。 现在,让我们往队列里添加一些 “任务”。在这个例子中,我们的任务是一些将被打印出来的字符串。
启动一个临时的可交互的 pod 用于运行 Redis 命令行界面。 启动一个临时的可交互的 Pod 用于运行 Redis 命令行界面。
```shell ```shell
kubectl run -i --tty temp --image redis --command "/bin/sh" kubectl run -i --tty temp --image redis --command "/bin/sh"
``` ```
输出类似于:
``` ```
Waiting for pod default/redis2-c7h78 to be running, status is Pending, pod ready: false Waiting for pod default/redis2-c7h78 to be running, status is Pending, pod ready: false
Hit enter for command prompt Hit enter for command prompt
@@ -119,7 +121,7 @@ Hit enter for command prompt
<!-- <!--
Now hit enter, start the redis CLI, and create a list with some work items in it. Now hit enter, start the redis CLI, and create a list with some work items in it.
--> -->
现在按回车键,启动 redis 命令行界面,然后创建一个存在若干个工作项的列表。 现在按回车键,启动 Redis 命令行界面,然后创建一个存在若干个工作项的列表。
```shell ```shell
# redis-cli -h redis # redis-cli -h redis
@@ -178,17 +180,17 @@ called rediswq.py ([Download](/examples/application/job/redis/rediswq.py)).
--> -->
## 创建镜像 ## 创建镜像
现在我们已经准备好创建一个我们要运行的镜像 现在我们已经准备好创建一个我们要运行的镜像
我们会使用一个带有 redis 客户端的 python 工作程序从消息队列中读出消息。 我们会使用一个带有 Redis 客户端的 Python 工作程序从消息队列中读出消息。
这里提供了一个简单的 Redis 工作队列客户端库, rediswq.py ([下载](/examples/application/job/redis/rediswq.py))。 这里提供了一个简单的 Redis 工作队列客户端库,名为 rediswq.py ([下载](/examples/application/job/redis/rediswq.py))。
<!-- <!--
The "worker" program in each Pod of the Job uses the work queue The "worker" program in each Pod of the Job uses the work queue
client library to get work. Here it is: client library to get work. Here it is:
--> -->
Job 中每个 Pod 内的 “工作程序” 使用工作队列客户端库获取工作。如下: Job 中每个 Pod 内的 “工作程序” 使用工作队列客户端库获取工作。具体如下:
{{< codenew language="python" file="application/job/redis/worker.py" >}} {{< codenew language="python" file="application/job/redis/worker.py" >}}
@@ -235,7 +237,7 @@ your app image with your project ID, and push to GCR. Replace
`<project>` with your project ID. `<project>` with your project ID.
--> -->
如果你使用的是 [Google Container Registry](https://cloud.google.com/tools/container-registry/) 如果你使用的是 [Google Container Registry](https://cloud.google.com/tools/container-registry/)
请先用你的 project ID 给你的镜像打上标签,然后 push 到 GCR 。请将 `<project>` 替换为你自己的 project ID 请先用你的 project ID 给你的镜像打上标签,然后 push 到 GCR 。请将 `<project>` 替换为你自己的 project ID
```shell ```shell
docker tag job-wq-2 gcr.io/<project>/job-wq-2 docker tag job-wq-2 gcr.io/<project>/job-wq-2
@@ -249,7 +251,7 @@ Here is the job definition:
--> -->
## 定义一个 Job ## 定义一个 Job
这是 job 定义: 这是 Job 定义:
{{< codenew file="application/job/redis/job.yaml" >}} {{< codenew file="application/job/redis/job.yaml" >}}
@@ -257,7 +259,7 @@ Here is the job definition:
Be sure to edit the job template to Be sure to edit the job template to
change `gcr.io/myproject` to your own path. change `gcr.io/myproject` to your own path.
--> -->
请确保将 job 模板中的 `gcr.io/myproject` 更改为你自己的路径。 请确保将 Job 模板中的 `gcr.io/myproject` 更改为你自己的路径。
<!-- <!--
In this example, each pod works on several items from the queue and then exits when there are no more items. In this example, each pod works on several items from the queue and then exits when there are no more items.
@@ -268,7 +270,7 @@ exits with success, the controller knows the work is done, and the Pods will exi
So, we set the completion count of the Job to 1. The job controller will wait for the other pods to complete So, we set the completion count of the Job to 1. The job controller will wait for the other pods to complete
too. too.
--> -->
在这个例子中,每个 pod 处理了队列中的多个项目,直到队列中没有项目时便退出。 在这个例子中,每个 Pod 处理了队列中的多个项目,直到队列中没有项目时便退出。
因为是由工作程序自行检测工作队列是否为空,并且 Job 控制器不知道工作队列的存在, 因为是由工作程序自行检测工作队列是否为空,并且 Job 控制器不知道工作队列的存在,
这依赖于工作程序在完成工作时发出信号。 这依赖于工作程序在完成工作时发出信号。
工作程序以成功退出的形式发出信号表示工作队列已经为空。 工作程序以成功退出的形式发出信号表示工作队列已经为空。
@@ -325,12 +327,13 @@ Events:
33s 33s 1 {job-controller } Normal SuccessfulCreate Created pod: job-wq-2-lglf8 33s 33s 1 {job-controller } Normal SuccessfulCreate Created pod: job-wq-2-lglf8
``` ```
查看日志: 运行以下命令查看日志:
```shell ```shell
kubectl logs pods/job-wq-2-7r7b2 kubectl logs pods/job-wq-2-7r7b2
``` ```
日志类似于:
``` ```
Worker with sessionID: bbd72d0a-9e5c-4dd6-abf6-416cc267991f Worker with sessionID: bbd72d0a-9e5c-4dd6-abf6-416cc267991f
Initial queue state: empty=False Initial queue state: empty=False
@@ -342,7 +345,7 @@ Working on lemon
<!-- <!--
As you can see, one of our pods worked on several work units. As you can see, one of our pods worked on several work units.
--> -->
你可以看到,其中的一个 pod 处理了若干个工作单元。 你可以看到,其中的一个 Pod 处理了若干个工作单元。
<!-- discussion --> <!-- discussion -->