Chapter 6. Implementation details: How was this done?

Table of Contents
Postgres protocol and pooling
Connection recovery
Thread and connection load adaptability
Another databases

Postgres protocol and pooling

When a DBBalancerDaemon starts, it inits a number of connections with every one of the backend hosts. These connections are conducted through the authentication procedure and leaved in that state, waiting for connections.

When a client wants a connection, the daemon carries the authentication procedure with the client. If the procedure finishes ok, the rest of the client protocol information is redirected right to one of the backend connections, only taking care of intercept the connection close message. When this message is received, the daemon marks the backend connection as free and then closes the socket connection to the client. As we seen, almost all the protocol data (except connection start and connection close) is transparently sent between the client and the backend server, which is good for performance.