eliminate cost estimation when tagSet is empty

This commit is contained in:
Xiaoxi Wang 2020-07-14 23:07:21 +00:00
parent a310faf9d1
commit bcb858288b
7 changed files with 30 additions and 16 deletions

View File

@ -231,8 +231,6 @@ void ClientKnobs::initialize(bool randomize) {
init( TAG_THROTTLE_SMOOTHING_WINDOW, 2.0 );
init( TAG_THROTTLE_RECHECK_INTERVAL, 5.0 ); if( randomize && BUGGIFY ) TAG_THROTTLE_RECHECK_INTERVAL = 0.0;
init( TAG_THROTTLE_EXPIRATION_INTERVAL, 60.0 ); if( randomize && BUGGIFY ) TAG_THROTTLE_EXPIRATION_INTERVAL = 1.0;
init( EXPENSIVE_COMMIT_COST_ESTIMATION_FRAC, 0.0);
// clang-format on
}

View File

@ -219,9 +219,6 @@ public:
double TAG_THROTTLE_RECHECK_INTERVAL;
double TAG_THROTTLE_EXPIRATION_INTERVAL;
double EXPENSIVE_COMMIT_COST_ESTIMATION_FRAC; // 0 --> estimate through shard-map; 1 --> estimate by asking StorageServer
// (more accurate but more expensive)
ClientKnobs();
void initialize(bool randomize = false);
};

View File

@ -158,8 +158,8 @@ struct CommitTransactionRequest : TimedRequest {
ReplyPromise<CommitID> reply;
uint32_t flags;
Optional<UID> debugID;
TransactionCommitCostEstimation commitCostEstimation;
TagSet tagSet;
Optional<TransactionCommitCostEstimation> commitCostEstimation;
Optional<TagSet> tagSet;
CommitTransactionRequest() : flags(0) {}

View File

@ -3270,7 +3270,7 @@ ACTOR Future<TransactionCommitCostEstimation> estimateCommitCosts(Transaction* s
trCommitCosts.numAtomicWrite++;
} else if (it->type == MutationRef::Type::ClearRange) {
trCommitCosts.numClear ++;
if (deterministicRandom()->random01() < CLIENT_KNOBS->EXPENSIVE_COMMIT_COST_ESTIMATION_FRAC) {
if(self->options.expensiveClearCostEstimation) {
try {
StorageMetrics m = wait(self->getStorageMetrics(KeyRangeRef(it->param1, it->param2), -1));
trCommitCosts.bytesClearEst += m.bytes;
@ -3300,10 +3300,17 @@ ACTOR static Future<Void> tryCommit( Database cx, Reference<TransactionLogInfo>
commit_unknown_result()});
}
if(!req.tagSet.present()) {
Version v = wait(readVersion);
req.transaction.read_snapshot = v;
TransactionCommitCostEstimation costEst = wait( estimateCommitCosts(tr, &req.transaction) );
}
else {
Version v;
TransactionCommitCostEstimation costEst;
wait(store(v, readVersion) && store(costEst, estimateCommitCosts(tr, &req.transaction)));
req.transaction.read_snapshot = v;
req.commitCostEstimation = costEst; // estimateCommitCosts(tr, &req.transaction, false);
}
startTime = now();
state Optional<UID> commitID = Optional<UID>();
@ -3449,6 +3456,7 @@ Future<Void> Transaction::commitMutations() {
cx->mutationsPerCommit.addSample(tr.transaction.mutations.size());
cx->bytesPerCommit.addSample(tr.transaction.mutations.expectedSize());
if(options.tags.size())
tr.tagSet = options.tags;
size_t transactionSize = getSize();
@ -3728,7 +3736,10 @@ void Transaction::setOption( FDBTransactionOptions::Option option, Optional<Stri
validateOptionValue(value, false);
options.reportConflictingKeys = true;
break;
case FDBTransactionOptions::EXPENSIVE_CLEAR_COST_ESTIMATION_ENABLE:
validateOptionValue(value, false);
options.expensiveClearCostEstimation = true;
break;
default:
break;
}

View File

@ -133,6 +133,7 @@ struct TransactionOptions {
bool firstInBatch : 1;
bool includePort : 1;
bool reportConflictingKeys : 1;
bool expensiveClearCostEstimation : 1;
TransactionPriority priority;

View File

@ -270,6 +270,8 @@ description is not currently required but encouraged.
description="Adds a tag to the transaction that can be used to apply manual or automatic targeted throttling. At most 5 tags can be set on a transaction." />
<Option name="span_parent" code="900" paramType="Bytes" paramDescription="A byte string of length 16 used to associate the span of this transaction with a parent"
description="Adds a parent to the Span of this transaction. Used for transaction tracing. A span can be identified with any 16 bytes"/>
<Option name="expensive_clear_cost_estimation_enable" code="1000"
description="Asks storage servers for how many bytes a clear key range contains. Otherwise uses the location cache to roughly estimate this." />
</Scope>
<!-- The enumeration values matter - do not change them without

View File

@ -1340,8 +1340,13 @@ ACTOR Future<Void> commitBatch(
ASSERT_WE_THINK(commitVersion != invalidVersion);
trs[t].reply.send(CommitID(commitVersion, t, metadataVersionAfter));
// aggregate commit cost estimation iff committed
for (auto& tag : trs[t].tagSet) {
(self->transactionTagCommitCostEst)[tag] += trs[t].commitCostEstimation;
ASSERT((trs[t].commitCostEstimation.present() && trs[t].tagSet.present()) ||
(!trs[t].commitCostEstimation.present() && !trs[t].tagSet.present()));
if (trs[t].tagSet.present()) {
TransactionCommitCostEstimation& costEstimation = trs[t].commitCostEstimation.get();
for (auto& tag : trs[t].tagSet.get()) {
(self->transactionTagCommitCostEst)[tag] += costEstimation;
}
}
}
else if (committed[t] == ConflictBatch::TransactionTooOld) {