我正在使用Tedious并RxJS
针对 SQL Server 运行 SQL 查询并使用Observable
. 这个函数定义了这个行为:
export function msExecute(sql) {
return new Observable(observer => {
config.database.sams.requestTimeout = 60000;
var connection = new mssql.Connection(config.database.sams, function (err) {
var request = new mssql.Request(connection);
request.stream = true;
request.query(sql);
request.on('row', row => {
observer.next(row);
});
request.on('error', err => {
observer.error(err);
});
request.on('done', () => {
observer.complete();
connection.close();
});
});
connection.on('error', error => console.log(`mssql error == ${error}`));
});
}
我有一个 SQL 查询,它返回要处理的 ~110k 记录,但在执行过程中出现此错误:
<--- Last few GCs --->
27330 ms: Scavenge 1396.7 (1457.4) -> 1396.7 (1457.4) MB, 1.4 / 0 ms (+ 2.0 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].
28635 ms: Mark-sweep 1396.7 (1457.4) -> 1396.6 (1457.4) MB, 1304.9 / 0 ms (+ 2.9 ms in 2 steps since start of marking, biggest step 2.0 ms) [last resort gc].
29936 ms: Mark-sweep 1396.6 (1457.4) -> 1396.5 (1457.4) MB, 1300.3 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x4035aee3ac1 <JS Object>
1: /* anonymous */(aka /* anonymous */) [/home/njones/projects/test-forge/node_modules/orawrap/lib/connectionmanager.js:250] [pc=0x20cbecafa065] (this=0x4035ae04189 <undefined>,resolve=0x3896ea762871 <JS Function resolvePromise (SharedFunctionInfo 0x203f09a91f11)>,reject=0x3896ea762829 <JS Function rejectPromise (SharedFunctionInfo 0x203f09a91fb9)>)
2: lib$es6$promise$$internal$$initiali...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
我不需要我曾经的所有结果,因此将结果分成单独的查询的解决方案会起作用,我只是不知道该怎么做。