I recently discovered rails streaming, and having read the various documentation, I tried to add it to one of my controllers like so:
def index
render :stream => true
end
My template file currently looks like this:
<%10.times do%>
<p>
I should get streamed ERB...
<%sleep 0.5%>
</p>
<%end%>
But instead of displaying a message every 0.5 seconds, it waits 5 seconds and displays the whole page! I have checked this behavior in a browser and using curl.
I am using unicorn on OSX, and yes, I configured unicorn.rb for streaming:
listen 3000, :tcp_nodelay => true, :tcp_nopush => false
worker_processes 1
If you want to see my layout file, it looks like this:
<!DOCTYPE html>
<html>
<head>
<title>StreamingTest</title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
I tried disabling all gems (except rails and postgres), and I pared my controller, layout, and template down to the bare minimum, without any success.
I even went so far as to download a complete streaming demo I found (https://github.com/slim-template/slim-streamingtest), and when I ran that, it didn't stream either! (Note to anybody trying to run that demo: I had to change the gemfile source to use https instead of http before I could "bundle install", and I had to "bundle update sprockets" before it would run)
I note that somebody else (using Puma) appears to have a similar problem, which has not been successfully resolved:
It may be that whatever works for me will also work for them.
Streaming would really help our app, if I could just get it to work, but I can't even get demo streaming apps to run correctly! I suspect it might have something to do with my dev environment, but the problem remains when I deploy my app to Heroku, and I'm out of ideas. Any help would be greatly appreciated . . .
Thanks!