使用 Thin & 进行 Http 流式传输事件机器 [英] Http streaming with thin & eventmachine

查看:50
本文介绍了使用 Thin & 进行 Http 流式传输事件机器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 EM 来实现流式传输和并发.我在流媒体上遇到了问题...我运行以下机架应用程序 https://gist.github.com/1394840 使用

I'm playing with EM to achieve streaming and concurrency. I had a problem with streaming... I run the following rack app https://gist.github.com/1394840 using

$ rackup -s thin -p 3000 async_app.ru

在使用 $ ab -c 10 -n 20 http://localhost:3000/ 进行测试时,该应用似乎接受并行请求.太棒了!

While testing with $ ab -c 10 -n 20 http://localhost:3000/, the app seemed accepting parellel requests. Great!

我希望它同时实现流式传输.当我在 Firefox8 中测试它时,它运行良好.并使用 $ curl -i http://localhost:3000/,结果也按预期流式传输!

I expect it to achieve streaming meanwhile. When I test it in Firefox8, it works so well. And using $ curl -i http://localhost:3000/, the result is streamed just as expected too!

但后来在 IE & 中测试时Chrome,流式传输失败,即请求触发后5秒才出现三行...

But later when tested in IE & Chrome, the streaming failed, that is, the three lines only showed up together 5 seconds after the request fired...

我怀疑如果我错过了浏览器所需的东西?我注意到响应头中没有 Transfer-Encoding:chunked ,这有关系吗?如果是这样,是Thin的问题吗?如何使用 Thin 或 Chrome 实现流式传输?

I doubted that if I miss something required by the browser? I noticed that there wasn't a Transfer-Encoding:chunked in the response headers, so does it matter? If so, is it Thin's problem? How can I implement streaming with thin, or in Chrome?

谢谢!

推荐答案

显然浏览器不会开始渲染页面,直到它们得到一定的数量"响应,正如它指出的那样在本文中.所以我试过以下:

Apparently browsers won't start rendering a page until they get certain "amount" of response, as it pointed out in this article. So I've tried following:

  body.call ["Hey!\n".ljust(1024)]

我已经在 Safari 6、Chrome 22 和 Firefox 14 上对其进行了测试,当第一条消息不小于 1 Kb 时,它们都开始按预期工作.实际上,即使第一条消息超过 512 字节,Safari 也开始打印消息.

I've tested it with Safari 6, Chrome 22 and Firefox 14 and they all start to work as expected when first message was no less than 1 Kb. Actually Safari started to print messages even if the first one was more than 512 bytes.

这篇关于使用 Thin & 进行 Http 流式传输事件机器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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