Commit 8bb0525b authored by Miroslav Crnic's avatar Miroslav Crnic Committed by Facebook Github Bot

NotificationQueueBenchmark add zero congestion benchmarks

Summary: While congested throughput is important it is also important not to regress non congested path too much.

Reviewed By: aary

Differential Revision: D16005428

fbshipit-source-id: 7b98a7ef253fc306b3097f7236b57a5d453ed15d
parent 35c941e4
......@@ -16,6 +16,7 @@
#include <folly/Benchmark.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/NotificationQueue.h>
#include <folly/synchronization/Baton.h>
#include <condition_variable>
#include <mutex>
......@@ -25,6 +26,13 @@ using namespace folly;
static size_t constexpr kMaxRead = 20;
class MockConsumer : public NotificationQueue<Func>::Consumer {
public:
void messageAvailable(Func&& message) noexcept override {
message();
}
};
void runTest(int iters, int numThreads) {
BenchmarkSuspender susp;
EventBase evb;
......@@ -75,6 +83,37 @@ void runTest(int iters, int numThreads) {
}
}
BENCHMARK(EnqueueBenchmark, n) {
BenchmarkSuspender suspender;
NotificationQueue<Func> queue;
suspender.dismiss();
for (unsigned int i = 0; i < n; ++i) {
queue.putMessage(Func());
}
suspender.rehire();
}
BENCHMARK(DequeueBenchmark, n) {
BenchmarkSuspender suspender;
NotificationQueue<Func> queue;
EventBase base;
MockConsumer consumer;
consumer.setMaxReadAtOnce(kMaxRead);
consumer.startConsumingInternal(&base, &queue);
for (unsigned int i = 0; i < n; ++i) {
queue.putMessage([]() {});
}
suspender.dismiss();
for (unsigned int i = 0; i <= (n / kMaxRead); ++i) {
consumer.handlerReady(0);
}
suspender.rehire();
if (queue.size() > 0) {
throw std::logic_error("This should not happen batching might be broken");
}
consumer.stopConsuming();
}
BENCHMARK_PARAM(runTest, 1)
BENCHMARK_PARAM(runTest, 2)
BENCHMARK_PARAM(runTest, 4)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment