YngwieWang commented on a change in pull request #9150: [FLINK-13227][docs-zh]
Translate "asyncio" page into Chinese
URL: https://github.com/apache/flink/pull/9150#discussion_r304728193
##########
File path: docs/dev/stream/operators/asyncio.zh.md
##########
@@ -140,130 +124,114 @@ DataStream<Tuple2<String, String>> resultStream =
<div data-lang="scala" markdown="1">
{% highlight scala %}
/**
- * An implementation of the 'AsyncFunction' that sends requests and sets the
callback.
+ * 实现 'AsyncFunction' 用于发送请求和设置回调。
*/
class AsyncDatabaseRequest extends AsyncFunction[String, (String, String)] {
- /** The database specific client that can issue concurrent requests with
callbacks */
+ /** 使用回调函数来并发发送请求的数据库客户端 */
lazy val client: DatabaseClient = new DatabaseClient(host, post,
credentials)
- /** The context used for the future callbacks */
+ /** 用于 future 回调的上下文环境 */
implicit lazy val executor: ExecutionContext =
ExecutionContext.fromExecutor(Executors.directExecutor())
override def asyncInvoke(str: String, resultFuture: ResultFuture[(String,
String)]): Unit = {
- // issue the asynchronous request, receive a future for the result
+ // 发送异步请求,接收 future 结果
val resultFutureRequested: Future[String] = client.query(str)
- // set the callback to be executed once the request by the client is
complete
- // the callback simply forwards the result to the result future
+ // 设置客户端完成请求后要执行的回调函数
+ // 回调函数只是简单地把结果发给 future
resultFutureRequested.onSuccess {
case result: String => resultFuture.complete(Iterable((str,
result)))
}
}
}
-// create the original stream
+// 创建初始 DataStream
val stream: DataStream[String] = ...
-// apply the async I/O transformation
+// 应用异步 I/O 转换操作
val resultStream: DataStream[(String, String)] =
AsyncDataStream.unorderedWait(stream, new AsyncDatabaseRequest(), 1000,
TimeUnit.MILLISECONDS, 100)
{% endhighlight %}
</div>
</div>
-**Important note**: The `ResultFuture` is completed with the first call of
`ResultFuture.complete`.
-All subsequent `complete` calls will be ignored.
+**重要提示**: 第一次调用 `ResultFuture.complete` 后 `ResultFuture` 就完成了。
+后续的 `complete` 调用都将被忽略。
-The following two parameters control the asynchronous operations:
+下面两个参数控制异步操作:
- - **Timeout**: The timeout defines how long an asynchronous request may take
before it is considered failed. This parameter
- guards against dead/failed requests.
+ - **Timeout**: 超时参数定义了异步请求发出多久后未得到响应即被认定为失败。 它可以防止一直等待得不到响应的请求。
- - **Capacity**: This parameter defines how many asynchronous requests may be
in progress at the same time.
- Even though the async I/O approach leads typically to much better
throughput, the operator can still be the bottleneck in
- the streaming application. Limiting the number of concurrent requests
ensures that the operator will not
- accumulate an ever-growing backlog of pending requests, but that it will
trigger backpressure once the capacity
- is exhausted.
+ - **Capacity**: 容量参数定义了可以同时进行的异步请求数。
+ 即使异步 I/O 通常带来更高的吞吐量, 执行异步 I/O 操作的算子仍然可能成为流处理的瓶颈。
限制并发请求的数量可以确保算子不会持续累积待处理的请求进而造成积压,而是在容量耗尽时触发反压。
Review comment:
持续积累的请求不会导致反压,容量耗尽会。
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services