简体   繁体   English

TCP客户端数据请求

[英]TCP client data requesting

I am trying to find an efficient way to transfer data between the server and the client without consistency errors while keeping a low network utilization. 我试图找到一种有效的方法在服务器和客户端之间传输数据,没有一致性错误,同时保持较低的网络利用率。 I have come against this situation many times before and have always ended up using one of the following two plans: 我以前曾多次反对这种情况,并且总是最终使用以下两种计划之一:

Plan #1: Client requests all available data (Either on connection or on first demand). 计划#1:客户端请求所有可用数据(在连接时或首次请求时)。 Client caches the data and uses it as its own local database (Stored in RAM). 客户端缓存数据并将其用作自己的本地数据库(存储在RAM中)。 Upon any changes (Addition, deletion, update) of the data, the server notifies the client which then updates its cache 在对数据进行任何更改(添加,删除,更新)时,服务器会通知客户端,然后客户端更新其缓存

Pros: Low network utilization after initial transfer (All data are cached). 优点:初始传输后网络利用率低(所有数据都被缓存)。 Dynamic update of data 动态更新数据

Cons: Server might be required to send a huge amount of data. 缺点:服务器可能需要发送大量数据。 This could cause a network congestion or even cause the client to crash 这可能会导致网络拥塞甚至导致客户端崩溃

Plan #2: Client requests some of the data on demand (eg Retrieve first 25 items of a list). 计划#2:客户端按需请求一些数据(例如,检索列表的前25项)。 If more data are required, client requests the next 25 items and so on. 如果需要更多数据,客户端会请求接下来的25个项目,依此类推。

Pros: Simple. 优点:简单。 No need to transfer all of the data at once 无需一次传输所有数据

Cons: Server cannot dynamically update the data of clients since it doesn't know what data each client has. 缺点:服务器无法动态更新客户端的数据,因为它不知道每个客户端具有哪些数据。 For the same reason, clients can't cache any data since they may cache an outdated item. 出于同样的原因,客户端无法缓存任何数据,因为它们可能会缓存过期的项目。 High network utilization throughout the usage of the system. 整个系统使用期间的高网络利用率。

What is the best way to deal with this? 处理这个问题的最佳方法是什么?

If I understand correctly, you have some kind of sequential list of data, " (eg Retrieve first 25 items of a list) ". 如果我理解正确,你有一些顺序的数据列表,“ (例如,检索列表的前25项) ”。

If that's the case, you can have the server keep an "up till record x" indicator on a per connection basis. 如果是这种情况,您可以让服务器在每个连接的基础上保持“直到记录x”指示符。 For example, say initially you send the first 25 items. 例如,假设您最初发送前25个项目。 The server keeps a record, client x has gotten up to record 25. The client then needs record 57, so the server send everything up till and including record 57. Let's say record 36 gets updated. 服务器保留一条记录,客户端x已经达到记录25.然后客户端需要记录57,所以服务器发送所有内容直到包括记录57.假设记录36得到更新。 The server can send that update only to the clients that have gotten up till at least record 36. 服务器只能将该更新发送给已经达到至少记录36的客户端。

This allows caching and updates, if in fact your data is a set of sequential records. 如果实际上您的数据是一组连续记录,则允许缓存和更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM