1

I am working on a realtime multiplayer game which was built using Ratchet 0.3.3, Laravel 5 and PHP 5.5.9, The server OS is Ubuntu. The server sends approximately 500 bytes of data in each cycle to every user via WebSocket (hundreds of users). It looks like WebSocket is buffering the requests and sends 5 to 6 requests at once (500 bytes each). We have 30 millisecond cycles. Is there a way to manually set the WebSocket buffer settings , so my requests can be sent with no delays ?

Daniel Ansari
  • 106
  • 1
  • 5
  • I can't understand your issue very clearly. is your websocket server will send messages to the connected clients every 30 millisecond? But now your clients will get 5 or 6 messages once? And What do you mean "send each request in every cycle"? – Gary Liu Nov 09 '15 at 06:25
  • Yes My websocket server sends message to connected clients every 30 millisecond . The problem is these messages are somehow queued , and clients get 5 or 6 messages at once. I need to send each message whenever server generates it. – Daniel Ansari Nov 09 '15 at 06:59
  • Sounds like you're falling victim to Nagle's Algorithm. I'd suggest setting the `TCP_NODELAY` flag, but you're using Ratchet... – Ghedipunk Nov 09 '15 at 22:24

2 Answers2

2

I found a solution for that problem. First, IoServer class created and extend IoServer from Ratchet.

class IoServer extends \Ratchet\Server\IoServer {

    public static function factory(MessageComponentInterface $component, $port = 80, $address = '0.0.0.0') {
        $loop   = LoopFactory::create();
        $socket = new Reactor($loop);
        $socket->listen($port, $address);
        $sock = socket_import_stream($socket->master);
        socket_set_option($sock, SOL_TCP, TCP_NODELAY, true);

        return new static($component, $socket, $loop);
    }
}
Daniel Ansari
  • 106
  • 1
  • 5
0

Azure itself does not have any certain restrictions on the buffer setting for the Ubuntu VM. First I would check the current buffer setting values using the commands listed here - How to find the socket buffer size of linux. Secondly, if you want to configure or tune them, you can refer - http://www.cyberciti.biz/faq/linux-tcp-tuning/

Not sure if this is the answer you are looking for, as Ghedipunk pointed, it might be a issue of Nagle's algo, in which case, you might want to try adding the tcp_nodelay configuration in the tunnel configurations -

socket = l:TCP_NODELAY=1 socket = r:TCP_NODELAY=1

though I personally never worked with Ratchet.

PS- I wanted to add this as a comment as I am not sure this is the correct answer you are looking for, but SO forum is not allowing me to add a comment.

Community
  • 1
  • 1