Google云端硬盘使用什么技术来获取实时更新? [英] What technology does Google Drive use to get real-time updates?

查看:108
本文介绍了Google云端硬盘使用什么技术来获取实时更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google云端硬盘使用哪种技术进行实时处理?

What technology does Google Drive use to do real-time?

当我输入被多个用户访问的Google云端硬盘文档时,"Chrome开发者工具"的网络"标签显示没有WebSocket.

When I type in a Google Drive document that is being accessed by multiple users, the Chrome Developer Tools Network tab shows that there are no WebSockets.

我看到两种最常见的AJAX调用都带有绑定"?或保存?"在网址中. 救?"每次键入时都会发出POST请求,这对于将更新发送到服务器来说是正常的AJAX.

I see that the two most frequent types of AJAX call have either "bind?" or "save?" in the URL. "save?" POST requests are made every time I type, which makes sense- normal AJAX for sending updates to the server.

当另一个用户键入时,最新的绑定?" GET呼叫保持打开状态,并且通过该连接传输的数据量增加.定期关闭"bind?",然后打开新的"bind?",逻辑似乎是持续时间和数据大小的函数.

When another user types, the most recent "bind?" GET call stays open, and the amount of data transferred over that connection increases. Periodically, "bind?"s are closed and new ones open up, and the logic seems to be some function of duration and data size.

这不是长时间轮询,因为当服务器发送更新时,它不会完成响应.

This isn't long-polling, since when the server sends updates it doesn't complete the response.

这似乎不是服务器发送的事件,因为内容类型是文本/纯文本"而不​​是文本/流".

This doesn't seem to be server-sent events, since the content-type is "text/plain" instead of "text/stream".

是否有Google所做的名字?如果是这样,我该如何尝试实现呢?

Is there a name for what Google is doing? If so, how can I try implementing this?

推荐答案

Google的云端硬盘实时更新(例如长轮询"或套接字")解决方案是否有名称?

直到现在还没有名字.我将其称为无轮询",以与轮询和长轮询形成对比.

Is there a name for Google's solution for real-time updates in Drive (such as "long polling" or "sockets")?

It didn't have a name until now. I'll call it "no-polling," to contrast with polling and long-polling.

通过轮询,客户端会定期发送对新数据的查询.

With polling, the client periodically sends queries for new data.

通过长轮询,客户端查询数据,服务器保留请求,并在有更新时以更新结束响应.

With long-polling, the client queries for data, and the server holds onto the request, ending the response with the updates when there are updates.

无轮询(Google云端硬盘的功能)利用了浏览器如何在请求完成之前从请求的正文中读取数据的优势.因此,随着协作者进行更多的键入和编辑,服务器会将更多的数据附加到当前请求中.如果满足某些限制(内容的长度或请求的持续时间),则请求完成,并且客户端向服务器发起新请求.

No-polling (what Google Drive does) takes advantage of how the browser can read data from the body of a request before the request is complete. So as collaborators do more typing and edits, the server appends more data to the current request. If certain limits are met (length of the content or duration of the request), the request completes, and the client initiates a new request with the server.

让客户端将更新发送到服务器:这可以通过普通的POST完成.

For the client to send updates to the server: this can be done with normal POSTs.

让客户端从服务器订阅更新:

For the client to subscribe to updates from the server:

  • 客户端发送GET以获得更新流,然后在响应完成之前开始读取响应的正文.

  • The client sends a GET for an update stream, then starts reading the body of the response before the response is complete.

XHR对象可以在事件发生之前发出 progress 事件请求已完成.可使用xhr.responseText访问(部分)响应. ~~还没有一种简单的方法来监视fetch 的进度(截至5月) 2016).~~使用fetch时,可以通过使用res.body ReadableStream来监视进度.

XHR objects can emit progress events before the request is complete. The (partial) response is accessible using xhr.responseText. ~~There's no simple way to watch for progress with fetch yet (as of May 2016).~~ When using fetch one can watch for progress by consuming the res.body ReadableStream.

  • 当前请求结束时,客户端应发起一个新请求.

  • The client should initiate a new request when the current request ends.

    服务器必须:

    • 跟踪哪些客户端订阅了哪些更新流.
    • 在收到针对特定更新流的请求时,将数据写入响应,但在数据量变大或超时之前不要完成响应.

    在我看来,无轮询似乎比长轮询更好,尽管我没有花太多时间.长轮询强制在延迟和消息大小(考虑到恒定的更新速率)之间进行折衷,而不必进行无轮询的折衷.长轮询的另一个缺点是,它可能导致许多HTTP请求,每次都要付出HTTP的开销.

    No-polling seems superior to long-polling, in my opinion, though I haven't played with it much. Long-polling forces a trade-off between latency and message size (given a constant rate of updates), a trade-off no-polling doesn't have to make. Another disadvantage of long-polling is that it can lead to many HTTP requests, paying the overhead of HTTP each time.

    No-polling与WebSockets相比的最大优势在于,尽管WebSocket支持非常好,但每个浏览器都支持no-polling —

    No-polling's big advantage over WebSockets is that no-polling is supported by every browser, though WebSocket support is pretty good — IE10+.

    这篇关于Google云端硬盘使用什么技术来获取实时更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆