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

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

问题描述

Google 云端硬盘使用什么技术进行实时操作?

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

当我输入多个用户正在访问的 Google Drive 文档时,Chrome Developer Tools Network 选项卡显示没有 WebSockets.

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 调用保持打开状态,并且通过该连接传输的数据量增加.定期地,绑定?"关闭并打开新的,逻辑似乎是持续时间和数据大小的某种函数.

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.

这似乎不是服务器发送的事件,因为内容类型是text/plain"而不是text/stream".

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 的进度 还没有(截至 2016 年 5 月).~~当使用 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 的一大优势是每个浏览器都支持 no-polling,尽管 WebSocket 支持相当不错 — IE10+.

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

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

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