报错如下
FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory
我的代码
connection.query('select * from `table` limit 100000', function(err, rows, fields) {
数据库里的链接大概做了个队列 就是 不断取数据 大概每次做 1W 大多时候 运行不稳定 出如上报错
var array = [1,2,3,4];
function check()
{
if(array.length > 0)
var url = array.pop();
load(url);
}}
function load(url)
{
http.get(url, function(res){
check();
)
}}
http://stackoverflow.com/ques... 跟这个情况类似
请问怎么解决比较好 能不能不断清楚内存的垃圾?
If I count correctly, you are taking out 100,000 records at one time. If you estimate that one row of records is 10K, 100,000 records is about 1 G of memory, so OOM occurs
The best way to deal with this problem is
stream processing
. You will need this method. Set eachhighWaterMark
to 10,000. For example, your total There are 1 million pieces of data to be taken out. You don’t have to control the array and load under your code. Write aReadStream
that processes 10,000 pieces at a time流处理
,你会需要这个方法的,把每一次的highWaterMark
设置成1万,比方说你总共有100万条数据要取出来,你也不用自己去控制了你代码下面的array和load,写好每次处理1万的ReadStream
TALK IS CHEAP, SHOW ME THE CODE
🎜TALK IS CHEAP, SHOW ME THE CODE🎜🎜 rrreee 🎜🎜🎜The pseudo code is as shown above,伪代码如上所示,
untest
根据自己实际业务改改untest
should be modified according to your actual business🎜🎜