Skip to content

Commit

Permalink
feat(load_speed): use journal_mode=MEMORY for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink committed Apr 24, 2020
1 parent adedc3c commit b7d9306
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
11 changes: 5 additions & 6 deletions cmd/load.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

var split = require('split2'),
through = require('through2'),
parser = require('../lib/jsonParseStream'),
Placeholder = require('../Placeholder'),
ph = new Placeholder();
const split = require('split2');
const through = require('through2');
const parser = require('../lib/jsonParseStream');
const Placeholder = require('../Placeholder');
const ph = new Placeholder();

// run import pipeline
console.error('import...');
Expand Down
2 changes: 1 addition & 1 deletion lib/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Database.prototype.configure = function(){
this.db.pragma('page_size=4096'); // (default: 1024)
this.db.pragma('cache_size=-2000'); // (default: -2000, 2GB)
this.db.pragma('synchronous=OFF');
this.db.pragma('journal_mode=OFF');
this.db.pragma('journal_mode=MEMORY');
this.db.pragma('temp_store=MEMORY');
};

Expand Down
1 change: 1 addition & 0 deletions lib/DocStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ util.inherits( DocStore, Database );

DocStore.prototype.reset = function(){
this.db.exec('DROP TABLE IF EXISTS docs');
this.db.exec('DROP TABLE IF EXISTS rtree');
this.db.exec('CREATE TABLE docs( id INTEGER PRIMARY KEY, json TEXT )');

// create rtree table
Expand Down
38 changes: 19 additions & 19 deletions test/lib/Database.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var Database = require('../../lib/Database');
const _ = require('lodash');
const Database = require('../../lib/Database');

module.exports.constructor = function(test, common) {
test('constructor', function(t) {
Expand Down Expand Up @@ -87,20 +87,20 @@ module.exports.prepare = function(test, common) {
test('prepare', function(t) {
var db = new Database();
db.open('/tmp/db', { test: true });

t.equal(typeof db.stmt, 'undefined');

const sql = 'SELECT * FROM sqlite_master';
db.prepare(sql);

t.true(typeof db.stmt, 'object');
t.true(db.stmt.hasOwnProperty(sql));
t.deepEqual(db.stmt[sql], {
reader: true,
source: 'SELECT * FROM sqlite_master',
database: db.db
});

t.end();
});
};
Expand All @@ -111,19 +111,19 @@ module.exports.configure = function(test, common) {
db.open('/tmp/db', { test: true });

// configure
const pragma_checks = [
{ foreign_keys: 0 },
{ page_size: 4096 },
{ cache_size: -2000 },
{ synchronous: 0 },
// { journal_mode: 0 },
{ temp_store: 2 }
];

t.plan( pragma_checks.length );
pragma_checks.forEach( pragma => {
var sql = 'PRAGMA ' + Object.keys(pragma)[0] + ';';
t.deepEqual( db.db.prepare(sql).get(), pragma );
const pragma_checks = {
foreign_keys: 0,
page_size: 4096,
cache_size: -2000,
synchronous: 0,
// journal_mode: 'memory',
temp_store: 2
};

t.plan(_.size(pragma_checks));
_.forEach(pragma_checks, (value, key) => {
const stmt = db.db.prepare(`PRAGMA ${key};`);
t.deepEqual(stmt.get(), { [key]: value });
});
});
};

0 comments on commit b7d9306

Please sign in to comment.