Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 68338 invoked from network); 17 Apr 2006 06:11:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Apr 2006 06:11:45 -0000 Received: (qmail 32541 invoked by uid 500); 17 Apr 2006 06:11:44 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 32492 invoked by uid 500); 17 Apr 2006 06:11:44 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 32481 invoked by uid 99); 17 Apr 2006 06:11:44 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 16 Apr 2006 23:11:44 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of bojan@rexursive.com designates 203.171.74.242 as permitted sender) Received: from [203.171.74.242] (HELO beauty.rexursive.com) (203.171.74.242) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 16 Apr 2006 23:11:41 -0700 Received: from coyote.rexursive.com (coyote.rexursive.com [172.27.0.22]) by beauty.rexursive.com (Postfix) with ESMTP id 67F141AF281 for ; Mon, 17 Apr 2006 16:11:19 +1000 (EST) Subject: [PATCH]: Make SQLite3 wait on BUSY inside dbd_sqlite3_query() From: Bojan Smojver To: APR Development List Content-Type: multipart/mixed; boundary="=-Mc5hmZg9Giw5cItMHiv3" Date: Mon, 17 Apr 2006 16:11:18 +1000 Message-Id: <1145254278.16371.37.camel@coyote.rexursive.com> Mime-Version: 1.0 X-Mailer: Evolution 2.6.0 (2.6.0-1) X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --=-Mc5hmZg9Giw5cItMHiv3 Content-Type: text/plain Content-Transfer-Encoding: 7bit I tested this patch with 1.2.x, but I'd like people to check if all is cool before it gets committed to any branch/trunk. Essentially, we're not assuming any more that the sqlite3_step() call is always going to be successful - this call can return SQLITE_BUSY just the same as the one inside the dbd_sqlite3_select() function. The gain from this patch was rather obvious in my testing, where I hammered Apache at concurrency level 10 with requests (using ab) and with APU DBD doing UPDATE to a single SQLite3 database. With this patch, I had 0 failed queries out of 1000 requests. Without it, I'd get anywhere between 750 and 1000 (!) failed queries out of 1000 requests in this high contention scenario. -- Bojan --=-Mc5hmZg9Giw5cItMHiv3 Content-Disposition: attachment; filename=apr-util-SQLite3-query-busy.patch Content-Type: text/x-patch; name=apr-util-SQLite3-query-busy.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit Index: apr_dbd_sqlite3.c =================================================================== --- apr_dbd_sqlite3.c (revision 394609) +++ apr_dbd_sqlite3.c (working copy) @@ -253,12 +253,29 @@ apr_dbd_mutex_lock(); do { + int retry_count = 0; + ret = sqlite3_prepare(sql->conn, query, length, &stmt, &tail); if (ret != SQLITE_OK) { sqlite3_finalize(stmt); break; } - ret = sqlite3_step(stmt); + + while(retry_count++ <= MAX_RETRY_COUNT) { + ret = sqlite3_step(stmt); + if (dbd_sqlite3_is_success(ret)) + break; + + if (ret == SQLITE_BUSY){ + apr_thread_mutex_unlock(sql->mutex); + apr_sleep(MAX_RETRY_SLEEP); + apr_thread_mutex_lock(sql->mutex); + continue; + } else { + break; + } + } + *nrows = sqlite3_changes(sql->conn); sqlite3_finalize(stmt); length -= (tail - query); --=-Mc5hmZg9Giw5cItMHiv3--