In high-traffic situations, performance of a server is usually limited by the network bandwidth or by the CPU usage of the server's higher layers. MUSES itself should not represent a performance bottleneck; nevertheless, there are some aspects of MUSES that must be taken into account during optimization.
There is little to do about incoming traffic. In many realistic cases, each
client receives what every other client is sending. If this is true, the total
output is proportional to the square of total input; as a consequence, when
there are many connections open, incoming traffic has negligible effects
when compared to outgoing traffic. Even if this is not the case, reading
network input into your application is usually a straightforward process,
unless you write a complicated ReceiveHandler
.
From the point of view of reducing input-related workload, two things can be done:
Connection::setBufferSize()
. Do not make
the buffer too small, or you might even prevent the server from accepting
client input.
ReceiveHandler
, if a profiler tells you
it is a performance bottleneck.
Optimizing outgoing traffic is usually a better strategy, both because there
is more to be gained, and because there are more efficient techniques. First
of all, you may want to use a simple SendFilter
(perhaps the default
raw filter, if you're certain your server is not going to send IAC to
a telnet client). Avoid frequent changes of the filter, unless they're
really necessary.
More importantly, consider the overhead associated to each outgoing network
packet. Sending a single 1000-byte packet is much more efficient than
sending 1000 1-byte packets. Therefore, don't flush
the output buffer
unless you really need to. By the way, did you know that endl
flushes
the buffer? If you need to send a multi-line text, put a CR/LF in the text,
rather than resorting to endl
.
For more information, see your operating system documentation (try
man setsockopt
).
To summarize:
endl
when you don't need to flush
SendFilter
simple, and don't change it too often
Go to the first, previous, next, last section, table of contents.