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

Max size for websocket #86

Closed IPv6 closed 11 years ago

IPv6 commented 11 years ago

I am using this module to send data to connected clients (via websockets). But there is one strange thing is going: all is fine while amount of data sent to client (via websocket channel) is small. But when server have to send a lot of data (50kb-100kb), client disconnects. Right after receiving this data, happens every time. So how it goes: Server send 100Kb of text->client receives 100Kb of text without errors->right after that socket shutdowned (client receive "socket closed" event from browser)->client recconnects. This is very annoing/resource consuming

Please, advice how this can be fixed. Is there any limits in size of pushed messages? who is closing socket, may be this is Nginx? But i failed to find any relevant options to tune (

Thanks in advance!

wandenberg commented 11 years ago

Hi,

the websocket implementation follow the specs. This problem will happens in any other protocol you use with push stream module if you not tune the write and read socket buffers on your server. When the module tries to write some data to the socket and receives an error it closes the socket. Check these O.S. parameters regarding with socket buffers.

IPv6 commented 11 years ago

Thanks, i will try.

-- Additional information, may be you found it helpful -- We are running online game and after several hours of peak workload push module started to throw 2013/07/04 05:37:22 [error] 6704#0: *132243 push stream module: unable to allocate message in shared memory and there is no "ngx_slab_alloc() failed" errors, just push stream module`s

module stats gives information that there is only 3 subscribers (because game refused to work :) over night), so any garbage collection should be done already:

u'pushmod': { u'broadcast_channels': u'0', u'by_worker': [ { u'pid': u'6698', u'subscribers': u'0', u'uptime': u'44556'}, { u'pid': u'6699', u'subscribers': u'0', u'uptime': u'44556'}, { u'pid': u'6700', u'subscribers': u'0', u'uptime': u'44556'}, { u'pid': u'6701', u'subscribers': u'2', u'uptime': u'44556'}, { u'pid': u'6702', u'subscribers': u'0', u'uptime': u'44556'}, { u'pid': u'6703', u'subscribers': u'0', u'uptime': u'44556'}, { u'pid': u'6704', u'subscribers': u'1', u'uptime': u'44556'}], u'channels': u'4', u'channels_in_trash': u'0', u'hostname': u'debian-60-squeeze-64-minimal', u'messages_in_trash': u'0',u'published_messages': u'5736', u'stored_messages': u'0', u'subscribers': u'3', u'time': u'2013-07-04T03:59:08', u'uptime': u'44556'}

nginx conf as follow { lua_code_cache on; push_stream_shared_memory_size 128M; push_stream_max_messages_stored_per_channel 20; push_stream_shared_memory_cleanup_objects_ttl 10s; push_stream_channel_inactivity_time 120s; push_stream_message_ttl 120s;

        location ^~ /rtapi4/pub {
            more_set_headers 'Content-Type: text/plain; charset=UTF-8';
            push_stream_publisher;
            push_stream_keepalive on;
            push_stream_store_messages on;
            set $push_stream_channel_id $arg_rtslot;
        }

        location ^~ /rtapi4/sub {
            more_set_headers 'Content-Type: text/plain; charset=UTF-8';
            push_stream_websocket;
            push_stream_subscriber_connection_ttl       360s;
            push_stream_ping_message_interval           10s;
            set $push_stream_channels_path              $arg_rtslots;
            #push_stream_websocket_allow_publish         on;
            #body_filter_by_lua '
            #   local handlers = require("wli_api.server");
            #   handlers.setup_request_context();
            #   handlers.request_pubsub_onmessage();
            #';
        }

}

IPv6 commented 11 years ago

after tuning sysctl tcp parameters problem is gone. but memory problems still exist (with low amount of subscribers + enough memory), i`ll create separate issue (may be somebody will be able to advise something) if you dont mind