Return-Path: X-Original-To: apmail-kudu-commits-archive@minotaur.apache.org Delivered-To: apmail-kudu-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3594F19B39 for ; Tue, 26 Apr 2016 20:38:08 +0000 (UTC) Received: (qmail 82122 invoked by uid 500); 26 Apr 2016 20:38:08 -0000 Delivered-To: apmail-kudu-commits-archive@kudu.apache.org Received: (qmail 82104 invoked by uid 500); 26 Apr 2016 20:38:08 -0000 Mailing-List: contact commits-help@kudu.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@kudu.incubator.apache.org Delivered-To: mailing list commits@kudu.incubator.apache.org Received: (qmail 82095 invoked by uid 99); 26 Apr 2016 20:38:08 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Apr 2016 20:38:08 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 715561A0883 for ; Tue, 26 Apr 2016 20:38:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.221 X-Spam-Level: X-Spam-Status: No, score=-3.221 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id VsUqfeRuobSJ for ; Tue, 26 Apr 2016 20:38:05 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id 010165F3A0 for ; Tue, 26 Apr 2016 20:38:04 +0000 (UTC) Received: (qmail 81939 invoked by uid 99); 26 Apr 2016 20:38:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Apr 2016 20:38:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 00E47DFC6F; Tue, 26 Apr 2016 20:38:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: todd@apache.org To: commits@kudu.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-kudu git commit: lock_manager: add better tracing for slow lock acquisition Date: Tue, 26 Apr 2016 20:38:04 +0000 (UTC) Repository: incubator-kudu Updated Branches: refs/heads/master 4ed147b7a -> 342b7a704 lock_manager: add better tracing for slow lock acquisition This can help diagnose performance issues due to row lock contention. I was just helping a user who was accidentally inserting a lot of duplicate primary keys, which resulted in high contention on those row locks. This was somewhat evident from the 'prepare_run_time_us' histogram metric, but would have been more obvious with some request counters showing the amount of time spent blocked on locks. No new test since this is just trace instrumentation. Change-Id: I133f496bfe8e85128471fc151001a7dab5da4eff Reviewed-on: http://gerrit.cloudera.org:8080/2868 Reviewed-by: David Ribeiro Alves Tested-by: Kudu Jenkins Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/342b7a70 Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/342b7a70 Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/342b7a70 Branch: refs/heads/master Commit: 342b7a704a89d2f6d5a2dfbf107497cfacb0b9af Parents: 4ed147b Author: Todd Lipcon Authored: Mon Apr 25 22:28:33 2016 -0700 Committer: Todd Lipcon Committed: Tue Apr 26 20:37:45 2016 +0000 ---------------------------------------------------------------------- src/kudu/tablet/lock_manager.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/342b7a70/src/kudu/tablet/lock_manager.cc ---------------------------------------------------------------------- diff --git a/src/kudu/tablet/lock_manager.cc b/src/kudu/tablet/lock_manager.cc index f38a1dd..b0d657e 100644 --- a/src/kudu/tablet/lock_manager.cc +++ b/src/kudu/tablet/lock_manager.cc @@ -24,9 +24,11 @@ #include "kudu/gutil/dynamic_annotations.h" #include "kudu/gutil/gscoped_ptr.h" #include "kudu/gutil/hash/city.h" +#include "kudu/gutil/walltime.h" #include "kudu/tablet/lock_manager.h" #include "kudu/util/locks.h" #include "kudu/util/semaphore.h" +#include "kudu/util/trace.h" namespace kudu { namespace tablet { @@ -348,18 +350,23 @@ LockManager::LockStatus LockManager::Lock(const Slice& key, // If we couldn't immediately acquire the lock, do a timed lock so we can // warn if it takes a long time. // TODO: would be nice to hook in some histogram metric about lock acquisition - // time. + // time. For now we just associate with per-request metrics. + TRACE_COUNTER_INCREMENT("row_lock_wait_count", 1); + MicrosecondsInt64 start_wait_us = GetMonoTimeMicros(); int waited_seconds = 0; while (!(*entry)->sem.TimedAcquire(MonoDelta::FromSeconds(1))) { const TransactionState* cur_holder = ANNOTATE_UNPROTECTED_READ((*entry)->holder_); LOG(WARNING) << "Waited " << (++waited_seconds) << " seconds to obtain row lock on key " << key.ToDebugString() << " cur holder: " << cur_holder; - // TODO: add RPC trace annotation here. Above warning should also include an RPC - // trace ID. // TODO: would be nice to also include some info about the blocking transaction, // but it's a bit tricky to do in a non-racy fashion (the other transaction may // complete at any point) } + MicrosecondsInt64 wait_us = GetMonoTimeMicros() - start_wait_us; + TRACE_COUNTER_INCREMENT("row_lock_wait_us", wait_us); + if (wait_us > 100 * 1000) { + TRACE("Waited $0us for lock on $1", wait_us, key.ToDebugString()); + } } (*entry)->holder_ = tx;