Since the accepted answer is only associated with remote hosts, it is obvious that it will always be slower than localhost. Even if this is the next computer in your home, it will take milliseconds to read from this computer, but local memory only takes nanoseconds. You must compare them using locally installed servers.
Here are my results from my local computer: you see, redis is almost as fast as in memory, under high load. You can clone my repo to make these test codes available: https://github.com/mustafaakin/express-session-store-benchmark
Concurrency: 1 none 4484.86 [#/sec] memory 2144.15 [#/sec] redis 1891.96 [#/sec] mongo 710.85 [#/sec] Concurrency: 10 none 5737.21 [#/sec] memory 3336.45 [#/sec] redis 3164.84 [#/sec] mongo 1783.65 [#/sec] Concurrency: 100 none 5500.41 [#/sec] memory 3274.33 [#/sec] redis 3269.49 [#/sec] mongo 2416.72 [#/sec] Concurrency: 500 none 5008.14 [#/sec] memory 3137.93 [#/sec] redis 3122.37 [#/sec] mongo 2258.21 [#/sec]
The session pages used are very simple pages;
app.get("/", function(req,res){ if ( req.session && req.session.no){ req.session.no = req.session.no + 1; } else { req.session.no = 1; } res.send("No: " + req.session.no); });
Redis save configuration:
app.use(express.session({ store: new RedisStore({ host: 'localhost', port: 6379, db: 2, }), secret: 'hello' }));
Mongo Store Configuration:
app.use(express.cookieParser()); app.use(express.session({ store: new MongoStore({ url: 'mongodb://localhost/test-session' }), secret: 'hello' }));
Mustafa Nov 05 '13 at 20:05 2013-11-05 20:05
source share