From efced9bb87837c060455607b3f733ad77a8ac2a8 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Sun, 25 Jan 2015 14:47:07 +0100 Subject: [PATCH] improved write performance of SQLite db --- scv_tr_sqlite/src/scv_tr_sqlite.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scv_tr_sqlite/src/scv_tr_sqlite.cpp b/scv_tr_sqlite/src/scv_tr_sqlite.cpp index 6fea0f1..127caed 100644 --- a/scv_tr_sqlite/src/scv_tr_sqlite.cpp +++ b/scv_tr_sqlite/src/scv_tr_sqlite.cpp @@ -103,7 +103,12 @@ static void dbCb(const scv_tr_db& _scv_tr_db, scv_tr_db::callback_reason reason, fName+=".txdb"; remove(fName.c_str()); db.open(fName.c_str()); -// scv_out << "TB Transaction Recording has started, file = " << my_sqlite_file_name << endl; + // performance related according to http://blog.quibb.org/2010/08/fast-bulk-inserts-into-sqlite/ + db.exec("PRAGMA synchronous=OFF"); + db.exec("PRAGMA count_changes=OFF"); + db.exec("PRAGMA journal_mode=MEMORY"); + db.exec("PRAGMA temp_store=MEMORY"); + // scv_out << "TB Transaction Recording has started, file = " << my_sqlite_file_name << endl; db.exec("CREATE TABLE IF NOT EXISTS " STREAM_TABLE "(id INTEGER NOT NULL PRIMARY KEY, name TEXT, kind TEXT);"); db.exec("CREATE TABLE IF NOT EXISTS " GENERATOR_TABLE "(id INTEGER NOT NULL PRIMARY KEY, stream INTEGER REFERENCES " STREAM_TABLE "(id), name TEXT, begin_attr INTEGER, end_attr INTEGER);"); db.exec("CREATE TABLE IF NOT EXISTS " TX_TABLE "(id INTEGER NOT NULL PRIMARY KEY, generator INTEGER REFERENCES " GENERATOR_TABLE "(id), stream INTEGER REFERENCES " STREAM_TABLE "(id), concurrencyLevel INTEGER);"); @@ -111,6 +116,7 @@ static void dbCb(const scv_tr_db& _scv_tr_db, scv_tr_db::callback_reason reason, db.exec("CREATE TABLE IF NOT EXISTS " TX_ATTRIBUTE_TABLE "(tx INTEGER REFERENCES " TX_TABLE "(id), type INTEGER, name TEXT, data_type INTEGER, data_value TEXT);"); db.exec("CREATE TABLE IF NOT EXISTS " TX_RELATION_TABLE "(name TEXT, src INTEGER REFERENCES " TX_TABLE "(id), sink INTEGER REFERENCES " TX_TABLE "(id));"); db.exec("CREATE TABLE IF NOT EXISTS " SIM_PROPS "(time_resolution INTEGER);"); + db.exec("BEGIN TRANSACTION"); queryBuilder.str(""); queryBuilder << "INSERT INTO " SIM_PROPS " (time_resolution) values (" << (long)(sc_get_time_resolution().to_seconds()*1e15) << ");"; @@ -121,7 +127,8 @@ static void dbCb(const scv_tr_db& _scv_tr_db, scv_tr_db::callback_reason reason, break; case scv_tr_db::DELETE: try { -// scv_out << "Transaction Recording is closing file: " << my_sqlite_file_name << endl; + // scv_out << "Transaction Recording is closing file: " << my_sqlite_file_name << endl; + db.exec("COMMIT TRANSACTION"); db.close(); } catch (SQLiteDB::SQLiteException& e) { _scv_message::message(_scv_message::TRANSACTION_RECORDING_INTERNAL, "Can't close recording file"); @@ -365,4 +372,3 @@ void scv_tr_sqlite_init() { scv_tr_handle::register_relation_cb(relationCb); } // ---------------------------------------------------------------------------- -