Should connection pooling be used?
Last updated 22, Mar 2024
Question
Should connection pooling be used?
Answer
It is always recommended to use connection pooling. Otherwise, each request will open a new connection. This exposes you to many possible momentary problems that could prevent the opening of the connection. In addition, if you make many requests, you will be frequently opening and closing connections, operations that might fail from time to time. Using connection pooling, you will open a few connections that will serve all the requests and not close after each request. This eliminates the problems above and will also give you better performance because no time will be wasted on opening and closing connections. Redis connections are kept open forever unless the client closes them or doesn't reply to TCP keep-alive messages. Redis will close idle connections that do not answer the keepalive for five consecutive minutes. Then, Redis can only assume that clients have closed their connections.
References
If you want to look at your active connections, you can always use the CLIENT LIST command. Examples of clients with connection pooling:
Not all the clients make the connection pooling feature available: StackExchange, as an example, multiplexes a single connection.