kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ale...@apache.org
Subject [1/3] kudu git commit: KUDU-2184. Avoid allocations larger than 1MB
Date Sun, 15 Oct 2017 04:10:30 GMT
Repository: kudu
Updated Branches:
  refs/heads/master b6f727ea2 -> 24308aa1a


KUDU-2184. Avoid allocations larger than 1MB

tcmalloc doesn't perform well for allocations larger than 1MB[1]. We
currently use large allocations for full arenas (in particular the MRS)
which can cause large latency blips when a thread tries to allocate a
new arena component.

This just changes the max buffer size for all arenas to be 1MB and adds
a DCHECK so we avoid this problem in the future.

Additionally I increased the buffer size for the /memz output so that we
can get more stats on the occupancy of different allocator size classes.

[1] https://github.com/gperftools/gperftools/issues/535

Change-Id: I19c8ae9ce268e2623a89624e19db673931a093c0
Reviewed-on: http://gerrit.cloudera.org:8080/8239
Tested-by: Kudu Jenkins
Reviewed-by: David Ribeiro Alves <davidralves@gmail.com>


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

Branch: refs/heads/master
Commit: eb5c7e2f0c73729a4486bc71512739b0788b1574
Parents: b6f727e
Author: Todd Lipcon <todd@apache.org>
Authored: Mon Oct 9 14:22:48 2017 -0700
Committer: Todd Lipcon <todd@apache.org>
Committed: Fri Oct 13 01:58:04 2017 +0000

----------------------------------------------------------------------
 src/kudu/cfile/binary_dict_block.cc          | 2 +-
 src/kudu/cfile/cfile-test-base.h             | 2 +-
 src/kudu/cfile/cfile-test.cc                 | 2 +-
 src/kudu/cfile/cfile_util.cc                 | 2 +-
 src/kudu/server/default-path-handlers.cc     | 7 ++++---
 src/kudu/tablet/concurrent_btree.h           | 5 +----
 src/kudu/tablet/deltamemstore.cc             | 2 +-
 src/kudu/tablet/memrowset.cc                 | 2 +-
 src/kudu/tablet/tablet-test-base.h           | 2 +-
 src/kudu/tablet/tablet_random_access-test.cc | 2 +-
 src/kudu/tablet/transactions/transaction.cc  | 2 +-
 src/kudu/util/memory/arena.cc                | 9 +++++----
 12 files changed, 19 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/cfile/binary_dict_block.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/binary_dict_block.cc b/src/kudu/cfile/binary_dict_block.cc
index 9e96163..f00d75d 100644
--- a/src/kudu/cfile/binary_dict_block.cc
+++ b/src/kudu/cfile/binary_dict_block.cc
@@ -52,7 +52,7 @@ namespace cfile {
 BinaryDictBlockBuilder::BinaryDictBlockBuilder(const WriterOptions* options)
     : options_(options),
       dict_block_(options_),
-      dictionary_strings_arena_(1024, 32*1024*1024),
+      dictionary_strings_arena_(1024, 1024*1024),
       mode_(kCodeWordMode) {
   data_builder_.reset(new BShufBlockBuilder<UINT32>(options_));
   // We use this invalid StringPiece for the "empty key". It's safe to build such

http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/cfile/cfile-test-base.h
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/cfile-test-base.h b/src/kudu/cfile/cfile-test-base.h
index f4f0c8f..64fd35d 100644
--- a/src/kudu/cfile/cfile-test-base.h
+++ b/src/kudu/cfile/cfile-test-base.h
@@ -467,7 +467,7 @@ void TimeReadFile(FsManager* fs_manager, const BlockId& block_id,
size_t *count_
   ASSERT_OK(reader->NewIterator(&iter, CFileReader::CACHE_BLOCK));
   ASSERT_OK(iter->SeekToOrdinal(0));
 
-  Arena arena(8192, 8*1024*1024);
+  Arena arena(8192, 1024 * 1024);
   int count = 0;
   switch (reader->type_info()->physical_type()) {
     case UINT8:

http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/cfile/cfile-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/cfile-test.cc b/src/kudu/cfile/cfile-test.cc
index 364fb93..f7ffe85 100644
--- a/src/kudu/cfile/cfile-test.cc
+++ b/src/kudu/cfile/cfile-test.cc
@@ -200,7 +200,7 @@ class TestCFile : public CFileTestBase {
     gscoped_ptr<CFileIterator> iter;
     ASSERT_OK(reader->NewIterator(&iter, CFileReader::CACHE_BLOCK));
 
-    Arena arena(8192, 8*1024*1024);
+    Arena arena(8192, 1024 * 1024);
     ScopedColumnBlock<DataGeneratorType::kDataType> cb(10);
 
     SelectionVector sel(10);

http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/cfile/cfile_util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/cfile_util.cc b/src/kudu/cfile/cfile_util.cc
index 2995407..31c5af3 100644
--- a/src/kudu/cfile/cfile_util.cc
+++ b/src/kudu/cfile/cfile_util.cc
@@ -46,7 +46,7 @@ Status DumpIterator(const CFileReader& reader,
                     int num_rows,
                     int indent) {
 
-  Arena arena(8192, 8*1024*1024);
+  Arena arena(8192, 1024 * 1024);
   uint8_t buf[kBufSize];
   const TypeInfo *type = reader.type_info();
   size_t max_rows = kBufSize/type->size();

http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/server/default-path-handlers.cc
----------------------------------------------------------------------
diff --git a/src/kudu/server/default-path-handlers.cc b/src/kudu/server/default-path-handlers.cc
index e71922b..8260ec8 100644
--- a/src/kudu/server/default-path-handlers.cc
+++ b/src/kudu/server/default-path-handlers.cc
@@ -152,10 +152,11 @@ static void MemUsageHandler(const Webserver::WebRequest& req,
 #ifndef TCMALLOC_ENABLED
   (*output) << "Memory tracking is not available unless tcmalloc is enabled.";
 #else
-  char buf[2048];
-  MallocExtension::instance()->GetStats(buf, 2048);
+  faststring buf;
+  buf.resize(32 * 1024);
+  MallocExtension::instance()->GetStats(reinterpret_cast<char*>(buf.data()), buf.size());
   // Replace new lines with <br> for html
-  string tmp(buf);
+  string tmp(reinterpret_cast<char*>(buf.data()));
   boost::replace_all(tmp, "\n", tags.line_break);
   (*output) << tmp << tags.end_pre_tag;
 #endif

http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/tablet/concurrent_btree.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/concurrent_btree.h b/src/kudu/tablet/concurrent_btree.h
index 0e4dfa6..a80fa6b 100644
--- a/src/kudu/tablet/concurrent_btree.h
+++ b/src/kudu/tablet/concurrent_btree.h
@@ -952,10 +952,7 @@ class PreparedMutation {
 template<class Traits = BTreeTraits>
 class CBTree {
  public:
-  CBTree()
-    : arena_(new typename Traits::ArenaType(512*1024, 4*1024*1024)),
-      root_(NewLeaf(false)),
-      frozen_(false) {
+  CBTree() : CBTree(std::make_shared<typename Traits::ArenaType>(4 * 1024, 1024 * 1024))
{
   }
 
   explicit CBTree(std::shared_ptr<typename Traits::ArenaType> arena)

http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/tablet/deltamemstore.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/deltamemstore.cc b/src/kudu/tablet/deltamemstore.cc
index d929fa8..8adfee5 100644
--- a/src/kudu/tablet/deltamemstore.cc
+++ b/src/kudu/tablet/deltamemstore.cc
@@ -54,7 +54,7 @@ using strings::Substitute;
 ////////////////////////////////////////////////////////////
 
 static const int kInitialArenaSize = 16;
-static const int kMaxArenaBufferSize = 5*1024*1024;
+static const int kMaxArenaBufferSize = 1024*1024;
 
 Status DeltaMemStore::Create(int64_t id,
                              int64_t rs_id,

http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/tablet/memrowset.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/memrowset.cc b/src/kudu/tablet/memrowset.cc
index 61130e7..1bfa6c7 100644
--- a/src/kudu/tablet/memrowset.cc
+++ b/src/kudu/tablet/memrowset.cc
@@ -62,7 +62,7 @@ using log::LogAnchorRegistry;
 using strings::Substitute;
 
 static const int kInitialArenaSize = 16;
-static const int kMaxArenaBufferSize = 8*1024*1024;
+static const int kMaxArenaBufferSize = 1024*1024;
 
 bool MRSRow::IsGhost() const {
   bool is_ghost = false;

http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/tablet/tablet-test-base.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet-test-base.h b/src/kudu/tablet/tablet-test-base.h
index 92ce1b6..d813aa7 100644
--- a/src/kudu/tablet/tablet-test-base.h
+++ b/src/kudu/tablet/tablet-test-base.h
@@ -310,7 +310,7 @@ class TabletTestBase : public KuduTabletTest {
     KuduTabletTest(TESTSETUP::CreateSchema(), clock_type),
     setup_(),
     max_rows_(setup_.GetMaxRows()),
-    arena_(1024, 4*1024*1024)
+    arena_(1024, 1024 * 1024)
   {}
 
   // Inserts "count" rows.

http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/tablet/tablet_random_access-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet_random_access-test.cc b/src/kudu/tablet/tablet_random_access-test.cc
index e31ae5d..4c25dec 100644
--- a/src/kudu/tablet/tablet_random_access-test.cc
+++ b/src/kudu/tablet/tablet_random_access-test.cc
@@ -279,7 +279,7 @@ class TestRandomAccess : public KuduTabletTest {
     optional<ExpectedKeyValueRow> ret;
     int n_results = 0;
 
-    Arena arena(1024, 4*1024*1024);
+    Arena arena(1024, 1024 * 1024);
     RowBlock block(schema, 100, &arena);
     while (iter->HasNext()) {
       arena.Reset();

http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/tablet/transactions/transaction.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/transaction.cc b/src/kudu/tablet/transactions/transaction.cc
index 543dcd8..7a95914 100644
--- a/src/kudu/tablet/transactions/transaction.cc
+++ b/src/kudu/tablet/transactions/transaction.cc
@@ -34,7 +34,7 @@ TransactionState::TransactionState(TabletReplica* tablet_replica)
     : tablet_replica_(tablet_replica),
       completion_clbk_(new TransactionCompletionCallback()),
       timestamp_error_(0),
-      arena_(1024, 4 * 1024 * 1024),
+      arena_(1024, 1024 * 1024),
       external_consistency_mode_(CLIENT_PROPAGATED) {
 }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/eb5c7e2f/src/kudu/util/memory/arena.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/memory/arena.cc b/src/kudu/util/memory/arena.cc
index 6f65df4..490be0a 100644
--- a/src/kudu/util/memory/arena.cc
+++ b/src/kudu/util/memory/arena.cc
@@ -39,15 +39,16 @@ ArenaBase<THREADSAFE>::ArenaBase(
     : buffer_allocator_(buffer_allocator),
       max_buffer_size_(max_buffer_size),
       arena_footprint_(0) {
+  DCHECK_LE(max_buffer_size_, 1024 * 1024)
+      << "Should not use buffer sizes larger than 1MB due to tcmalloc inefficiencies";
   AddComponent(CHECK_NOTNULL(NewComponent(initial_buffer_size, 0)));
 }
 
 template <bool THREADSAFE>
 ArenaBase<THREADSAFE>::ArenaBase(size_t initial_buffer_size, size_t max_buffer_size)
-    : buffer_allocator_(HeapBufferAllocator::Get()),
-      max_buffer_size_(max_buffer_size),
-      arena_footprint_(0) {
-  AddComponent(CHECK_NOTNULL(NewComponent(initial_buffer_size, 0)));
+    : ArenaBase<THREADSAFE>(HeapBufferAllocator::Get(),
+                            initial_buffer_size,
+                            max_buffer_size) {
 }
 
 template <bool THREADSAFE>


Mime
View raw message