In order to achieve an efficient client/server communication and handling of connection problems the following requirements were defined for db4o:
Unfortunately all the requirements are difficult to achieve for a cross-platform application, as Java and .NET sockets behave differently.
The initial db4o CS implementation used one-thread clients and connection was terminated when there was a timeout and a post-timeout check-up message could not get a response from the other side. However this approach failed for .NET implementation, as .NET sockets upon timeout continue to send and receive messages, but timeout settings are not respected anymore, which in fact leads to a very high CPU usage.
The next approach was to create a separate housekeeping thread on the server, which will send messages to the client regularly, thus checking if the client is still alive and in the same time giving the client information about the server. Unfortunately, the problem described above can occur to the housekeeping thread too.
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 are two small downsides:
1. Clients are not single-threaded anymore
2. If an action on the server takes longer than the socket timeout, the connection will be closed.
In the latter case you can adjust the behaviour of db4o with the following configuration settings:
.NET:
configuration.ClientServer().TimeoutServerSocket(int
milliseconds)
configuration.ClientServer().TimeoutClientSocket(int
milliseconds)
An easy rule of thumb: