mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 09:59:33 +08:00
replaced the lockfree queue with bounded, locked queue
This commit is contained in:
@@ -7,8 +7,7 @@
|
||||
// bench.cpp : spdlog benchmarks
|
||||
//
|
||||
#include "spdlog/async_logger.h"
|
||||
#include "spdlog/sinks/file_sinks.h"
|
||||
#include "spdlog/sinks/null_sink.h"
|
||||
#include "spdlog/sinks/test_sink.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utils.h"
|
||||
#include <atomic>
|
||||
@@ -30,12 +29,10 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int queue_size = 1048576;
|
||||
int queue_size = 1024*1024;
|
||||
int howmany = 1000000;
|
||||
int threads = 10;
|
||||
int file_size = 30 * 1024 * 1024;
|
||||
int rotating_files = 5;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -45,7 +42,7 @@ int main(int argc, char *argv[])
|
||||
threads = atoi(argv[2]);
|
||||
if (argc > 3)
|
||||
queue_size = atoi(argv[3]);
|
||||
|
||||
/*
|
||||
cout << "*******************************************************************************\n";
|
||||
cout << "Single thread, " << format(howmany) << " iterations" << endl;
|
||||
cout << "*******************************************************************************\n";
|
||||
@@ -67,17 +64,32 @@ int main(int argc, char *argv[])
|
||||
bench_mt(howmany, daily_mt, threads);
|
||||
bench(howmany, spdlog::create<null_sink_st>("null_mt"));
|
||||
|
||||
*/
|
||||
|
||||
cout << "\n*******************************************************************************\n";
|
||||
cout << "async logging.. " << threads << " threads sharing same logger, " << format(howmany) << " iterations " << endl;
|
||||
cout << "*******************************************************************************\n";
|
||||
|
||||
spdlog::set_async_mode(queue_size);
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
|
||||
for (int i = 0; i < 300; ++i)
|
||||
{
|
||||
auto as = spdlog::daily_logger_st("as", "logs/daily_async.log");
|
||||
bench_mt(howmany, as, threads);
|
||||
//auto as = spdlog::daily_logger_mt("as", "logs/daily_async.log");
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||
//auto as = spdlog::basic_logger_mt("as", "logs/async.log", true);
|
||||
auto as = std::make_shared<spdlog::async_logger>("as", test_sink, queue_size, async_overflow_policy::block_retry, nullptr, std::chrono::milliseconds(2000));
|
||||
bench_mt(howmany, as, threads);
|
||||
as.reset();
|
||||
spdlog::drop("as");
|
||||
|
||||
auto msg_counter = test_sink->msg_counter();
|
||||
cout << "Count:" << msg_counter << endl;
|
||||
if (msg_counter != howmany)
|
||||
{
|
||||
cout << "ERROR! Expected " << howmany;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception &ex)
|
||||
@@ -119,6 +131,7 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
|
||||
if (counter > howmany)
|
||||
break;
|
||||
log->info("Hello logger: msg number {}", counter);
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
@@ -10,9 +10,6 @@
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="example.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\spdlog\async_logger.h" />
|
||||
<ClInclude Include="..\include\spdlog\common.h" />
|
||||
@@ -21,7 +18,6 @@
|
||||
<ClInclude Include="..\include\spdlog\details\file_helper.h" />
|
||||
<ClInclude Include="..\include\spdlog\details\logger_impl.h" />
|
||||
<ClInclude Include="..\include\spdlog\details\log_msg.h" />
|
||||
<ClInclude Include="..\include\spdlog\details\mpmc_bounded_q.h" />
|
||||
<ClInclude Include="..\include\spdlog\details\null_mutex.h" />
|
||||
<ClInclude Include="..\include\spdlog\details\os.h" />
|
||||
<ClInclude Include="..\include\spdlog\details\pattern_formatter_impl.h" />
|
||||
@@ -46,23 +42,26 @@
|
||||
<ClInclude Include="..\include\spdlog\spdlog.h" />
|
||||
<ClInclude Include="..\include\spdlog\tweakme.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="bench.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9E5AB93A-0CCE-4BAC-9FCB-0FC9CB5EB8D2}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>.</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
|
Reference in New Issue
Block a user