Open topic with navigation
Client-Server Timeouts
Every client/server application has to face a problem of
network communications. Luckily modern protocols screen the end-application
from all fixable problems. However there are still physical reasons that can't
be fixed by a protocol: disconnections, power failures, crash of a system on
the other end of communication channel etc. In these cases it is still the
responsibility of the client-server application to exit the connection
gracefully, releasing all resources and protecting data.
In order to achieve an efficient client/server communication
and handling of connection problems the following requirements were defined for
db4o:
- The connection should not
be terminated when both client and server are still alive, even if either
of the machines is running under heavy load.
- Whenever a client dies,
peacefully or with a crash, the server should clean up all resources that
were reserved for the client.
- Whenever a server goes
offline, it should be possible for the client to detect that there is a problem.
- Since many clients may be
connected at the same time, it makes sense to be careful with the
resources the server reserves for each client.
- A client can be a very
small machine, so it would be good if the client application can work with
a single thread.
Unfortunately all the requirements are difficult to achieve
for a cross-platform application, as Java and .NET sockets behave differently.
The current approach tries to keep things as simple as
possible: any connection is closed immediately upon a timeout. In order to
prevent closing connections when there is no communication between client and
server due to reasons different from connection problems a separate timer
thread was created to send messages to the server at a regular basis. The
server must reply to the thread immediately, if this does not happen the
communication channel gets closed.
This approach works effectively for both client and server side. However
there's are small downside to this. When a server operation takes longer than the timeout, the connection will be closed. You can configure the timeouts for the client and the server.
An easy rule of thumb:
- If you experience clients disconnecting, raise the timeout value.
- If you have a system where clients crash frequently or where the network is
very instable, lower the values, so resources for disconnected clients are
freed faster.