kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [2/2] kudu git commit: write_transaction: allocate RowOp objects from the arena
Date Tue, 28 Mar 2017 04:23:35 GMT
write_transaction: allocate RowOp objects from the arena

This improves the memory locality of write transactions by making all of
the RowOps in a batch come from the transaction's arena. Additionally
this reduces contention on tcmalloc since the arena grabs memory in
bulk.

I didn't benchmark this before/after, but in various write stress
testing this made a bit of a difference in cache miss rates and CPU time
spent in RowOp code.

Change-Id: I8e7969423c057f9bf1169fe066819228c59ed269
Reviewed-on: http://gerrit.cloudera.org:8080/6480
Reviewed-by: David Ribeiro Alves <dralves@apache.org>
Tested-by: Kudu Jenkins


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

Branch: refs/heads/master
Commit: 473221e20298f17d6416143ce7ce48013dbf2f8f
Parents: a51c9b0
Author: Todd Lipcon <todd@apache.org>
Authored: Fri Mar 24 17:39:05 2017 -0700
Committer: Todd Lipcon <todd@apache.org>
Committed: Tue Mar 28 04:11:44 2017 +0000

----------------------------------------------------------------------
 src/kudu/tablet/tablet.cc                         |  9 +--------
 src/kudu/tablet/transactions/write_transaction.cc | 17 ++++++++++++++++-
 src/kudu/tablet/transactions/write_transaction.h  |  6 ++----
 3 files changed, 19 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/473221e2/src/kudu/tablet/tablet.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet.cc b/src/kudu/tablet/tablet.cc
index 172e9d4..bc0a330 100644
--- a/src/kudu/tablet/tablet.cc
+++ b/src/kudu/tablet/tablet.cc
@@ -339,17 +339,10 @@ Status Tablet::DecodeWriteOperations(const Schema* client_schema,
   RETURN_NOT_OK(dec.DecodeOperations(&ops));
   TRACE_COUNTER_INCREMENT("num_ops", ops.size());
 
-  // Create RowOp objects for each
-  vector<RowOp*> row_ops;
-  row_ops.reserve(ops.size());
-  for (const DecodedRowOperation& op : ops) {
-    row_ops.push_back(new RowOp(op));
-  }
-
   // Important to set the schema before the ops -- we need the
   // schema in order to stringify the ops.
   tx_state->set_schema_at_decode_time(schema());
-  tx_state->swap_row_ops(&row_ops);
+  tx_state->SetRowOps(std::move(ops));
 
   return Status::OK();
 }

http://git-wip-us.apache.org/repos/asf/kudu/blob/473221e2/src/kudu/tablet/transactions/write_transaction.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/write_transaction.cc b/src/kudu/tablet/transactions/write_transaction.cc
index bfbc867..7efd276 100644
--- a/src/kudu/tablet/transactions/write_transaction.cc
+++ b/src/kudu/tablet/transactions/write_transaction.cc
@@ -253,6 +253,17 @@ void WriteTransactionState::ReleaseSchemaLock() {
   TRACE("Released schema lock");
 }
 
+void WriteTransactionState::SetRowOps(vector<DecodedRowOperation> decoded_ops) {
+  std::lock_guard<simple_spinlock> l(txn_state_lock_);
+  row_ops_.clear();
+  row_ops_.reserve(decoded_ops.size());
+
+  Arena* arena = this->arena();
+  for (DecodedRowOperation& op : decoded_ops) {
+    row_ops_.push_back(arena->NewObject<RowOp>(std::move(op)));
+  }
+}
+
 void WriteTransactionState::StartApplying() {
   CHECK_NOTNULL(mvcc_tx_.get())->StartApplying();
 }
@@ -343,7 +354,11 @@ void WriteTransactionState::ResetRpcFields() {
   std::lock_guard<simple_spinlock> l(txn_state_lock_);
   request_ = nullptr;
   response_ = nullptr;
-  STLDeleteElements(&row_ops_);
+  // these are allocated from the arena, so just run the dtors.
+  for (RowOp* op : row_ops_) {
+    op->~RowOp();
+  }
+  row_ops_.clear();
 }
 
 string WriteTransactionState::ToString() const {

http://git-wip-us.apache.org/repos/asf/kudu/blob/473221e2/src/kudu/tablet/transactions/write_transaction.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/write_transaction.h b/src/kudu/tablet/transactions/write_transaction.h
index 2d35d27..aa25a8e 100644
--- a/src/kudu/tablet/transactions/write_transaction.h
+++ b/src/kudu/tablet/transactions/write_transaction.h
@@ -158,10 +158,8 @@ class WriteTransactionState : public TransactionState {
     return row_ops_;
   }
 
-  void swap_row_ops(std::vector<RowOp*>* new_ops) {
-    std::lock_guard<simple_spinlock> l(txn_state_lock_);
-    row_ops_.swap(*new_ops);
-  }
+  // Set the 'row_ops' member based on the given decoded operations.
+  void SetRowOps(std::vector<DecodedRowOperation> decoded_ops);
 
   void UpdateMetricsForOp(const RowOp& op);
 


Mime
View raw message