如何防止我的永久框架关闭我的连接?

发布于 2024-11-13 00:49:15 字数 408 浏览 3 评论 0原文

因此,我使用永久帧将数据从 Tornado 流式传输到 JavaScript 客户端应用程序,并且我发现 JavaScript 客户端偶尔会停止接收数据。我已经实现了一种心跳方法,当心跳丢失时,客户端将更改框架的 URL 以重新打开连接,但这感觉像是一个尴尬的黑客——并且必须进行一定量的设置和拆卸当连接刷新时,会在应用程序 UI 中发生。我真的更希望它能够成为整个使用会话的一个持久连接。

有时这种情况每隔几分钟发生一次,有时它似乎陷入了每五秒发生一次的循环。我的浏览器是 Firefox 和 Chrome。

哪些情况可能会导致此问题?我真的只需要一些调试起点的想法——我应该考虑延迟、数据泛滥、连接不良吗?问题更有可能出现在 Tornado 端还是 JavaScript 端?或者,我是否会更好地投入精力让 JavaScript 应用程序能够更优雅地重新初始化自身?

So, I'm using a forever-frame to stream data from Tornado to a JavaScript client application, and I'm finding that the JavaScript client occasional just stops receiving data. I've implemented a heartbeat method, where the client will change the URL of the frame to reopen the connection when a heartbeat is missed, but this feels like an awkward hack--- and there's a certain amount of setup and teardown which has to happen in the app UI when the connection refreshes. I'd really prefer if it could be one persistent connection for the entire session of use.

Sometimes this is once every few minutes, other times it seems to get itself in a loop where it happens every five seconds. My browsers are Firefox and Chrome.

What kinds of things could cause this issue? I really just need some ideas for starting points in my debugging--- should I be looking at latency, data flooding, bad connection? Would the problem be more likely to be at the Tornado end or the JavaScript end? Alternatively, would I be better to invest my efforts in making the JavaScript app able to reinitialize itself more gracefully?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朕就是辣么酷 2024-11-20 00:49:15

啊哈。我明白了这一点。 Tornado 并发性较差。问题是我的逻辑是从多个线程调用长期存在的 RequestHandler 实例(由入站 RPC 触发),当它们发生冲突时,Tornado 会崩溃并关闭连接。

修复方法是使用 add_callback 将我与 IOLoop 线程上的 RequestHandler 实例的交互排队:

tornado.ioloop.IOLoop.instance().add_callback(do_stuff)

Aha. I figured this out. Tornado does poorly with concurrency. The issue was that my logic was calling the long-lived RequestHandler instances from multiple threads (triggered by inbound RPCs), and when they collided, Tornado would freak out and close the connection.

The fix was to queue up my interactions with RequestHandler instances on the IOLoop thread, using add_callback:

tornado.ioloop.IOLoop.instance().add_callback(do_stuff)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文