Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 36e880e

Browse files
mbutrovichpervazea
authored andcommitted
Performance fixes: move all stats_mode checks to end of transaction (#1381)
* Removed all incremental stats updates from TimestampOrderingTransactionManager. Now processed entirely in TransactionManager's EndTransaction(). * Minor refactor on stats_type variable. * Added more comments to EndTransaction() * Adjust logic to find database oid in EndTransaction, also remove redundant code from Commit and Abort in TOTM. * Removed stats_mode check from BeginTransaction(). This requires us to rely on the transaction timestamp to calculate the latency stat during EndTransaction(). Loss in precision looks reasonable for stats purposes: transaction latency (new timestamp mode): 52.366000 transaction latency (old stats mode): 52.379732 Also moved all stats-related tasks from EndTransaction() to a dedicated function. * clang-format-3.6 on modified lines.
1 parent 0c64806 commit 36e880e

File tree

5 files changed

+101
-152
lines changed

5 files changed

+101
-152
lines changed

src/concurrency/timestamp_ordering_transaction_manager.cpp

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -225,27 +225,11 @@ bool TimestampOrderingTransactionManager::PerformRead(
225225

226226
// if we have already owned the version.
227227
PELOTON_ASSERT(IsOwner(current_txn, tile_group_header, tuple_id) == true);
228-
229-
// Increment table read op stats
230-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
231-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
232-
stats::BackendStatsContext::GetInstance()->IncrementTableReads(
233-
location.block);
234-
}
235-
236228
return true;
237229

238230
} else {
239231
// if it's not select for update, then update read set and return true.
240-
241232
current_txn->RecordRead(location);
242-
243-
// Increment table read op stats
244-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
245-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
246-
stats::BackendStatsContext::GetInstance()->IncrementTableReads(
247-
location.block);
248-
}
249233
return true;
250234
}
251235

@@ -283,26 +267,13 @@ bool TimestampOrderingTransactionManager::PerformRead(
283267
}
284268
// if we have already owned the version.
285269
PELOTON_ASSERT(IsOwner(current_txn, tile_group_header, tuple_id) == true);
286-
// Increment table read op stats
287-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
288-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
289-
stats::BackendStatsContext::GetInstance()->IncrementTableReads(
290-
location.block);
291-
}
292270
return true;
293271

294272
} else {
295273
// a transaction can never read an uncommitted version.
296274
if (IsOwner(current_txn, tile_group_header, tuple_id) == false) {
297275
if (IsOwned(current_txn, tile_group_header, tuple_id) == false) {
298276
current_txn->RecordRead(location);
299-
300-
// Increment table read op stats
301-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
302-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
303-
stats::BackendStatsContext::GetInstance()->IncrementTableReads(
304-
location.block);
305-
}
306277
return true;
307278

308279
} else {
@@ -315,14 +286,6 @@ bool TimestampOrderingTransactionManager::PerformRead(
315286
} else {
316287
// this version must already be in the read/write set.
317288
// so no need to update read set.
318-
// current_txn->RecordRead(location);
319-
320-
// Increment table read op stats
321-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
322-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
323-
stats::BackendStatsContext::GetInstance()->IncrementTableReads(
324-
location.block);
325-
}
326289
return true;
327290
}
328291
}
@@ -379,12 +342,6 @@ bool TimestampOrderingTransactionManager::PerformRead(
379342
PELOTON_ASSERT(GetLastReaderCommitId(tile_group_header, tuple_id) ==
380343
current_txn->GetCommitId() ||
381344
GetLastReaderCommitId(tile_group_header, tuple_id) == 0);
382-
// Increment table read op stats
383-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
384-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
385-
stats::BackendStatsContext::GetInstance()->IncrementTableReads(
386-
location.block);
387-
}
388345
return true;
389346

390347
} else {
@@ -395,13 +352,6 @@ bool TimestampOrderingTransactionManager::PerformRead(
395352
current_txn->GetCommitId(), false) == true) {
396353
// update read set.
397354
current_txn->RecordRead(location);
398-
399-
// Increment table read op stats
400-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
401-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
402-
stats::BackendStatsContext::GetInstance()->IncrementTableReads(
403-
location.block);
404-
}
405355
return true;
406356
} else {
407357
// if the tuple has been owned by some concurrent transactions,
@@ -419,14 +369,6 @@ bool TimestampOrderingTransactionManager::PerformRead(
419369

420370
// this version must already be in the read/write set.
421371
// so no need to update read set.
422-
// current_txn->RecordRead(location);
423-
424-
// Increment table read op stats
425-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
426-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
427-
stats::BackendStatsContext::GetInstance()->IncrementTableReads(
428-
location.block);
429-
}
430372
return true;
431373
}
432374
}
@@ -464,13 +406,6 @@ void TimestampOrderingTransactionManager::PerformInsert(
464406

465407
// Write down the head pointer's address in tile group header
466408
tile_group_header->SetIndirection(tuple_id, index_entry_ptr);
467-
468-
// Increment table insert op stats
469-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
470-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
471-
stats::BackendStatsContext::GetInstance()->IncrementTableInserts(
472-
location.block);
473-
}
474409
}
475410

476411
void TimestampOrderingTransactionManager::PerformUpdate(
@@ -548,13 +483,6 @@ void TimestampOrderingTransactionManager::PerformUpdate(
548483

549484
// Add the old tuple into the update set
550485
current_txn->RecordUpdate(old_location);
551-
552-
// Increment table update op stats
553-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
554-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
555-
stats::BackendStatsContext::GetInstance()->IncrementTableUpdates(
556-
new_location.block);
557-
}
558486
}
559487

560488
void TimestampOrderingTransactionManager::PerformUpdate(
@@ -581,13 +509,6 @@ void TimestampOrderingTransactionManager::PerformUpdate(
581509
// transaction
582510
// is updating a version that is installed by itself.
583511
// in this case, nothing needs to be performed.
584-
585-
// Increment table update op stats
586-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
587-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
588-
stats::BackendStatsContext::GetInstance()->IncrementTableUpdates(
589-
location.block);
590-
}
591512
}
592513

593514
void TimestampOrderingTransactionManager::PerformDelete(
@@ -669,13 +590,6 @@ void TimestampOrderingTransactionManager::PerformDelete(
669590
}
670591

671592
current_txn->RecordDelete(old_location);
672-
673-
// Increment table delete op stats
674-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
675-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
676-
stats::BackendStatsContext::GetInstance()->IncrementTableDeletes(
677-
old_location.block);
678-
}
679593
}
680594

681595
void TimestampOrderingTransactionManager::PerformDelete(
@@ -703,13 +617,6 @@ void TimestampOrderingTransactionManager::PerformDelete(
703617
// if this version is newly inserted.
704618
current_txn->RecordDelete(location);
705619
}
706-
707-
// Increment table delete op stats
708-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
709-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
710-
stats::BackendStatsContext::GetInstance()->IncrementTableDeletes(
711-
location.block);
712-
}
713620
}
714621

715622
ResultType TimestampOrderingTransactionManager::CommitTransaction(
@@ -752,20 +659,6 @@ ResultType TimestampOrderingTransactionManager::CommitTransaction(
752659
gc_object_set->emplace_back(database_oid, table_oid, index_oid);
753660
}
754661

755-
oid_t database_id = 0;
756-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
757-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
758-
for (const auto &tuple_entry : rw_set) {
759-
// Call the GetConstIterator() function to explicitly lock the cuckoohash
760-
// and initilaize the iterator
761-
const auto tile_group_id = tuple_entry.first.block;
762-
database_id = manager.GetTileGroup(tile_group_id)->GetDatabaseId();
763-
if (database_id != CATALOG_DATABASE_OID) {
764-
break;
765-
}
766-
}
767-
}
768-
769662
// install everything.
770663
// 1. install a new version for update operations;
771664
// 2. install an empty version for delete operations;
@@ -896,13 +789,6 @@ ResultType TimestampOrderingTransactionManager::CommitTransaction(
896789

897790
EndTransaction(current_txn);
898791

899-
// Increment # txns committed metric
900-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
901-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
902-
stats::BackendStatsContext::GetInstance()->IncrementTxnCommitted(
903-
database_id);
904-
}
905-
906792
return result;
907793
}
908794

@@ -930,20 +816,6 @@ ResultType TimestampOrderingTransactionManager::AbortTransaction(
930816
gc_object_set->emplace_back(database_oid, table_oid, index_oid);
931817
}
932818

933-
oid_t database_id = 0;
934-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
935-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
936-
for (const auto &tuple_entry : rw_set) {
937-
// Call the GetConstIterator() function to explicitly lock the cuckoohash
938-
// and initilaize the iterator
939-
const auto tile_group_id = tuple_entry.first.block;
940-
database_id = manager.GetTileGroup(tile_group_id)->GetDatabaseId();
941-
if (database_id != CATALOG_DATABASE_OID) {
942-
break;
943-
}
944-
}
945-
}
946-
947819
// Iterate through each item pointer in the read write set
948820
// TODO (Pooja): This might be inefficient since we will have to get the
949821
// tile_group_header for each entry. Check if this needs to be consolidated
@@ -1085,12 +957,6 @@ ResultType TimestampOrderingTransactionManager::AbortTransaction(
1085957
current_txn->SetResult(ResultType::ABORTED);
1086958
EndTransaction(current_txn);
1087959

1088-
// Increment # txns aborted metric
1089-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
1090-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
1091-
stats::BackendStatsContext::GetInstance()->IncrementTxnAborted(database_id);
1092-
}
1093-
1094960
return ResultType::ABORTED;
1095961
}
1096962

src/concurrency/transaction_manager.cpp

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ TransactionContext *TransactionManager::BeginTransaction(
6464
txn->SetReadOnly();
6565
}
6666

67-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
68-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
69-
stats::BackendStatsContext::GetInstance()
70-
->GetTxnLatencyMetric()
71-
.StartTimer();
72-
}
73-
7467
txn->SetTimestamp(function::DateFunctions::Now());
7568

7669
return txn;
@@ -82,21 +75,23 @@ void TransactionManager::EndTransaction(TransactionContext *current_txn) {
8275
current_txn->ExecOnCommitTriggers();
8376
}
8477

85-
if(gc::GCManagerFactory::GetGCType() == GarbageCollectionType::ON) {
78+
// log RWSet and result stats
79+
const auto &stats_type = static_cast<StatsType>(
80+
settings::SettingsManager::GetInt(settings::SettingId::stats_mode));
81+
82+
// update stats
83+
if (stats_type != StatsType::INVALID) {
84+
RecordTransactionStats(current_txn);
85+
}
86+
87+
// pass transaction context to garbage collector
88+
if (gc::GCManagerFactory::GetGCType() == GarbageCollectionType::ON) {
8689
gc::GCManagerFactory::GetInstance().RecycleTransaction(current_txn);
8790
} else {
8891
delete current_txn;
8992
}
9093

9194
current_txn = nullptr;
92-
93-
if (static_cast<StatsType>(settings::SettingsManager::GetInt(
94-
settings::SettingId::stats_mode)) != StatsType::INVALID) {
95-
stats::BackendStatsContext::GetInstance()
96-
->GetTxnLatencyMetric()
97-
.RecordLatency();
98-
99-
}
10095
}
10196

10297
// this function checks whether a concurrent transaction is inserting the same
@@ -253,5 +248,74 @@ VisibilityType TransactionManager::IsVisible(
253248
}
254249
}
255250

251+
void TransactionManager::RecordTransactionStats(
252+
const TransactionContext *const current_txn) const {
253+
PELOTON_ASSERT(static_cast<StatsType>(settings::SettingsManager::GetInt(
254+
settings::SettingId::stats_mode)) != StatsType::INVALID);
255+
256+
auto stats_context = stats::BackendStatsContext::GetInstance();
257+
const auto &rw_set = current_txn->GetReadWriteSet();
258+
259+
// update counters for each element in the RWSet
260+
for (const auto &element : rw_set) {
261+
const auto &tile_group_id = element.first.block;
262+
const auto &rw_type = element.second;
263+
switch (rw_type) {
264+
case RWType::READ:
265+
case RWType::READ_OWN:
266+
stats_context->IncrementTableReads(tile_group_id);
267+
break;
268+
case RWType::UPDATE:
269+
stats_context->IncrementTableUpdates(tile_group_id);
270+
break;
271+
case RWType::INSERT:
272+
stats_context->IncrementTableInserts(tile_group_id);
273+
break;
274+
case RWType::DELETE:
275+
stats_context->IncrementTableDeletes(tile_group_id);
276+
break;
277+
case RWType::INS_DEL:
278+
stats_context->IncrementTableInserts(tile_group_id);
279+
stats_context->IncrementTableDeletes(tile_group_id);
280+
break;
281+
default:
282+
break;
283+
}
284+
}
285+
286+
// get database_id from RWSet
287+
oid_t database_id = 0;
288+
for (const auto &tuple_entry : rw_set) {
289+
// Call the GetConstIterator() function to explicitly lock the cuckoohash
290+
// and initilaize the iterator
291+
const auto &tile_group_id = tuple_entry.first.block;
292+
database_id = catalog::Manager::GetInstance()
293+
.GetTileGroup(tile_group_id)
294+
->GetDatabaseId();
295+
if (database_id != CATALOG_DATABASE_OID) {
296+
break;
297+
}
298+
}
299+
300+
// update transaction result stat
301+
switch (current_txn->GetResult()) {
302+
case ResultType::ABORTED:
303+
stats_context->IncrementTxnAborted(database_id);
304+
break;
305+
case ResultType::SUCCESS:
306+
stats_context->IncrementTxnCommitted(database_id);
307+
break;
308+
default:
309+
break;
310+
}
311+
312+
// update latency results using txn timestamp instead of LatencyMetric timer
313+
// divide by 1000 to get to ms
314+
auto txn_latency = static_cast<double>(function::DateFunctions::Now() -
315+
current_txn->GetTimestamp()) /
316+
1000;
317+
stats_context->GetTxnLatencyMetric().RecordLatency(txn_latency);
318+
}
319+
256320
} // namespace concurrency
257321
} // namespace peloton

src/include/concurrency/transaction_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class TransactionContext : public Printable {
203203
*
204204
* @return The read write set.
205205
*/
206-
inline const ReadWriteSet &GetReadWriteSet() { return rw_set_; }
206+
inline const ReadWriteSet &GetReadWriteSet() const { return rw_set_; }
207207
inline const CreateDropSet &GetCreateDropSet() { return rw_object_set_; }
208208

209209
/**

src/include/concurrency/transaction_manager.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,16 @@ class TransactionManager {
233233
*/
234234
void EndTransaction(TransactionContext *current_txn);
235235

236-
virtual ResultType CommitTransaction(TransactionContext *const current_txn) = 0;
236+
/**
237+
* @brief Record transaction results
238+
* @param[in] current_txn The current transaction
239+
* @warning Assumes stats_mode != INVALID
240+
*/
241+
void RecordTransactionStats(
242+
const TransactionContext *const current_txn) const;
243+
244+
virtual ResultType CommitTransaction(
245+
TransactionContext *const current_txn) = 0;
237246

238247
virtual ResultType AbortTransaction(TransactionContext *const current_txn) = 0;
239248

0 commit comments

Comments
 (0)