博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Node.js session 存储的几种方法
阅读量:6971 次
发布时间:2019-06-27

本文共 1763 字,大约阅读时间需要 5 分钟。

hot3.png

    Since the accepted answer is only connecting to remote hosts, it is obvious thatit will be always slower than localhost. Even if it is the next computer in your home, it would take milliseconds to read from that computer, but local memory takes only nanoseconds. You should compare them by using locally installed servers.

Here are my results from my local pc: You see, redis is almost as fast as in-memory in under high load. You can clone my the repo that these test codes are available: 

node.js session store 有可选的四种方法的性能测试如下:

Concurrency: 1none       4484.86 [#/sec] memory     2144.15 [#/sec] redis      1891.96 [#/sec] mongo      710.85 [#/sec] Concurrency: 10none       5737.21 [#/sec] memory     3336.45 [#/sec] redis      3164.84 [#/sec] mongo      1783.65 [#/sec] Concurrency: 100none       5500.41 [#/sec] memory     3274.33 [#/sec] redis      3269.49 [#/sec] mongo      2416.72 [#/sec] Concurrency: 500none       5008.14 [#/sec] memory     3137.93 [#/sec] redis      3122.37 [#/sec] mongo      2258.21 [#/sec]

对比得出redis来存储在并发性越多的情况下性能优越。

    The session used pages are very simple pages;

app.get("/", function(req,res){    if ( req.session && req.session.user_id){        req.session.no = req.session.user_id;    } else {        throw Error('error');    }    res.send("No: " + req.session.no);});

Redis store config:

app.use(express.session({    store: new RedisStore({        host: 'localhost',        port: 6379,        db: 2,        }),    secret: 'hello'}));

Mongo store config:

app.use(express.cookieParser());app.use(express.session({    store: new MongoStore({        url: 'mongodb://localhost/test-session'    }),    secret: 'hello'}));

 在使用mongodb存储时别忘记在加载一个模块:connect-mongo

npm install connect-mongo

转载于:https://my.oschina.net/antianlu/blog/186645

你可能感兴趣的文章
【转】app瘦身
查看>>
拓扑排序
查看>>
【转】获取Windows系统明文密码神器
查看>>
Rhel6-keepalived+lvs配置文档
查看>>
Paint.FontMetrics
查看>>
笔记本分类大全
查看>>
C/S 登录跳转/系统升级
查看>>
git的使用
查看>>
.NET MVC+EF CodeFirst+IOC+EasyUI 框架设计教程(概述)
查看>>
变态方式实现大数据量转换的小表热点盘问题
查看>>
算法是什么(〇)
查看>>
(转)优先队列用法
查看>>
poj 3126 Prime Path (bfs)
查看>>
MySQL报错
查看>>
Atom打开txt文件中文乱码解决、指定文件的语法格式、win10中禁止睡眠
查看>>
OCP读书笔记(3) - 使用RMAN恢复目录
查看>>
Notepad++ 配置 支持jquery、html、css、javascript、php代码提示
查看>>
Linux常用命令1
查看>>
几张动态图弄懂递归,二叉树,二分查找简短算法
查看>>
javascript中的数组去重
查看>>