g3log logger in c++ introduces stall/latency on logger initialization

  aio, c++, latency, logging

I am using libaio library to write to a file on disk using c++. I am using g3log for logging messages and have initialized the logger like this :

auto log_worker = g3::LogWorker::createLogWorker();
auto sink_handle = log_worker->addSink(std::make_unique<CustomSink>(), &CustomSink::forwardLogToStdout);
g3::initializeLogging(log_worker.get());

I have created a custom class like this:

class CustomSink{
public: 
   void forwardLogToStdout(g3::LogMessageMover logEntry)
   {
     std::cout<<logEntry.get().message()<<"n";
   }
};

I have a class Foo which has a member function func which writes to the file /tmp/test till EOF using libaio functions like io_submit, io_getevents.
When I comment the logger initialization code, I am able to write to the full file of size 64MB with buffer size 4k in 0.15 seconds. When I uncomment the logger initialization, the "write" to the file takes about 1.5 seconds.
I have read that g3log is an asynchronous logger and that it is the fastest logger. I am unable to figure out why there is so much latency using g3log in my program.
I tried multiple times running the program without g3log logger initialization, and the writes execute as expected. However when I add the logger initialization, it slows down the writes to file.

Is this a problem with the g3log logger initialization or is it a problem related to libaio or maybe is it a problem related to the filesystem?
I am a total beginner and would love any guidance from the community.

Source: Windows Questions C++

LEAVE A COMMENT