简体   繁体   中英

Http streaming with thin & eventmachine

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

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

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!

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...

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?

Thanks!

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)]

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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