2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* FastTriggeredWatches.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fdbrpc/ContinuousSample.h"
|
|
|
|
#include "fdbclient/NativeAPI.h"
|
|
|
|
#include "fdbserver/TesterInterface.h"
|
|
|
|
#include "fdbclient/ReadYourWrites.h"
|
|
|
|
#include "fdbserver/Knobs.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbserver/workloads/workloads.h"
|
2018-08-11 06:18:24 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
struct FastTriggeredWatchesWorkload : TestWorkload {
|
|
|
|
int nodes, keyBytes;
|
|
|
|
double testDuration;
|
|
|
|
vector<Future<Void>> clients;
|
|
|
|
PerfIntCounter operations, retries;
|
|
|
|
Value defaultValue;
|
|
|
|
|
|
|
|
FastTriggeredWatchesWorkload(WorkloadContext const& wcx)
|
|
|
|
: TestWorkload(wcx), operations("Operations"), retries("Retries")
|
|
|
|
{
|
|
|
|
testDuration = getOption( options, LiteralStringRef("testDuration"), 600.0 );
|
|
|
|
nodes = getOption( options, LiteralStringRef("nodes"), 100 );
|
|
|
|
defaultValue = StringRef(format( "%010d", g_random->randomInt( 0, 1000 ) ));
|
|
|
|
keyBytes = std::max( getOption( options, LiteralStringRef("keyBytes"), 16 ), 16 );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::string description() { return "Watches"; }
|
|
|
|
|
|
|
|
virtual Future<Void> setup( Database const& cx ) {
|
|
|
|
if( clientId == 0 )
|
|
|
|
return _setup( cx, this );
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> _setup( Database cx, FastTriggeredWatchesWorkload* self ) {
|
|
|
|
state Transaction tr(cx);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
for(int i = 0; i < self->nodes; i+=2) tr.set(self->keyForIndex(i), self->defaultValue);
|
|
|
|
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( tr.commit() );
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
} catch (Error& e) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( tr.onError(e) );
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Future<Void> start( Database const& cx ) {
|
|
|
|
if( clientId == 0 )
|
|
|
|
return _start( cx, this );
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Version> setter( Database cx, Key key, Optional<Value> value ) {
|
|
|
|
state ReadYourWritesTransaction tr( cx );
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( delay( g_random->random01() ) );
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
if( value.present() )
|
|
|
|
tr.set( key, value.get() );
|
|
|
|
else
|
|
|
|
tr.clear( key );
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("FTWSetBegin").detail("Key", printable(key)).detail("Value", printable(value));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( tr.commit() );
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("FTWSetEnd").detail("Key", printable(key)).detail("Value", printable(value)).detail("Ver", tr.getCommittedVersion());
|
2017-05-26 04:48:44 +08:00
|
|
|
return tr.getCommittedVersion();
|
|
|
|
} catch( Error &e ) {
|
2018-08-02 05:30:57 +08:00
|
|
|
//TraceEvent("FTWSetError").error(e).detail("Key", printable(key)).detail("Value", printable(value));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( tr.onError(e) );
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> _start( Database cx, FastTriggeredWatchesWorkload* self ) {
|
|
|
|
state double testStart = now();
|
|
|
|
state Version lastReadVersion = 0;
|
|
|
|
try {
|
|
|
|
loop {
|
|
|
|
state double getDuration = 0;
|
|
|
|
state double watchEnd = 0;
|
|
|
|
state bool first = true;
|
|
|
|
state Key setKey = self->keyForIndex(g_random->randomInt(0,self->nodes));
|
|
|
|
state Optional<Value> setValue;
|
|
|
|
if( g_random->random01() > 0.5 )
|
|
|
|
setValue = StringRef(format( "%010d", g_random->randomInt( 0, 1000 )));
|
|
|
|
state Future<Version> setFuture = self->setter( cx, setKey, setValue );
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( delay( g_random->random01() ) );
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
|
|
|
state ReadYourWritesTransaction tr( cx );
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Optional<Value> val = wait( tr.get( setKey ) );
|
|
|
|
if(!first) {
|
|
|
|
getDuration = now() - watchEnd;
|
|
|
|
}
|
|
|
|
lastReadVersion = tr.getReadVersion().get();
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("FTWGet").detail("Key", printable(setKey)).detail("Value", printable(val)).detail("Ver", tr.getReadVersion().get());
|
2017-05-26 04:48:44 +08:00
|
|
|
if( val == setValue )
|
|
|
|
break;
|
|
|
|
ASSERT( first );
|
|
|
|
state Future<Void> watchFuture = tr.watch( setKey );
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( tr.commit() );
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("FTWStartWatch").detail("Key", printable(setKey));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( watchFuture );
|
2017-05-26 04:48:44 +08:00
|
|
|
watchEnd = now();
|
|
|
|
first = false;
|
|
|
|
} catch( Error &e ) {
|
2018-08-02 05:30:57 +08:00
|
|
|
//TraceEvent("FTWWatchError").error(e).detail("Key", printable(setKey));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( tr.onError(e) );
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Version ver = wait( setFuture );
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("FTWWatchDone").detail("Key", printable(setKey));
|
2017-05-26 04:48:44 +08:00
|
|
|
ASSERT( lastReadVersion - ver >= SERVER_KNOBS->MAX_VERSIONS_IN_FLIGHT || lastReadVersion - ver < SERVER_KNOBS->VERSIONS_PER_SECOND*(12+getDuration) );
|
|
|
|
|
|
|
|
if( now() - testStart > self->testDuration )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
} catch( Error &e ) {
|
|
|
|
TraceEvent(SevError, "FastWatchError").error(e,true);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Future<bool> check( Database const& cx ) {
|
|
|
|
bool ok = true;
|
|
|
|
for( int i = 0; i < clients.size(); i++ )
|
|
|
|
if( clients[i].isError() )
|
|
|
|
ok = false;
|
|
|
|
clients.clear();
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getMetrics( vector<PerfMetric>& m ) {
|
|
|
|
double duration = testDuration;
|
|
|
|
m.push_back( PerfMetric( "Operations/sec", operations.getValue() / duration, false ) );
|
|
|
|
m.push_back( operations.getMetric() );
|
|
|
|
m.push_back( retries.getMetric() );
|
|
|
|
}
|
|
|
|
|
|
|
|
Key keyForIndex( uint64_t index ) {
|
|
|
|
Key result = makeString( keyBytes );
|
|
|
|
uint8_t* data = mutateString( result );
|
|
|
|
memset(data, '.', keyBytes);
|
|
|
|
|
|
|
|
double d = double(index) / nodes;
|
|
|
|
emplaceIndex( data, 0, *(int64_t*)&d );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-02 05:30:57 +08:00
|
|
|
WorkloadFactory<FastTriggeredWatchesWorkload> FastTriggeredWatchesWorkloadFactory("FastTriggeredWatches");
|