花了一天的时间调查这件事.以下是我发现的选项.每秒的请求通过本地机器上的ab -n 100000 -c 1 http://127.0.0.1:9778/
执行.
- 无会话-快速(438请求/秒)
- cookieSession:不需要外部服务,速度影响较小(311请求/秒)-最快,会话将随着cookie过期(由
maxAge
定制)
- connect-redis:需要redis服务器,速度影响大(使用redis2go和redisgreen时每秒4个请求)-比mongo更快,会话将在一段时间后被删除(由
ttl
定制)
- connect-mongo-需要mongodb服务器,速度影响大(mongohq为2 req/sec)-比redis慢,需要将manual
clear_interval
设置为清理会话
以下是我在cookieSession上使用的咖啡脚本:
server.use express.cookieSession({
secret: appConfig.site.salt
cookie: maxAge: 1000*60*60
})
以下是我为redis使用的咖啡脚本:
RedisSessionStore ?= require('connect-redis')(express)
redisSessionStore ?= new RedisSessionStore(
host: appConfig.databaseRedis.host
port: appConfig.databaseRedis.port
db: appConfig.databaseRedis.username
pass: appConfig.databaseRedis.password
no_ready_check: true
ttl: 60*60 # hour
)
server.use express.session({
secret: appConfig.site.salt
cookie: maxAge: 1000*60*60
store: redisSessionStore
})
以下是我为mongo准备的咖啡脚本:
server.use express.session({
secret: appConfig.site.salt
cookie:
maxAge: 100*60*60
store: new MongoSessionStore({
db: appConfig.database.name
host: appConfig.database.host
port: appConfig.database.port
username: appConfig.database.username
password: appConfig.database.password
auto_reconnect: appConfig.database.serverOptions.auto_reconnect
clear_interval: 60*60 # hour
})
})
当然,远程redis和mongo数据库的运行速度将比本地同类数据库慢.I just couldn't get the local equivalents working, especially considering the installation and maintenance time for me was far more than what I was willing to invest when compared with hosted remote alternatives, something I feel is true for others too hence why these hosted remote database services exist in the first place!
有关本地数据库benhmarks,请参见@Mustafa's answer.
很高兴有人到了edit this answer岁,可以将本地数据库基准添加到这个组合中.