[gom] gom: Enhance performance for our use cases
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gom] gom: Enhance performance for our use cases
- Date: Thu, 17 Apr 2014 17:49:37 +0000 (UTC)
commit 46fc743a1cf2da9a811c052b45e249bf22e04fa3
Author: Bastien Nocera <hadess hadess net>
Date: Thu Apr 17 19:27:56 2014 +0200
gom: Enhance performance for our use cases
First, we'll use the SQLITE_OPEN_NOMUTEX open flag, which will
mean that we are expected to implement our own locking access to
the database, which we don't need to do as a single worked thread
will access the database.
Secondly, we'll execute a few PRAGMA statements. The journal_mode
will change the behaviour of the rollback model. We now use a
write-ahead log instead of a journal. This is much faster with small
transactions (ours are very small).
https://www.sqlite.org/pragma.html#pragma_journal_mode
With this change, adding 1000 items into a disk-backed database
drops from 20 seconds to 7 seconds.
Finally, we also change the synchronous behaviour to NORMAL.
This is a good trade-off between performance, and possibility of
database corruption.
https://www.sqlite.org/pragma.html#pragma_synchronous
With the same test case as above, we drop from taking 7 seconds
to 0.2 seconds to add 1000 items.
gom/gom-adapter.c | 2 +-
gom/gom-repository.c | 3 +++
2 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/gom/gom-adapter.c b/gom/gom-adapter.c
index c0d8b3e..9bc223c 100644
--- a/gom/gom-adapter.c
+++ b/gom/gom-adapter.c
@@ -189,7 +189,7 @@ open_callback (GomAdapter *adapter,
queue = g_object_get_data(G_OBJECT(simple), "queue");
uri = g_object_get_data(G_OBJECT(simple), "uri");
- flags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_URI;
+ flags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_URI | SQLITE_OPEN_NOMUTEX;
ret = sqlite3_open_v2(uri, &adapter->priv->db, flags, NULL);
if (ret != SQLITE_OK) {
g_simple_async_result_set_error(simple, GOM_ADAPTER_ERROR,
diff --git a/gom/gom-repository.c b/gom/gom-repository.c
index cc81318..13e7e86 100644
--- a/gom/gom-repository.c
+++ b/gom/gom-repository.c
@@ -174,6 +174,9 @@ gom_repository_migrate_cb (GomAdapter *adapter,
goto out;
}
+ EXECUTE_OR_GOTO(adapter, "PRAGMA synchronous = NORMAL;", &error, rollback);
+ EXECUTE_OR_GOTO(adapter, "PRAGMA journal_mode = WAL;", &error, rollback);
+
EXECUTE_OR_GOTO(adapter, "BEGIN;", &error, rollback);
for (i = MAX(current, 1); i <= version; i++) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]