Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZcDqL-0007yb-6d for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Sep 2015 14:37:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZcDqK-0005Nc-KU for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Sep 2015 14:37:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZcDqK-0005NW-2M for pgsql-hackers@postgresql.org; Wed, 16 Sep 2015 14:37:52 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZcDqG-0006Sh-5t for pgsql-hackers@postgresql.org; Wed, 16 Sep 2015 14:37:50 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 0C782C062C96 for ; Wed, 16 Sep 2015 14:37:45 +0000 (UTC) Received: from localhost.localdomain (vpn-53-52.rdu2.redhat.com [10.10.53.52]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8GEbi5H025448 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 16 Sep 2015 10:37:44 -0400 Subject: Re: Additional LWLOCK_STATS statistics To: "pgsql-hackers@postgresql.org" References: <55F82AE1.3010407@redhat.com> <55F871BA.4060404@redhat.com> <55F876CA.8020702@redhat.com> <55F97909.3010101@redhat.com> <55F97BF0.70503@redhat.com> From: Jesper Pedersen Organization: JBoss, by Red Hat Message-ID: <55F97EB7.8080308@redhat.com> Date: Wed, 16 Sep 2015 10:37:43 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <55F97BF0.70503@redhat.com> Content-Type: multipart/mixed; boundary="------------000605000402000602070208" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------000605000402000602070208 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 09/16/2015 10:25 AM, Jesper Pedersen wrote: > Likely from LWLOCK_STATS' own lwlock.c::print_lwlock_stats, which would > make sense. > Version 3 attached, which ignores entries from MainLWLockArray[0]. Best regards, Jesper --------------000605000402000602070208 Content-Type: text/x-patch; name="lwstats_v3.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="lwstats_v3.patch" *** /tmp/NTwtmh_lwlock.c 2015-09-16 10:34:02.955957192 -0400 --- src/backend/storage/lmgr/lwlock.c 2015-09-16 10:32:18.088843413 -0400 *************** *** 163,172 **** --- 163,175 ---- { lwlock_stats_key key; int sh_acquire_count; + int sh_acquire_max; int ex_acquire_count; + int ex_acquire_max; int block_count; int dequeue_self_count; int spin_delay_count; + int max_waiters; } lwlock_stats; static HTAB *lwlock_stats_htab; *************** *** 297,308 **** while ((lwstats = (lwlock_stats *) hash_seq_search(&scan)) != NULL) { ! fprintf(stderr, ! "PID %d lwlock %s %d: shacq %u exacq %u blk %u spindelay %u dequeue self %u\n", ! MyProcPid, LWLockTrancheArray[lwstats->key.tranche]->name, ! lwstats->key.instance, lwstats->sh_acquire_count, ! lwstats->ex_acquire_count, lwstats->block_count, ! lwstats->spin_delay_count, lwstats->dequeue_self_count); } LWLockRelease(&MainLWLockArray[0].lock); --- 300,325 ---- while ((lwstats = (lwlock_stats *) hash_seq_search(&scan)) != NULL) { ! if (lwstats->key.tranche == 0 && lwstats->key.instance < NUM_INDIVIDUAL_LWLOCKS) ! { ! /* We ignore information from MainLWLockArray[0] since it isn't in real use */ ! if (lwstats->key.instance != 0) ! fprintf(stderr, ! "PID %d lwlock %s: shacq %u shmax %u exacq %u exmax %u blk %u spindelay %u dequeue self %u maxw %u\n", ! MyProcPid, MainLWLockNames[lwstats->key.instance], ! lwstats->sh_acquire_count, lwstats->sh_acquire_max, ! lwstats->ex_acquire_count, lwstats->ex_acquire_max, ! lwstats->block_count, lwstats->spin_delay_count, lwstats->dequeue_self_count, ! lwstats->max_waiters); ! } ! else ! fprintf(stderr, ! "PID %d lwlock %s %d: shacq %u shmax %u exacq %u exmax %u blk %u spindelay %u dequeue self %u maxw %u\n", ! MyProcPid, LWLockTrancheArray[lwstats->key.tranche]->name, ! lwstats->key.instance, lwstats->sh_acquire_count, lwstats->sh_acquire_max, ! lwstats->ex_acquire_count, lwstats->ex_acquire_max, ! lwstats->block_count, lwstats->spin_delay_count, lwstats->dequeue_self_count, ! lwstats->max_waiters); } LWLockRelease(&MainLWLockArray[0].lock); *************** *** 330,339 **** --- 347,359 ---- if (!found) { lwstats->sh_acquire_count = 0; + lwstats->sh_acquire_max = 0; lwstats->ex_acquire_count = 0; + lwstats->ex_acquire_max = 0; lwstats->block_count = 0; lwstats->dequeue_self_count = 0; lwstats->spin_delay_count = 0; + lwstats->max_waiters = 0; } return lwstats; } *************** *** 774,779 **** --- 794,802 ---- LWLockQueueSelf(LWLock *lock, LWLockMode mode) { #ifdef LWLOCK_STATS + bool include; + int counter, size; + dlist_iter iter; lwlock_stats *lwstats; lwstats = get_lwlock_stats_entry(lock); *************** *** 792,797 **** --- 815,860 ---- #ifdef LWLOCK_STATS lwstats->spin_delay_count += SpinLockAcquire(&lock->mutex); + + /* + * We scan the list of waiters from the back in order to find + * out how many of the same lock type are waiting for a lock. + * Similar types have the potential to be groupped together. + * + * We also count the number of waiters, including ourself. + */ + include = true; + size = 1; + counter = 1; + + dlist_reverse_foreach(iter, &lock->waiters) + { + if (include) + { + PGPROC *waiter = dlist_container(PGPROC, lwWaitLink, iter.cur); + + if (waiter->lwWaitMode == mode) + counter += 1; + else + include = false; + } + + size += 1; + } + + if (mode == LW_EXCLUSIVE || mode == LW_WAIT_UNTIL_FREE) + { + if (counter > lwstats->ex_acquire_max) + lwstats->ex_acquire_max = counter; + } + else if (mode == LW_SHARED) + { + if (counter > lwstats->sh_acquire_max) + lwstats->sh_acquire_max = counter; + } + + if (size > lwstats->max_waiters) + lwstats->max_waiters = size; #else SpinLockAcquire(&lock->mutex); #endif *************** *** 943,951 **** --- 1006,1022 ---- #ifdef LWLOCK_STATS /* Count lock acquisition attempts */ if (mode == LW_EXCLUSIVE) + { lwstats->ex_acquire_count++; + if (lwstats->ex_acquire_max == 0) + lwstats->ex_acquire_max = 1; + } else + { lwstats->sh_acquire_count++; + if (lwstats->sh_acquire_max == 0) + lwstats->sh_acquire_max = 1; + } #endif /* LWLOCK_STATS */ /* --------------000605000402000602070208 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------000605000402000602070208--