c++websocketqueueoverloading

Information overload from a websocket


I am just very thankful that stackoverflow exists, so many questions that would have taken me hours, they are answred here from exprienced people, thanks everyone :).

One question I have, suppose I am connected to a server via a websocket that sends me data every 1 second, and I am processing that data in a function call it on_feed(cons map_t& m). Suppose each on_feed call takes 2 seconds, what will happend? Is there an internal queue in the OS that will process the input and queue them?

I hope I am clear, if not what happens if a server sends data too quickly that I can't process it as my process takes time. (I don't want to use my own queue :) )

Thanks!!


Solution

  • Is there an internal queue in the OS that will process the input and queue them?"

    Most operating system kernels do not have built-in support for the WebSocket protocol. They generally only provide TCP/IP support. You will probably be using a WebSocket library which will be linked to your program. This library will likely not be part of the operating system (in the narrow sense). In order to support WebSocket messages, this library will probably have its own input queue.

    what happens if a server sends data too quickly that I can't process it as my process takes time

    If the input queue of the WebSocket library is full, then the WebSocket library will probably stop accepting new data from the server, until more input has been processed and there is room in the queue to accept new input.

    Therefore, it should generally not be a problem if a server attempts to send data faster than the client can process.

    If the server software is programmed to send new data sets to the client at a certain rate, but the client is unable to process the data sets at this rate, then the client will probably stop accepting new data after some time, due to its input buffer being full. After that, the server's output buffer will start to fill. If the server software is well-designed, then it should be able to handle this situation well, and it will stop generating data once the output buffer is full, until there is room again in the output buffer.

    However, if the server software is not well-designed, then, depending on the situtation, it may not be able to cope with this type of problem. But most popular server software is well-designed in this respect.

    Nevertheless, even well-designed server software may expect the client to be able to process the WebSocket messages within a reasonable time frame, and the server may decide to abort the connection if the client is taking an unresonable amount of time.