- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想知道 node.js 是否正在为以下场景使用缓存,或者是否存在用于该场景的模块:
例如,如果您有一个 Web 门户网站,它在首页显示 20 个带有图像的产品,每次服务器都必须从 hdd 或最好的情况下从 ssd 获取图像。对于每个单独的图像,服务器需要大约 5-7 毫秒。当您有 50 个用户同时访问起始页时,需要 20img * 5ms * 50 usr = 5000ms 才能在硬盘上找到图像。
因此,如果有一种方法可以将所有常用文件(如图像、css、html 等)保存在内存中,那就太好了。所以您只需定义缓存大小即可。例如 50MB 和 module/node.js 将经常使用的文件保留在缓存中。
最佳答案
Node.js 本身(默认情况下)不做任何缓存,尽管操作系统和其他较低层元素(例如 HDD)可能会做,从而显着加快连续读取。
如果你想在 nodejs 中启用缓存的 http 响应,有一个 http-cache
库 - https://www.npmjs.com/package/http-cache和 request-caching
库 - https://www.npmjs.com/package/node-request-caching .对于缓存文件,您可以使用 filecache
https://www.npmjs.com/package/filecache并用于提供静态文件 - serve-static
( https://www.npmjs.com/package/serve-static )。
如果您使用的是 Express 等框架,那就不再那么简单了 - 例如,在生产模式下运行 Express 会导致它缓存一些内容(如模板或 CSS)。另请注意,res.sendFile
将文件直接流式传输给客户(可能是代理服务器,例如 nginx)
但是,即使是 Express 的网页(http://expressjs.com/en/advanced/best-practice-performance.html)也建议使用单独的代理:
Cache request results
Another strategy to improve the performance inproduction is to cache the result of requests, so that your app doesnot repeat the operation to serve the same request repeatedly.
Use a caching server like Varnish or Nginx (see also Nginx Caching) togreatly improve the speed and performance of your app.
有关加速 nodejs 的其他建议,您可以查看 https://engineering.gosquared.com/making-dashboard-faster或 http://www.sitepoint.com/10-tips-make-node-js-web-app-faster/
关于node.js - node.js/nginx 是否对常用文件使用内部缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36480513/
本文主要给大家介绍Mysql数据库分库和分表方式(常用),涉及到mysql数据库相关知识,对mysql数据库分库分表相关知识感兴趣的朋友一起学习吧 1 分库 1.1 按照功能分库 按照功能进行
在当前对象由其他包含对象操作的系统中,当传递对当前对象的引用时,链接似乎一直在继续......没有任何结束(对于下面的代码,Car ->myCurrentComponent->myCar_Brake-
我有一个密码 UIAlertView,我们要求用户提供。我需要根据情况在不同的 View 上询问它,从 downloadViewController (用户下载数据后),当他们切换到他们的数据时(如果
我正在尝试编写一个函数,使得对于任何整数 x 的 P(x) 都有一个包含三个元素的列表,即平方、立方和 n 的四次方,但我仍然不知道如何组合然后制作一个函数,例如我有平方、立方体和 4 次幂函数下面是
关闭。这个问题需要更多 focused .它目前不接受答案。 关闭4年前。 锁定。这个问题及其答案是locked因为这个问题是题外话,但具有历史意义。它目前不接受新的答案或交互。 我能否列出一份常见的
Python 常用 PEP8 编码规范 代码布局 缩进 每级缩进用4个空格。 括号中使用垂直隐式缩进或使用悬挂缩进。 EXAMPLE: ?
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 去年关闭。 Improve this questio
在经典 ui 中,您可以使用 xtype:cqinclude 包含来自不同路径的 rtePlugins,基本上为标准 RTE 插件创建一个位置,我如何在 Touch UI 中执行相同操作? 我尝试使用
在经典 ui 中,您可以使用 xtype:cqinclude 包含来自不同路径的 rtePlugins,基本上为标准 RTE 插件创建一个位置,我如何在 Touch UI 中执行相同操作? 我尝试使用
*strong text*我有多个网络应用程序使用了一些常见的依赖项,比如蒙戈连接器谷歌 Guava 乔达时间 我想到将它们从 webapp/WEB-INF/lib 中取出并放入一些 common-l
我正在编写一个 Web 服务器,我想知道哪些 HTTP 请求 header (由客户端发送)是最常见的,因此我应该重点实现。 目前,我只支持Accept 和Host。 最佳答案 不确定您的范围,但由于
我是一名优秀的程序员,十分优秀!