问题
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!
回答1:
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.
来源:https://stackoverflow.com/questions/8275899/http-streaming-with-thin-eventmachine