Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 7093 invoked from network); 6 Nov 2009 17:51:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 6 Nov 2009 17:51:56 -0000 Received: (qmail 84125 invoked by uid 500); 6 Nov 2009 17:51:56 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 84103 invoked by uid 500); 6 Nov 2009 17:51:56 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 84095 invoked by uid 99); 6 Nov 2009 17:51:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Nov 2009 17:51:56 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Nov 2009 17:51:53 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 69880234C045 for ; Fri, 6 Nov 2009 09:51:32 -0800 (PST) Message-ID: <1082161537.1257529892427.JavaMail.jira@brutus> Date: Fri, 6 Nov 2009 17:51:32 +0000 (UTC) From: "Rick Hillegas (JIRA)" To: derby-dev@db.apache.org Subject: [jira] Commented: (DERBY-4437) Concurrent inserts into table with identity column perform poorly In-Reply-To: <1695886845.1257504932402.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/DERBY-4437?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12774331#action_12774331 ] Rick Hillegas commented on DERBY-4437: -------------------------------------- Hopefully, the solution will be something that we can re-use for sequence generators (DERBY-712). As I read the SQL Standard, a sequence should "normally" not have any gaps but no guarantees are made and it is hard to understand how holes won't turn up since the sequence is not affected by rollbacks and the sequence is supposed to change monotonically in one direction or another. Pre-allocating a block of sequence numbers (Mike's solution #1) is attractive, particularly if we can release the unused ids when the database is brought down in an orderly fashion. I like the idea that the size of that block is self-tuning. > Concurrent inserts into table with identity column perform poorly > ----------------------------------------------------------------- > > Key: DERBY-4437 > URL: https://issues.apache.org/jira/browse/DERBY-4437 > Project: Derby > Issue Type: Improvement > Components: SQL > Affects Versions: 10.5.3.0 > Reporter: Knut Anders Hatlen > > I have a multi-threaded application which is very insert-intensive. I've noticed that it sometimes can come into a state where it slows down considerably and basically becomes single-threaded. This is especially harmful on modern multi-core machines since most of the available resources are left idle. > The problematic tables contain identity columns, and here's my understanding of what happens: > 1) Identity columns are generated from a counter that's stored in a row in SYS.SYSCOLUMNS. During normal operation, the counter is maintained in a nested transaction within the transaction that performs the insert. This allows the nested transaction to commit the changes to SYS.SYSCOLUMN separately from the main transaction, and the exclusive lock that it needs to obtain on the row holding the counter, can be releases after a relatively short time. Concurrent transactions can therefore insert into the same table at the same time, without needing to wait for the others to commit or abort. > 2) However, if the nested transaction cannot lock the row in SYS.SYSCOLUMNS immediately, it will give up and retry the operation in the main transaction. This prevents self-deadlocks in the case where the main transaction already owns a lock on SYS.SYSCOLUMNS. Unfortunately, this also increases the time the row is locked, since the exclusive lock cannot be released until the main transaction commits. So as soon as there is one lock collision, the waiting transaction changes to a locking mode that increases the chances of others having to wait, which seems to result in all insert threads having to obtain the SYSCOLUMNS locks in the main transaction. The end result is that only one of the insert threads can execute at any given time as long as the application is in this state. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.