Skip to content

Commit

Permalink
Add coroutine net2 benchmarks
Browse files Browse the repository at this point in the history
Benchmark                                                        Time             CPU      Time Old      Time New       CPU Old       CPU New
---------------------------------------------------------------------------------------------------------------------------------------------
[bench_delay vs. coroutine_delay]<DELAY>/0                    +0.0418         +0.0418           102           106           102           106
[bench_delay vs. coroutine_delay]<DELAY>/1                    +0.0424         +0.0424           102           107           102           107
[bench_delay vs. coroutine_delay]<DELAY>/8                    +0.0393         +0.0393           102           106           102           106
[bench_delay vs. coroutine_delay]<DELAY>/64                   +0.0638         +0.0638           115           122           115           122
[bench_delay vs. coroutine_delay]<DELAY>/512                  +0.0429         +0.0429           127           132           127           132
[bench_delay vs. coroutine_delay]<DELAY>/4096                 +0.0369         +0.0369           137           142           137           142
[bench_delay vs. coroutine_delay]<DELAY>/32768                +0.0498         +0.0498           149           157           149           157
[bench_delay vs. coroutine_delay]<DELAY>/65536                +0.0343         +0.0343           174           180           174           180
[bench_delay vs. coroutine_delay]<YIELD>/0                    +0.0976         +0.0976            46            50            46            50
[bench_delay vs. coroutine_delay]<YIELD>/1                    +0.0331         +0.0331            42            43            42            43
[bench_delay vs. coroutine_delay]<YIELD>/8                    +0.0293         +0.0293            42            43            42            43
[bench_delay vs. coroutine_delay]<YIELD>/64                   +0.0300         +0.0300            42            43            42            43
[bench_delay vs. coroutine_delay]<YIELD>/512                  +0.0294         +0.0294            42            43            42            43
[bench_delay vs. coroutine_delay]<YIELD>/4096                 +0.0271         +0.0271            42            43            42            43
[bench_delay vs. coroutine_delay]<YIELD>/32768                +0.0320         +0.0320            43            45            43            45
[bench_delay vs. coroutine_delay]<YIELD>/65536                +0.0264         +0.0264            46            47            46            47
OVERALL_GEOMEAN                                               +0.0409         +0.0409             0             0             0             0

Comparing bench_net2 to coroutine_net2 (from ./cbuild_output/bin/flowbench)
Benchmark                                               Time             CPU      Time Old      Time New       CPU Old       CPU New
------------------------------------------------------------------------------------------------------------------------------------
[bench_net2 vs. coroutine_net2]/1                    +0.0317         +0.0317          1660          1712          1660          1712
[bench_net2 vs. coroutine_net2]/8                    +0.0627         +0.0627          2900          3082          2900          3082
[bench_net2 vs. coroutine_net2]/64                   +0.1096         +0.1096         13499         14979         13498         14978
[bench_net2 vs. coroutine_net2]/512                  +0.1434         +0.1434        119422        136551        119420        136549
[bench_net2 vs. coroutine_net2]/4096                 +0.1966         +0.1966       1269104       1518596       1269076       1518563
[bench_net2 vs. coroutine_net2]/32768                +0.1929         +0.1929      13250215      15805923      13249663      15805633
[bench_net2 vs. coroutine_net2]/65536                +0.3265         +0.3265      30584645      40571416      30584104      40569898
OVERALL_GEOMEAN                                      +0.1484         +0.1484             0             0             0             0
  • Loading branch information
jzhou77 committed Aug 26, 2024
1 parent b07498b commit d939f97
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions flowbench/BenchNet2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* BenchNet2.cpp
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2024 Apple Inc. and the FoundationDB project authors
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 "benchmark/benchmark.h"

#include "flow/IRandom.h"
#include "flow/flow.h"
#include "flow/DeterministicRandom.h"
#include "flow/network.h"
#include "flow/ThreadHelper.actor.h"

#include "flow/actorcompiler.h" // This must be the last #include.

static Future<Void> increment(TaskPriority priority, uint32_t* sum) {
co_await delay(0, priority);
++(*sum);
}

static inline TaskPriority getRandomTaskPriority(DeterministicRandom& rand) {
return static_cast<TaskPriority>(rand.randomInt(0, 100));
}

static Future<Void> benchNet2Actor(benchmark::State* benchState) {
size_t actorCount = benchState->range(0);
uint32_t sum;
int seed = platform::getRandomSeed();
while (benchState->KeepRunning()) {
sum = 0;
std::vector<Future<Void>> futures;
futures.reserve(actorCount);
DeterministicRandom rand(seed);
for (int i = 0; i < actorCount; ++i) {
futures.push_back(increment(getRandomTaskPriority(rand), &sum));
}
co_await waitForAll(futures);
benchmark::DoNotOptimize(sum);
}
benchState->SetItemsProcessed(actorCount * static_cast<long>(benchState->iterations()));
}

static void coroutine_net2(benchmark::State& benchState) {
onMainThread([&benchState] { return benchNet2Actor(&benchState); }).blockUntilReady();
}

BENCHMARK(coroutine_net2)->Range(1, 1 << 16)->ReportAggregatesOnly(true);

static constexpr bool DELAY = false;
static constexpr bool YIELD = true;

template <bool useYield>
static Future<Void> benchDelay(benchmark::State* benchState) {
// Number of random delays to start to just to populate the run loop
// priority queue
int64_t timerCount = benchState->range(0);
std::vector<Future<Void>> futures;
DeterministicRandom rand(platform::getRandomSeed());
while (--timerCount > 0) {
futures.push_back(delay(1.0 + rand.random01(), getRandomTaskPriority(rand)));
}

while (benchState->KeepRunning()) {
co_await (useYield ? yield() : delay(0));
}
benchState->SetItemsProcessed(static_cast<long>(benchState->iterations()));
}

template <bool useYield>
static void coroutine_delay(benchmark::State& benchState) {
onMainThread([&benchState] { return benchDelay<useYield>(&benchState); }).blockUntilReady();
}

BENCHMARK_TEMPLATE(coroutine_delay, DELAY)->Range(0, 1 << 16)->ReportAggregatesOnly(true);
BENCHMARK_TEMPLATE(coroutine_delay, YIELD)->Range(0, 1 << 16)->ReportAggregatesOnly(true);

0 comments on commit d939f97

Please sign in to comment.