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
|
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.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 07:41:16 +08:00
|
|
|
#include "fdbclient/NativeAPI.actor.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "fdbserver/pubsub.h"
|
2019-02-18 11:25:16 +08:00
|
|
|
#include "fdbserver/TesterInterface.actor.h"
|
2019-02-18 11:18:30 +08:00
|
|
|
#include "fdbserver/workloads/workloads.actor.h"
|
2021-03-11 02:06:03 +08:00
|
|
|
#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;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
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 {
|
2021-03-11 02:06:03 +08:00
|
|
|
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
|
|
|
|
2021-03-11 02:06:03 +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
|
|
|
|
2021-03-11 02:06:03 +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;
|
2021-03-11 02:06:03 +08:00
|
|
|
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 {
|
2021-03-11 02:06:03 +08:00
|
|
|
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
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(tr.commit());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
wait(tr.onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> createNodes(PubSubMultiplesWorkload* self, Database cx) {
|
2017-05-26 04:48:44 +08:00
|
|
|
state PubSub ps(cx);
|
|
|
|
vector<Future<Void>> actors;
|
2021-03-04 11:36:21 +08:00
|
|
|
actors.reserve(self->actorCount);
|
2021-03-11 02:06:03 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
/*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();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
/*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();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> startTests(PubSubMultiplesWorkload* self, Database cx) {
|
2017-05-26 04:48:44 +08:00
|
|
|
vector<Future<Void>> subscribers;
|
2021-03-04 11:36:21 +08:00
|
|
|
subscribers.reserve(self->actorCount);
|
2021-03-11 02:06:03 +08:00
|
|
|
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
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
state Future<Void> sender = self->messageSender(self, cx);
|
2017-05-26 04:48:44 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WorkloadFactory<PubSubMultiplesWorkload> PubSubMultiplesWorkloadFactory("PubSubMultiples");
|