You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2018/02/23 00:19:09 UTC

kudu git commit: KUDU-2238. DMS not flush under memory pressure.

Repository: kudu
Updated Branches:
  refs/heads/branch-1.5.x 611627f2c -> 4b3a5a5f4


KUDU-2238. DMS not flush under memory pressure.

When we choose DMS to flush, now we always pick the DMS with
highest log retention. However, as KUDU-2238 shows, in some cases
DMS with highest log retention may only consume little memory, and
other DMSs may consume much more memory, but get no chance to be
flushed, even under memory pressure.

This patch gives the ability to take memory consumption into
consideration when we choose DMS.

Change-Id: I0c04d76aa0e3888352dc56eeb493a5437ef47e42
Reviewed-on: http://gerrit.cloudera.org:8080/8904
Reviewed-by: Todd Lipcon <to...@apache.org>
Tested-by: Kudu Jenkins
Reviewed-on: http://gerrit.cloudera.org:8080/9322
Tested-by: Will Berkeley <wd...@gmail.com>
Reviewed-by: Will Berkeley <wd...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/4b3a5a5f
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/4b3a5a5f
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/4b3a5a5f

Branch: refs/heads/branch-1.5.x
Commit: 4b3a5a5f4474618ec55c18437090ec41f7764656
Parents: 611627f
Author: zhangzhen [张震] <zh...@xiaomi.com>
Authored: Thu Dec 21 16:32:19 2017 +0800
Committer: Will Berkeley <wd...@gmail.com>
Committed: Thu Feb 22 21:23:10 2018 +0000

----------------------------------------------------------------------
 src/kudu/tablet/tablet.cc                | 21 ++++++++++++++++-----
 src/kudu/tablet/tablet.h                 |  2 +-
 src/kudu/tablet/tablet_replica_mm_ops.cc |  2 +-
 3 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/4b3a5a5f/src/kudu/tablet/tablet.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet.cc b/src/kudu/tablet/tablet.cc
index 90c4835..33a969d 100644
--- a/src/kudu/tablet/tablet.cc
+++ b/src/kudu/tablet/tablet.cc
@@ -87,6 +87,7 @@
 #include "kudu/util/make_shared.h"
 #include "kudu/util/metrics.h"
 #include "kudu/util/monotime.h"
+#include "kudu/util/process_memory.h"
 #include "kudu/util/slice.h"
 #include "kudu/util/status_callback.h"
 #include "kudu/util/stopwatch.h"  // IWYU pragma: keep
@@ -1752,7 +1753,7 @@ void Tablet::GetInfoForBestDMSToFlush(const ReplaySizeMap& replay_size_map,
   }
 }
 
-Status Tablet::FlushDMSWithHighestRetention(const ReplaySizeMap& replay_size_map) const {
+Status Tablet::FlushBestDMS(const ReplaySizeMap &replay_size_map) const {
   shared_ptr<RowSet> rowset = FindBestDMSToFlush(replay_size_map);
   if (rowset) {
     return rowset->FlushDeltas();
@@ -1765,6 +1766,13 @@ shared_ptr<RowSet> Tablet::FindBestDMSToFlush(const ReplaySizeMap& replay_size_m
   GetComponents(&comps);
   int64_t mem_size = 0;
   int64_t retention_size = 0;
+  double max_score = 0;
+  double mem_weight = 0;
+  // If system is under memory pressure, we use the percentage of the hard limit consumed
+  // as mem_weight, so the tighter memory, the higher weight. Otherwise just left the
+  // mem_weight to 0.
+  process_memory::UnderMemoryPressure(&mem_weight);
+
   shared_ptr<RowSet> best_dms;
   for (const shared_ptr<RowSet> &rowset : comps->rowsets->all_rowsets()) {
     if (rowset->DeltaMemStoreEmpty()) {
@@ -1772,11 +1780,14 @@ shared_ptr<RowSet> Tablet::FindBestDMSToFlush(const ReplaySizeMap& replay_size_m
     }
     int64_t size = GetReplaySizeForIndex(rowset->MinUnflushedLogIndex(),
                                          replay_size_map);
-    if ((size > retention_size) ||
-        (size == retention_size &&
-         (rowset->DeltaMemStoreSize() > mem_size))) {
-      mem_size = rowset->DeltaMemStoreSize();
+    int64_t mem = rowset->DeltaMemStoreSize();
+    double score = mem * mem_weight + size * (100 - mem_weight);
+
+    if ((score > max_score) ||
+        (score > max_score - 1 && mem > mem_size)) {
+      max_score = score;
       retention_size = size;
+      mem_size = mem;
       best_dms = rowset;
     }
   }

http://git-wip-us.apache.org/repos/asf/kudu/blob/4b3a5a5f/src/kudu/tablet/tablet.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet.h b/src/kudu/tablet/tablet.h
index daf7227..ca8fb1a 100644
--- a/src/kudu/tablet/tablet.h
+++ b/src/kudu/tablet/tablet.h
@@ -256,7 +256,7 @@ class Tablet {
                                 int64_t* mem_size, int64_t* replay_size) const;
 
   // Flushes the DMS with the highest retention.
-  Status FlushDMSWithHighestRetention(const ReplaySizeMap& replay_size_map) const;
+  Status FlushBestDMS(const ReplaySizeMap &replay_size_map) const;
 
   // Flush only the biggest DMS
   Status FlushBiggestDMS();

http://git-wip-us.apache.org/repos/asf/kudu/blob/4b3a5a5f/src/kudu/tablet/tablet_replica_mm_ops.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_replica_mm_ops.cc b/src/kudu/tablet/tablet_replica_mm_ops.cc
index 6d0fc38..d86d353 100644
--- a/src/kudu/tablet/tablet_replica_mm_ops.cc
+++ b/src/kudu/tablet/tablet_replica_mm_ops.cc
@@ -184,7 +184,7 @@ void FlushDeltaMemStoresOp::Perform() {
                  << tablet_replica_->tablet_id();
     return;
   }
-  KUDU_CHECK_OK_PREPEND(tablet_replica_->tablet()->FlushDMSWithHighestRetention(
+  KUDU_CHECK_OK_PREPEND(tablet_replica_->tablet()->FlushBestDMS(
                             max_idx_to_replay_size),
                             Substitute("Failed to flush DMS on $0",
                                        tablet_replica_->tablet()->tablet_id()));