简体   繁体   English

如何管理节点js中的内存

[英]How do I manage memory in node js

I'm writing a node.js software module which stores a number of strings of varying length in an object map. 我正在编写一个node.js软件模块,它在对象图中存储了许多不同长度的字符串。 This is essentially serving as a in memory cache for my overall software. 这基本上是我整个软件的内存缓存。

I was wondering how do I account for the fact that more memory will be used up the longer my application is running and I understand node processes by default have a memory limit imposed by the v8 engine. 我想知道如何解释这样一个事实,即在我的应用程序运行的时间越长,内存将被用尽,我理解节点进程默认情况下具有v8引擎强加的内存限制。

I have already put in place code which after a certain time removes old cache entries but this does not protect against a lot of cache entries being placed in a short amount of time. 我已经放置了一段代码,在一段时间后删除了旧的缓存条目,但这并不能防止很多缓存条目在很短的时间内被放置。

As dm03514 says, use a dedicated cache component. 正如dm03514所说,使用专用的缓存组件。 Memcached will do this for you, as will Redis. Memcached会为你做这件事,Redis也是如此。

The main problem you will face is invalidation, both of these allow you to set expiry times for keys. 您将面临的主要问题是失效,这两个问题都允许您设置密钥的到期时间。

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

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