简体   繁体   English

nodeJS,mongoDB,express,eJS-关于内存缓存的意见

[英]nodeJS, mongoDB, express, eJS - opinions on memory caching

I'm building my first site using this framework, i'm remaking a website i had done in PHP+mySQL and wish to know something about performance... In my website, i have two kinds of content: 我正在使用此框架构建我的第一个网站,我正在重建一个用PHP + mySQL完成的网站,希望对性能有所了解...在我的网站中,我有两种内容:

  • Blog Posts (for 2 sections of the site) - these have the tendency to one day sum to thousands of records and, are more often updated 博客文章(针对网站的两个部分)-这些文章倾向于一天之内汇总成千上万的记录,并且经常更新
  • Static (sort of) data: this is information i keep in the database, like site section's data (title, metatags, header image url, fixed html content, javascript and css filenames to include in that section), that is rarely updated and it's very small in size. 静态(某种)数据:这是我保存在数据库中的信息,例如网站部分的数据(标题,元标记,标头图片url,固定的html内容,要包含在该部分中的javascript和css文件名),该信息很少更新,并且很小。

While i was learning the basics on nodeJS, i started thinking of a way to improve the performance of the website, in a way i couldn't do with PHP. 当我学习有关nodeJS的基础知识时,我开始考虑一种无法使用PHP来改善网站性能的方法。 So, what i'm doing is: 所以,我正在做的是:

When i run the app, the static content is all loaded into memory, i have a "model" Object for each content that stores the data in an array, has a method to refresh that data, ie, when the administrator updates something, i call refresh() to go get the new data from the database to that array. 当我运行该应用程序时,静态内容全部加载到内存中,对于每个将数据存储在数组中的内容,我都有一个“模型”对象,具有刷新该数据的方法,即,当管理员更新某些内容时,调用refresh()将新数据从数据库获取到该数组。 In this way, for every page load, instead of querying the database, the app queries the object in memory directly. 这样,对于每个页面加载,应用程序都直接查询内存中的对象,而不是查询数据库。

What i would like to know is if there should be any increase of performance, working with objects directly in memory or if constant queries to the database would work just as good or even better. 我想知道的是,是否应该提高性能,直接在内存中使用对象,或者对数据库的持续查询是否同样有效甚至更好。

Any documentation supporting your answer will be much appreciated. 任何支持您答案的文档将不胜感激。

Thanks 谢谢

In terms of the general database performance, MongoDB will keep your working set in memory - that's its basic method of operation. 在一般数据库性能方面,MongoDB会将您的工作集保存在内存中-这是其基本操作方法。

So, as long as there is no memory contention to cause the data to get swapped out, and it is not too large to fit into your physical RAM, then the queries to the database should be extremely fast (in the sub millisecond range once you have your data set paged in initially). 因此,只要不存在引起数据交换的内存争用,并且它不会太大而无法放入您的物理RAM中,那么对数据库的查询就应该非常快(一旦您将其保留在亚毫秒范围内)首先将您的数据集放入页面)。

Of course, if the database is on a different host then you have network latency to think about and such, but theoretically you can treat them as the same until you have a reason to question it. 当然,如果数据库位于其他主机上,则您需要考虑网络延迟,但是从理论上讲,您可以将它们视为相同,直到您有理由质疑它为止。

I don't think there will be any performance difference. 我认为不会有任何性能差异。 First thing is that this static data is probably not so big (up to 100 records?) and querying DB for it is not a big deal. 第一件事是该静态数据可能不会很大(最多100条记录?),并且查询数据库也没什么大不了的。 Second thing (more important) is that most DB engines (including mongoDB) have caching systems built-in (although I'm not sure how they work in details). 第二件事(更重要的是)是大多数数据库引擎(包括mongoDB)具有内置的缓存系统(尽管我不确定它们如何工作)。 Third thing is that holding query results in memory does not scale well (for big websites) unless you use storage engine like Redis . 第三件事是,除非使用Redis这样的存储引擎,否则将查询结果保存在内存中的伸缩性不好(对于大型网站)。 And that's my opinion, although I'm not the expert. 这是我的观点,尽管我不是专家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM