wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.22k stars 295 forks source link

Default push_stream_subscriber (streaming) isn't flushing messages #137

Closed rstruber closed 10 years ago

rstruber commented 10 years ago

I've spun up a set of endpoints running the basic configuration straight from the readme, and unfortunately am not receiving messages on a streaming endpoint until the server is restarted.

Some information about the host:

nginx version: nginx/1.4.7 push version: 0.4.0 os: Gentoo Base System release 2.1 Kernel release 3.7.10

What I'm seeing as best I can describe it:

Start listening:

curl -s http://localhost/sub/ch1

Start publishing:

curl -s -X POST 'http://localhost/pub?id=ch1' -d 'Hello World!' curl -s -X POST 'http://localhost/pub?id=ch1' -d 'Hello World!' curl -s -X POST 'http://localhost/pub?id=ch1' -d 'Hello World!'

no messages appear in streaming channel.

Restart nginx /etc/init.d/nginx restart

3 messages appear in streaming channel:

Hello World!Hello World!Hello World!

Please let me know what else I can do to help you debug this issue.

vhost config as follows:

    push_stream_shared_memory_size 32m;

    server {
            listen 80;
            server_name localhost;

            access_log off;
            error_log /dev/null emerg;

            location /pub {
                    # activate publisher (admin) mode for this location
                    push_stream_publisher admin;

                    # query string based channel id
                    push_stream_channels_path               $arg_id;
            }

            location ~ /sub/(.*) {
                    # activate subscriber (streaming) mode for this location
                    push_stream_subscriber;

                    # positional channel path
                    push_stream_channels_path                   $1;
            }
    }
wandenberg commented 10 years ago

Hi @rstruber

try to use the --raw options on the curl for subscriber like

curl -s --raw http://localhost/sub/ch1

the curl buffer the response and only show the content when a flush happens, buffer full or on the restart case, connection closed.

If you what to force the flush you can append a \r\n on message_template, but it isn't necessary for browsers until I can see.

rstruber commented 10 years ago

Thanks @wandenberg. The following response came back after publishing a message.

curl -s --raw http://localhost/sub/ch1

c Hello World!

(Our application is connecting over curl not through a browser.)

I added \r\n to the message template and that seems to work. Should it work without? The "c" above "Hello World!" was not present using the message template. That only came back with curl --raw.

wandenberg commented 10 years ago

Hi @rstruber you can try set --no-buffer option on curl, instead of add the \r\n on the template. check if it works, please.

curl -s --no-buffer http://localhost/sub/ch1

The "c" make part of the chuncked response, each response chunk will come with a different value. The --raw make the curl output exactly which it receives.

rstruber commented 10 years ago

Thank you @wandenberg. This has the behavior we expected. Feel free to close this issue.