From 22405cf9aedd4c001d55fe132bc76da49e638c53 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 1 Feb 2025 19:23:23 +0200 Subject: [PATCH] Fixed async bench --- bench/async_bench.cpp | 19 +++++++++---------- bench/latency.cpp | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/bench/async_bench.cpp b/bench/async_bench.cpp index d434a85e..bf255eda 100644 --- a/bench/async_bench.cpp +++ b/bench/async_bench.cpp @@ -21,8 +21,7 @@ using namespace std; using namespace std::chrono; -using namespace spdlog; -using namespace spdlog::sinks; +using spdlog::sinks::async_sink; void bench_mt(int howmany, std::shared_ptr log, int thread_count); @@ -50,8 +49,8 @@ using namespace spdlog::sinks; int main(int argc, char *argv[]) { // setlocale to show thousands separators std::locale::global(std::locale("en_US.UTF-8")); - int howmany = 1000000; - int queue_size = std::min(howmany + 2, 8192); + int howmany = 1'000'000; + int queue_size = async_sink::default_queue_size; int threads = 10; int iters = 3; @@ -75,14 +74,14 @@ int main(int argc, char *argv[]) { exit(1); } - constexpr int max_q_size = sinks::async_sink::max_queue_size; + constexpr int max_q_size = async_sink::max_queue_size; if(queue_size > max_q_size) { spdlog::error("Queue size too large. Max queue size is {:L}", max_q_size); exit(1); } - auto slot_size = sizeof(details::async_log_msg); + auto slot_size = sizeof(spdlog::details::async_log_msg); spdlog::info("-------------------------------------------------"); spdlog::info("Messages : {:L}", howmany); spdlog::info("Threads : {:L}", threads); @@ -102,8 +101,8 @@ int main(int argc, char *argv[]) { auto cfg = async_sink::config(); cfg.queue_size = queue_size; cfg.sinks.push_back(std::move(file_sink)); - auto async_sink = std::make_shared(cfg); - auto logger = std::make_shared("async_logger", std::move(async_sink)); + auto sink = std::make_shared(cfg); + auto logger = std::make_shared("async_logger", std::move(sink)); bench_mt(howmany, std::move(logger), threads); } // verify_file(filename, howmany); // in separate scope to ensure logger is destroyed and all logs were written @@ -120,8 +119,8 @@ int main(int argc, char *argv[]) { cfg.queue_size = queue_size; auto file_sink = std::make_shared(filename, true); cfg.sinks.push_back(std::move(file_sink)); - auto async_sink = std::make_shared(cfg); - auto logger = std::make_shared("async_logger", std::move(async_sink)); + auto sink = std::make_shared(cfg); + auto logger = std::make_shared("async_logger", std::move(sink)); bench_mt(howmany, std::move(logger), threads); } spdlog::shutdown(); diff --git a/bench/latency.cpp b/bench/latency.cpp index ac15974a..ac552bf1 100644 --- a/bench/latency.cpp +++ b/bench/latency.cpp @@ -153,8 +153,8 @@ int main(int argc, char *argv[]) { } using spdlog::sinks::async_sink; async_sink::config config; - config.queue_size = 3 * 1024 * 1024; - ; + config.queue_size = async_sink::default_queue_size;; + config.sinks.push_back(std::make_shared()); config.policy = async_sink::overflow_policy::overrun_oldest; auto async_logger = std::make_shared("async_logger", std::make_shared(config));