gpt4 book ai didi

java - 响应式(Reactive)编程背压与传统分页有何不同?

转载 作者:行者123 更新时间:2023-12-02 11:21:57 29 4
gpt4 key购买 nike

我刚刚开始学习reactive-programming我对Back-Pressure这个词感到困惑.

根据文档:

This back-pressure is an important feedback mechanism that allows systems to gracefully respond to load rather than collapse under it.

我从中了解到的是:客户端会询问他在特定时间想要的记录数量,后端只会响应所询问的记录。

但是不是和分页一样吗?我们还可以使用分页来查询后端我们感兴趣的记录。

这两者有何不同?

有人可以解释一下吗?

最佳答案

分页正如您所说,客户端请求许多记录并获取该数量的记录作为返回。

背压用于监控系统,以确保系统的负载在可接受的范围内。

例如:

Let's say you have an application that is supposed to pick up and process files. The users upload files to a directory, and your application has two components, one that picks up the files from the directory (component A) and one that processes those files (component B).

Pretend that the processing component (B) can only handle 100 files at a time, otherwise it will crash due to memory issues, or any other resource problem that may happen.

A form of back-pressure is for the component that picks up files from the directory (A) to also monitor how many files are currently being processed by component B. If component A sees that component B is overloaded or is close to being overloaded, component A can stop sending files to component B. This will prevent component B from crashing.

Component A will continue to monitor the load and send files when component B is available.

这样做有什么好处?

一天、一周、一个月或一年中的某个时间,您的系统可能会收到比平时更多的请求或数据。您不希望它当时崩溃,也不希望添加更多只是偶尔使用的资源。您可以使用反压来调整传入数据的速度。

背压还可以防止数据丢失。在上面的示例中,在用户上传文件并且文件被读取并发送到处理后,它们可能会被删除以释放空间。如果系统在处理过程中崩溃,您必须找出哪些文件已处理以及哪些文件正在处理但失败并恢复它们或从用户那里获取新副本。

关于java - 响应式(Reactive)编程背压与传统分页有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49849711/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com