我正在尝试使用Node向Cassandra插入行。以前我用Mongo代替了Cassandra,我可以在单个节点mongo上合理地获得每秒1500次的插入。使用Cassandra和node-cassandra-cql,我只能获得每秒175-250次的插入。这是性能的巨大下降。这是一个没有索引的表。
cql = require("node-cassandra-cql")
...
if (this.dbConnection == null) {
this.dbConnection = new cql.Client({
hosts: this.hosts,
keyspace: this.keyspace
});
}
...
var colAndValues, statement, v;
colAndValues = "(" + (this.fieldsWithValue.join(',')) + ") values (" + (((function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = values.length; _i < _len; _i++) {
v = values[_i];
_results.push('?');
}
return _results;
})()).join(', ')) + ")";
statement = "INSERT INTO " + this.table + " " + colAndValues + ";";
this.dbConnection.execute(statement, values, cql.types.consistencies.one, function(err) {
if (err) {
return emitter.emit('error', err + (" \nstatement: " + statement + "\nvalues: " + (JSON.stringify(values))));
} else {
return emitter.emit('complete', true);
}
});
好的,这可能有点晦涩,但是语句和值看起来像:
statement:
INSERT INTO data (order_id,order_ts,transaction_id,transaction_discount,transaction_qty,transaction_total,product_category,product_profit,product_upc,product_name,product_price,product_distributor,store_id,store_name,store_state,store_region,id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
values
[{"value":"70DQLVZLSN","hint":10},"2014-06-08T20:30:23.000Z",{"value":"1OOSC3PL9Q","hint":10},{"value":0,"hint":8},{"value":3,"hint":9},{"value":37.77,"hint":8},{"value":"Movies","hint":10},{"value":3.4,"hint":8},{"value":"PD1334R9688","hint":10},{"value":"The Hunt","hint":10},{"value":12.59,"hint":8},{"value":"IN5","hint":10},{"value":"6LMTY1OWR3","hint":10},{"value":"Sporket Spokane","hint":10},{"value":"WA","hint":10},{"value":"Northwest","hint":10},{"value":"819ddd7f-28e7-4247-90cf-03132ef8b66e","hint":12}]
这些只是插入到虚拟数据库中的测试值。它可以正常工作,但性能很差。我以为添加提示会有所帮助,但并没有。我还尝试了
executeAsPrepared
,但没有变化。文档说,在执行之前连接不是必需的(驱动程序会存储任何已建立的连接)。因此,我已经无法想出如何加速这个过程了。我想对其进行分析,但在Ubuntu上运行V8分析器一直是一个时间成本高昂的问题(而且没有成功)。