Node.js,将对象存储在内存或数据库中? [英] Node.js, store object in memory or database?
问题描述
正在开发一个节点js应用程序,它从集中式数据库读取一个json列表
Am developing a node js application, which reads a json list from a centralised db
List Object
是大约1.2mb(如果保存在txt文件中)
List Object
is around 1.2mb(if kept in txt file)
要求就像,数据每24小时刷新一次,所以我保留了一份cron工作
Requirement is like, data is to be refreshed every 24 hours, so i kept a cron job for it
现在获取数据后我将其保存到我的服务器本地运行的db(couchbase)
Now after fetching data i keep it into a db(couchbase) which is locally running on my server
数据访问非常频繁,我每秒约1或2 req,几乎所有req需要对象
Data access is very frequent, i get around 1 or 2 req per sec and nearly all req need that Object
是将 Object
保留为节点js中的内存对象或将其保存在本地数据库中是否很好?
Is it good to keep that Object
as a in memory object in node js or to keep it in local db ?
两者的优点和缺点是什么?
What are the advantages and disadvantages of both ?
对象
仅读取所有请求,仅由cron作业写过一次
Object
only read for all requests , only written once by cron job
这是一个高端系统,i7四核,16GB ram
推荐答案
- 这取决于你的硬件
- 如果此对象是不可变的,则根据请求,最好将其保留在内存中。如果没有 - 依赖。
- 在任何情况下,工作流打开连接到db - 获取数据 - 返回结果 - 免费数据将比内存中的缓存消耗更多资源。
例如,在我们的项目中,我们处理高清图像,并将所有对象保存在内存中 - 原始格式为3-7mb。测试表明,这比使用任何缓存系统(如redis或沙发基座)更有效。
For example, in our project we processing high definition images, and keep all objects in memory - 3-7mb in raw format. Tests shows that this is much efficient than usage of any caching systems, such as redis or couch base.
这篇关于Node.js,将对象存储在内存或数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!