2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* UnitPerf.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
2022-03-22 04:36:23 +08:00
|
|
|
* Copyright 2013-2022 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/ActorFuzz.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"
|
2019-02-18 10:46:59 +08:00
|
|
|
#include "flow/actorcompiler.h" // has to be last include
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
ACTOR Future<Void> sleepyActor(double interval, int* counter) {
|
|
|
|
loop {
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(delay(interval));
|
2017-05-26 04:48:44 +08:00
|
|
|
++*counter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> unitPerfTest() {
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
state int counter = 0;
|
2021-09-17 08:42:34 +08:00
|
|
|
state std::vector<Future<Void>> sleepy;
|
2021-03-04 11:36:21 +08:00
|
|
|
sleepy.reserve(100000);
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < 100000; i++)
|
|
|
|
sleepy.push_back(sleepyActor(.1, &counter));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(delay(10));
|
2017-05-26 04:48:44 +08:00
|
|
|
sleepy.clear();
|
|
|
|
TraceEvent("Completed").detail("Count", counter);
|
|
|
|
printf("Completed: %d\n", counter);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct UnitPerfWorkload : TestWorkload {
|
|
|
|
bool enabled;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
UnitPerfWorkload(WorkloadContext const& wcx) : TestWorkload(wcx) {
|
2017-05-26 04:48:44 +08:00
|
|
|
enabled = !clientId; // only do this on the "first" client
|
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
std::string description() const override { return "UnitPerfWorkload"; }
|
|
|
|
Future<Void> setup(Database const& cx) override { return Void(); }
|
|
|
|
Future<Void> start(Database const& cx) override {
|
2017-05-26 04:48:44 +08:00
|
|
|
if (enabled)
|
|
|
|
return unitPerfTest();
|
|
|
|
return Void();
|
|
|
|
}
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<bool> check(Database const& cx) override { return true; }
|
2021-09-17 08:42:34 +08:00
|
|
|
void getMetrics(std::vector<PerfMetric>& m) override {}
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2019-02-18 10:46:59 +08:00
|
|
|
WorkloadFactory<UnitPerfWorkload> UnitPerfWorkloadFactory("UnitPerf");
|