Skip to content

Commit

Permalink
Fixed async bench
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Feb 1, 2025
1 parent 27d8580 commit 22405cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions bench/async_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<spdlog::logger> log, int thread_count);

Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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<sinks::async_sink>(cfg);
auto logger = std::make_shared<spdlog::logger>("async_logger", std::move(async_sink));
auto sink = std::make_shared<async_sink>(cfg);
auto logger = std::make_shared<spdlog::logger>("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
Expand All @@ -120,8 +119,8 @@ int main(int argc, char *argv[]) {
cfg.queue_size = queue_size;
auto file_sink = std::make_shared<basic_file_sink_mt>(filename, true);
cfg.sinks.push_back(std::move(file_sink));
auto async_sink = std::make_shared<sinks::async_sink>(cfg);
auto logger = std::make_shared<spdlog::logger>("async_logger", std::move(async_sink));
auto sink = std::make_shared<async_sink>(cfg);
auto logger = std::make_shared<spdlog::logger>("async_logger", std::move(sink));
bench_mt(howmany, std::move(logger), threads);
}
spdlog::shutdown();
Expand Down
4 changes: 2 additions & 2 deletions bench/latency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<null_sink_st>());
config.policy = async_sink::overflow_policy::overrun_oldest;
auto async_logger = std::make_shared<spdlog::logger>("async_logger", std::make_shared<async_sink>(config));
Expand Down

0 comments on commit 22405cf

Please sign in to comment.