foundationdb/fdbserver/workloads/PubSubMultiples.actor.cpp

118 lines
4.3 KiB
C++
Raw Normal View History

2017-05-26 04:48:44 +08:00
/*
* PubSubMultiples.actor.cpp
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
*
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
*
2017-05-26 04:48:44 +08:00
* http://www.apache.org/licenses/LICENSE-2.0
*
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 "fdbclient/NativeAPI.actor.h"
2017-05-26 04:48:44 +08:00
#include "fdbserver/pubsub.h"
#include "fdbserver/TesterInterface.actor.h"
#include "fdbserver/workloads/workloads.actor.h"
#include "flow/actorcompiler.h" // This must be the last #include.
2017-05-26 04:48:44 +08:00
struct PubSubMultiplesWorkload : TestWorkload {
double testDuration, messagesPerSecond;
int actorCount, inboxesPerActor;
vector<Future<Void>> inboxWatchers;
PerfIntCounter messages;
PubSubMultiplesWorkload(WorkloadContext const& wcx) : TestWorkload(wcx), messages("Messages") {
testDuration = getOption(options, LiteralStringRef("testDuration"), 10.0);
messagesPerSecond = getOption(options, LiteralStringRef("messagesPerSecond"), 500.0) / clientCount;
actorCount = getOption(options, LiteralStringRef("actorsPerClient"), 20);
inboxesPerActor = getOption(options, LiteralStringRef("inboxesPerActor"), 20);
2017-05-26 04:48:44 +08:00
}
2020-10-05 13:29:07 +08:00
std::string description() const override { return "PubSubMultiplesWorkload"; }
Future<Void> setup(Database const& cx) override { return createNodes(this, cx); }
Future<Void> start(Database const& cx) override {
Future<Void> _ = startTests(this, cx);
2017-05-26 04:48:44 +08:00
return delay(testDuration);
}
2020-10-05 13:29:07 +08:00
Future<bool> check(Database const& cx) override { return true; }
2017-05-26 04:48:44 +08:00
2020-10-05 13:29:07 +08:00
void getMetrics(vector<PerfMetric>& m) override { m.push_back(messages.getMetric()); }
2017-05-26 04:48:44 +08:00
Key keyForFeed(int i) { return StringRef(format("/PSM/feeds/%d", i)); }
Key keyForInbox(int i) { return StringRef(format("/PSM/inbox/%d", i)); }
Value valueForUInt(uint64_t i) { return StringRef(format("%llx", i)); }
2017-05-26 04:48:44 +08:00
ACTOR Future<Void> createNodeSwath(PubSubMultiplesWorkload* self, int actor, Database cx) {
2017-05-26 04:48:44 +08:00
state PubSub ps(cx);
state vector<uint64_t> feeds;
state vector<uint64_t> inboxes;
state int idx;
for (idx = 0; idx < self->inboxesPerActor; idx++) {
uint64_t feedIdx = wait(ps.createFeed(StringRef()));
feeds.push_back(feedIdx);
uint64_t inboxIdx = wait(ps.createInbox(StringRef()));
inboxes.push_back(inboxIdx);
2017-05-26 04:48:44 +08:00
}
state Transaction tr(cx);
loop {
try {
for (int idx = 0; idx < self->inboxesPerActor; idx++) {
int offset = (self->clientId * self->clientCount * self->actorCount * self->inboxesPerActor) +
(actor * self->actorCount * self->inboxesPerActor) + idx;
tr.set(self->keyForFeed(offset), self->valueForUInt(feeds[idx]));
tr.set(self->keyForInbox(offset), self->valueForUInt(inboxes[idx]));
2017-05-26 04:48:44 +08:00
}
wait(tr.commit());
2017-05-26 04:48:44 +08:00
break;
} catch (Error& e) {
wait(tr.onError(e));
2017-05-26 04:48:44 +08:00
}
}
return Void();
}
ACTOR Future<Void> createNodes(PubSubMultiplesWorkload* self, Database cx) {
2017-05-26 04:48:44 +08:00
state PubSub ps(cx);
vector<Future<Void>> actors;
actors.reserve(self->actorCount);
for (int i = 0; i < self->actorCount; i++)
actors.push_back(self->createNodeSwath(self, i, cx->clone()));
wait(waitForAll(actors));
2017-05-26 04:48:44 +08:00
TraceEvent("PSMNodesCreated").detail("ClientIdx", self->clientId);
return Void();
}
/*ACTOR*/ Future<Void> createSubscriptions(PubSubMultiplesWorkload* self, int actor, Database cx) {
2017-05-26 04:48:44 +08:00
// create the "multiples" subscriptions for each owned inbox
return Void();
}
/*ACTOR*/ Future<Void> messageSender(PubSubMultiplesWorkload* self, Database cx) {
2017-05-26 04:48:44 +08:00
// use a possion loop and post messages to feeds
return Void();
}
ACTOR Future<Void> startTests(PubSubMultiplesWorkload* self, Database cx) {
2017-05-26 04:48:44 +08:00
vector<Future<Void>> subscribers;
subscribers.reserve(self->actorCount);
for (int i = 0; i < self->actorCount; i++)
subscribers.push_back(self->createSubscriptions(self, i, cx));
wait(waitForAll(subscribers));
2017-05-26 04:48:44 +08:00
state Future<Void> sender = self->messageSender(self, cx);
2017-05-26 04:48:44 +08:00
return Void();
}
};
WorkloadFactory<PubSubMultiplesWorkload> PubSubMultiplesWorkloadFactory("PubSubMultiples");