Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Redis Connection Pooling

When using node_redis Node.js module with Redis, should I just use one connection as Redis is single thread process or shall I create a pool of connections to improve performance?

like image 546
Vad Avatar asked Feb 23 '14 23:02

Vad


People also ask

Do you need connection pooling for redis?

If we create a separate Redis connection for a thread it will be overhead for the Redis server. We need to have a pool of connections in multi-threaded environments to address these challenges. This allows us to talk to Redis from multiple threads while still getting the benefits of reused connections.

Can redis handle multiple connections?

Redis can handle many connections, and by default, Redis has a maximum number of client connections set at 10,000 connections. You can set the maximum number of client connections you want the Redis server to accept by altering the maxclient from within the redis. conf file.

What is redis pool size?

To improve performance, go-redis automatically manages a pool of network connections (sockets). By default, the pool size is 10 connections per every available CPU as reported by runtime.

How does redis integrate with node js?

Create new session. js file in the root directory with the following content: const express = require('express'); const session = require('express-session'); const redis = require('redis'); const client = redis. createClient(); const redisStore = require('connect-redis')(session); const app = express(); app.


2 Answers

Just use a single connection. Both Node and Redis are effectively single thread. I don't think you'll gain anything by having multiple connections. I asked a similar question before starting to develop with Redis and it seems that one client/one application is pretty effective pattern.

like image 164
stockholmux Avatar answered Oct 07 '22 18:10

stockholmux


There is a use case for pooling multiple connections, actually: blocking commands like BRPOP and SUBSCRIBE.

like image 42
VPhantom Avatar answered Oct 07 '22 17:10

VPhantom