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

problem with connecting multiple channels very very urgent #51

Closed pokal4u closed 12 years ago

pokal4u commented 12 years ago

Hi,

I connect to multiple channels like this

var pushstream = new PushStream({ host: window.location.hostname, port: window.location.port, modes: "longpolling", secondsAgo:3600
}); pushstream.addChannel('chan1'); pushstream.addChannel('chan2'); pushstream.addChannel('chan3'); pushstream.addChannel('chan4'); pushstream.addChannel('chan5');

pushstream.connect();

Then send messages to every channel messages are received "chan1" only.

And if i connect like this:

var i=1; while(6<i){

var pushstream = new PushStream({ host: window.location.hostname, port: window.location.port, modes: "longpolling", secondsAgo:3600
}); pushstream.addChannel('chan'+i);

pushstream.connect();

i++; }

it's work fine but connect max 5 only if i connect above 5 connections notworking(take the load for send and receive messages).

Please help me urgent

Thanks

and my config file like this

pid logs/nginx.pid; error_log logs/nginx-main_error.log debug; Development Mode

master_process off; daemon off; worker_rlimit_core 500M; working_directory /tmp/nginx;

worker_processes 2;

events { worker_connections 1024; use epoll; }

http { include mime.types; default_type application/octet-stream;

access_log logs/nginx-http_access.log; error_log logs/nginx-http_error.log debug;

tcp_nopush off; tcp_nodelay on; keepalive_timeout 10; send_timeout 10; client_body_timeout 10; client_header_timeout 10; sendfile on; client_header_buffer_size 1k; large_client_header_buffers 2 4k; client_max_body_size 1k; client_body_buffer_size 1k; ignore_invalid_headers on;

push_stream_shared_memory_size 100m; push_stream_max_channel_id_length 200;

max messages to store in memory

push_stream_max_messages_stored_per_channel 20;

message ttl

push_stream_message_ttl 5m;

ping frequency

push_stream_ping_message_interval 10s;

connection ttl to enable recycle

push_stream_subscriber_connection_ttl 15m;

connection ttl for long polling

push_stream_longpolling_connection_ttl 30s;

broadcast

push_stream_broadcast_channelprefix "broad";

push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"eventid\":\"~event-id~\"}";

push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\"}";

subscriber may create channels on demand or only authorized

(publisher) may do it?

push_stream_authorized_channels_only off; push_stream_broadcast_channel_max_qtd 3;

server { listen 9080 default_server;

listen 9443 ssl;

#ssl_certificate     /usr/local/nginx/ssl/server.crt;
#ssl_certificate_key /usr/local/nginx/ssl/server.key;
server_name     localhost;
location @backend {
  internal;
  proxy_pass http://localhost:8080;
  #include proxy.inc; # Refer step 9
}
location ~ .*\.(php|jsp|cgi|pl|py)?$ {
  proxy_pass http://localhost:8080;
  #include proxy.inc; # Refer step 9
}
location ~ /\.ht {
  deny all;
}

location /channels-stats {
    # activate channels statistics mode for this location
    push_stream_channels_statistics;

    # query string based channel id
    set $push_stream_channel_id             $arg_id;
}

location /pub {
    # activate publisher mode for this location, with admin support
    push_stream_publisher admin ;

    # query string based channel id
    set $push_stream_channel_id             $arg_id;

    # store messages in memory
    push_stream_store_messages              on;
    # max messages to store in memory
    #push_stream_max_message_buffer_length   20;
    # message ttl
    #push_stream_min_message_buffer_timeout  5m;

    push_stream_keepalive                   on;

    # Message size limit
    # client_max_body_size MUST be equal to client_body_buffer_size or
    # you will be sorry.
    client_max_body_size                    32k;
    client_body_buffer_size                 32k;
}

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

    # positional channel path
    set $push_stream_channels_path              $1;

    # header to be sent when receiving new subscriber connection
    push_stream_header_template                 "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script type=\"text/javascript\">\r\nwindow.onError = null;\r\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-2).join('.');}catch(e){}\r\nparent.PushStream.register(this);\r\n</script>\r\n</head>\r\n<body>";
    # message template
    #push_stream_message_template                "<script>p(~id~,'~channel~','~text~','~event-id~');</script>";
    push_stream_message_template                "<script>p(~id~,'~channel~','~text~');</script>";
    # footer to be sent when finishing subscriber connection
    push_stream_footer_template                 "</body></html>";
    # content-type
    push_stream_content_type                    "text/html; charset=utf-8";
}

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

    # positional channel path
    set $push_stream_channels_path              $1;

    # activate event source support for this location
    push_stream_eventsource_support on;
}

location ~ /lp/(.*) {
    # activate long-polling mode for this location
    push_stream_subscriber      long-polling;
   push_stream_store_messages              on;

    # positional channel path
    set $push_stream_channels_path    $1;
}

location ~ /ws/(.*) {
    # activate websocket mode for this location
    push_stream_websocket;

    # positional channel path
    set $push_stream_channels_path              $1;

    # store messages in memory
    push_stream_store_messages              on;

    push_stream_websocket_allow_publish     on;
}

}

wandenberg commented 12 years ago

if you create n objects of PushStream you will be doing one connection to each object, and the browser has a limit to this. the right way to connect to multiple channels is the first one you used, calling the addChannel multiple times. probably you are doing something wrong when publishing the messages, I did a test here and everything worked.

Regards, Wandenberg

pokal4u commented 12 years ago

Hi, Thanks for reply.

Actually i am doing gmail type chat application, so i am trying to create individual channels

here i am created one 'pushstream object' and add 'multiple channels' and 'connect all onetime' like this var pushstream = new PushStream({ host: window.location.hostname, port: window.location.port, modes: "longpolling", secondsAgo:3600

}); pushstream.addChannel('chan1'); pushstream.addChannel('chan2'); pushstream.addChannel('chan3'); pushstream.addChannel('chan4'); pushstream.addChannel('chan5');

pushstream.connect();

please let me know where i done mistake? and tell me how to connect?

Thanks