HTML and CSS Reference
WebSocket Buffering and Throttling
With WebSocket applications using full-duplex connections, you can control the rate
at which applications send data to the server, also known as “throttling.” Throttling the
traffic can help avoid saturation or bottlenecks in the network that may be influenced by
other limitations, such as Internet bandwidth and server CPU limits, which we'll discuss
in the subsequent sections. The WebSocket API enables you to control the rate that the
applications send data to the server, with the WebSocket bufferedAmount attribute, which
we discussed in Chapter 2. The bufferedAmount attribute represents the number of bytes
that have been queued but not transmitted to the server yet.
You can also throttle client connections to the server and allow the server to
determine whether to accept or reject the client connection depending on pre-defined
settings in the server.
To assess your system's performance, you can also configure a monitoring tool to track
user activity, server performance, and terminate client sessions, if necessary. Monitoring
is extremely useful not only in analyzing the health of your network and system, but also
in diagnosing the root cause of performance bottlenecks or failures and identifying areas
where you can tune aspects of the system for better performance.
Ideally, you should be able to provide visibility and control needed to assure that
business transactions are flowing through the system without any issues and meeting the
service-level agreements (SLAs).
Implementing WebSocket in your architecture enables you to build flexible and scalable
frameworks. Even with this flexibility, you must still plan for the needs of the deployment,
including sizing considerations, specifically in relation to hardware capacity. Among
these areas are the memory and CPU of the server (whether it's your back-end server that
has been WebSocket-enabled or a gateway that enables WebSocket traffic to flow between
clients and back-end servers), and network optimization. In general, sizing means
estimating the hardware requirements for your application.
Table 8-2 describes areas you may want to take into account when thinking about
the hardware requirements for your WebSocket application. The items in this checklist
contain factors to consider when deploying any application and may certainly change
over time as your user base, data, and system grow.