This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new bfa875c00 [tablet] reduce lock contention in OpTracker::Release()
bfa875c00 is described below

commit bfa875c00d657b8d5c37ed2032cf82c6c5704f37
Author: Alexey Serbin <ale...@apache.org>
AuthorDate: Wed Sep 25 21:25:41 2024 -0700

    [tablet] reduce lock contention in OpTracker::Release()
    
    Since MemTracker::Release() runs tcmalloc's GC-ing which might
    block for some time under heavy concurrent activity, it makes sense
    to call it outside of the critical section that guards the map
    with pending operations for the tablet.  Also, avoid double lookups
    in that map, re-using the iterator for erasing the element.
    
    Change-Id: Ic5e4298ccabe2f70500765d63083cc817b7a5f95
    Reviewed-on: http://gerrit.cloudera.org:8080/21856
    Reviewed-by: Abhishek Chennaka <achenn...@cloudera.com>
    Tested-by: Alexey Serbin <ale...@apache.org>
---
 src/kudu/tablet/ops/op_tracker.cc | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/kudu/tablet/ops/op_tracker.cc 
b/src/kudu/tablet/ops/op_tracker.cc
index 894bee72b..058d16429 100644
--- a/src/kudu/tablet/ops/op_tracker.cc
+++ b/src/kudu/tablet/ops/op_tracker.cc
@@ -23,6 +23,7 @@
 #include <ostream>
 #include <string>
 #include <type_traits>
+#include <utility>
 #include <vector>
 
 #include <gflags/gflags.h>
@@ -226,14 +227,19 @@ void OpTracker::Release(OpDriver* driver) {
   DecrementCounters(*driver);
 
   // Remove the op from the map updating memory consumption if needed.
-  std::lock_guard l(lock_);
-  if (mem_tracker_) {
-    const State& st = FindOrDie(pending_ops_, driver);
-    mem_tracker_->Release(st.memory_footprint);
+  int64_t memory_footprint = 0;
+  {
+    std::lock_guard l(lock_);
+    const auto it = pending_ops_.find(driver);
+    if (PREDICT_FALSE(it == pending_ops_.end())) {
+      LOG(FATAL) << Substitute("$0: pending op not found",
+                               driver->ToStringUnlocked());
+    }
+    memory_footprint = it->second.memory_footprint;
+    pending_ops_.erase(it);
   }
-  if (PREDICT_FALSE(pending_ops_.erase(driver) != 1)) {
-    LOG(FATAL) << Substitute("Could not remove pending op from map: $0",
-                             driver->ToStringUnlocked());
+  if (mem_tracker_) {
+    mem_tracker_->Release(memory_footprint);
   }
 }
 

Reply via email to