OrientDB - 插入后不释放内存
OrientDB - don't release memory after insert
我使用 NodeJS 将 8.000.000 条记录插入到我的 orientdb 数据库中,但是在大约 2.000.000 条插入记录后我的应用程序停止并显示错误“Java 堆”。
有没有办法在每次插入记录后释放内存?
Ram usage:
-befor start app: 2.6g
-after insert 2milions records: 7.6g
我的 app.js (NodeJS):
var dbConn = [];
var dbNext = 0;
var dbMax = 25;
for (var i = 0; i <= dbMax; i++) {
var db = new ODatabase({
host: orientdb.host,
port: 2424,
username: 'root',
password: orientdb.password,
name: 'test',
});
dbConn.push(db);
}
//---------------------------------------------------
//Start loop
// record = {name: 'test'}
record["@class"] = "table";
var db = nextDB();
db.open().then(function () {
return db.record.create(record);
}).then(function (res) {
db.close().then(function () {
//----resume loop
});
}).error(function (err) {
//------
});
// end loop - iteration loop
//---------------------------------------------------
function nextDB() {
if (++dbNext >= dbMax) {
dbNext -= dbMax;
}
return dbConn[dbNext];
}
来自documentation,对于大量插入你应该声明你的意图:
db.declareIntent( new OIntentMassiveInsert() );
// YOUR MASSIVE INSERTION
db.declareIntent( null );
但是现在好像还没有在orientJS驱动中实现。
另一件事是你不应该 open/close 你的数据库为每条新记录创建。这通常是不好的做法。
我现在还没有 node.js 环境,但像这样应该可以解决问题:
db.open().then(function () {
// when available // db.declareIntent( new OIntentMassiveInsert() );
for (var i = 0; i < 8000000; i++) {
// create a new record
myRecord = { "@class" : "myClass", "attributePosition" : i };
db.record.create(myRecord);
}
// when available // db.declareIntent( null );
}).then(function () { db.close() });
OrientJS 无法有效地将大量数据从 SqlServer 插入到 OrientDB。我使用 ETL module 进行大量插入,这是在不增加内存超过 2GB 的情况下传输大量数据的最快方法和好主意。
我每分钟可以传输 7.000 条记录。
我的 ETL config.json:
{
"config": {
log : "debug"
},
"extractor" : {
"jdbc": { "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"url": "jdbc:sqlserver://10.10.10.10;databaseName=My_DB;",
"userName": "sa",
"userPassword": "123",
"query": "select * from My_Table"
}
},
"transformers" : [
{ "vertex": { "class": "Company"} }
],
"loader" : {
"orientdb": {
"dbURL": "plocal:D:\DB\Orient_DB",
dbUser: "admin",
dbPassword: "admin",
"dbAutoCreate": true,
"tx": false,
"batchCommit": 1000,
"wal" : false,
"dbType": "graph"
}
}
}
我使用 NodeJS 将 8.000.000 条记录插入到我的 orientdb 数据库中,但是在大约 2.000.000 条插入记录后我的应用程序停止并显示错误“Java 堆”。
有没有办法在每次插入记录后释放内存?
Ram usage:
-befor start app: 2.6g
-after insert 2milions records: 7.6g
我的 app.js (NodeJS):
var dbConn = [];
var dbNext = 0;
var dbMax = 25;
for (var i = 0; i <= dbMax; i++) {
var db = new ODatabase({
host: orientdb.host,
port: 2424,
username: 'root',
password: orientdb.password,
name: 'test',
});
dbConn.push(db);
}
//---------------------------------------------------
//Start loop
// record = {name: 'test'}
record["@class"] = "table";
var db = nextDB();
db.open().then(function () {
return db.record.create(record);
}).then(function (res) {
db.close().then(function () {
//----resume loop
});
}).error(function (err) {
//------
});
// end loop - iteration loop
//---------------------------------------------------
function nextDB() {
if (++dbNext >= dbMax) {
dbNext -= dbMax;
}
return dbConn[dbNext];
}
来自documentation,对于大量插入你应该声明你的意图:
db.declareIntent( new OIntentMassiveInsert() );
// YOUR MASSIVE INSERTION
db.declareIntent( null );
但是现在好像还没有在orientJS驱动中实现。 另一件事是你不应该 open/close 你的数据库为每条新记录创建。这通常是不好的做法。
我现在还没有 node.js 环境,但像这样应该可以解决问题:
db.open().then(function () {
// when available // db.declareIntent( new OIntentMassiveInsert() );
for (var i = 0; i < 8000000; i++) {
// create a new record
myRecord = { "@class" : "myClass", "attributePosition" : i };
db.record.create(myRecord);
}
// when available // db.declareIntent( null );
}).then(function () { db.close() });
OrientJS 无法有效地将大量数据从 SqlServer 插入到 OrientDB。我使用 ETL module 进行大量插入,这是在不增加内存超过 2GB 的情况下传输大量数据的最快方法和好主意。
我每分钟可以传输 7.000 条记录。
我的 ETL config.json:
{
"config": {
log : "debug"
},
"extractor" : {
"jdbc": { "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"url": "jdbc:sqlserver://10.10.10.10;databaseName=My_DB;",
"userName": "sa",
"userPassword": "123",
"query": "select * from My_Table"
}
},
"transformers" : [
{ "vertex": { "class": "Company"} }
],
"loader" : {
"orientdb": {
"dbURL": "plocal:D:\DB\Orient_DB",
dbUser: "admin",
dbPassword: "admin",
"dbAutoCreate": true,
"tx": false,
"batchCommit": 1000,
"wal" : false,
"dbType": "graph"
}
}
}