From 627b331b32c44ce5e8847d8a9abd049d266da29f Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Fri, 17 Sep 2010 11:20:20 -0700 Subject: [PATCH] add new param to device config properties: db connection pool size connection pool = number of database connections opened when the app opens a database. These pooled connections are used by readers only and they use the sqlite write-ahead-logging option to increase reader concurrency. The size of this connection pool depends on the number of CPUs, RAM etc. On most single-core devices, this can be set to 1. But on some multi-core devices with more RAM, pool size can be more than 1. On a device with more resources, here are the results of a test (in coretests/src/android/database/sqlite/SQLiteDatabaseTest.java) which measures the reader-parallelism achieved for different connection pool sizes. connpool-size = 1 num xacts by writer = 467 num-reads-in-xact/NOT-in-xact by reader1 = 1358/14542, by reader2 = 1431/14269 connpool-size = 2 num xacts by writer = 473 num-reads-in-xact/NOT-in-xact by reader1 = 5703/35227, by reader2 = 6222/35898 connpool-size = 3 num xacts by writer = 542 num-reads-in-xact/NOT-in-xact by reader1 = 6531/32329, by reader2 = 6252/32728 connpool-size = 4 num xacts by writer = 578 num-reads-in-xact/NOT-in-xact by reader1 = 6009/32701, by reader2 = 5977/32953 connpool-size = 5 num xacts by writer = 547 num-reads-in-xact/NOT-in-xact by reader1 = 6554/31186, by reader2 = 5318/31022 connpool-size = 6 num xacts by writer = 534 num-reads-in-xact/NOT-in-xact by reader1 = 5317/31463, by reader2 = 5413/31537 connpool-size = 7 num xacts by writer = 549 num-reads-in-xact/NOT-in-xact by reader1 = 5396/28004, by reader2 = 5214/28496 seems like connection pool size of 3 is optimal on this device. Change-Id: I348ff5a31783c31b5e3e5ac78b7c2cea54ef114a --- .../database/sqlite/DatabaseConnectionPool.java | 11 ++++------- core/res/res/values/config.xml | 4 ++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/java/android/database/sqlite/DatabaseConnectionPool.java b/core/java/android/database/sqlite/DatabaseConnectionPool.java index 54b06054f86c4..4f5c4e63770b6 100644 --- a/core/java/android/database/sqlite/DatabaseConnectionPool.java +++ b/core/java/android/database/sqlite/DatabaseConnectionPool.java @@ -16,6 +16,7 @@ package android.database.sqlite; +import android.content.res.Resources; import android.os.SystemClock; import android.util.Log; @@ -31,13 +32,9 @@ import java.util.Random; private static final String TAG = "DatabaseConnectionPool"; - /** The default connection pool size. It is set based on the amount of memory the device has. - * TODO: set this with 'a system call' which returns the amount of memory the device has - */ - private static final int DEFAULT_CONNECTION_POOL_SIZE = 1; - - /** the pool size set for this {@link SQLiteDatabase} */ - private volatile int mMaxPoolSize = DEFAULT_CONNECTION_POOL_SIZE; + /** The default connection pool size. */ + private volatile int mMaxPoolSize = + Resources.getSystem().getInteger(com.android.internal.R.integer.db_connection_pool_size); /** The connection pool objects are stored in this member. * TODO: revisit this data struct as the number of pooled connections increase beyond diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index ff37d05d5b9f0..b4e1fcbbd0cc3 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -416,4 +416,8 @@ false + + + 1