r/cpp • • Oct 07 '26

BqLog 2.6.0: a C++ logging library running on 30M+ devices daily, benchmarked against quill, fmtlog, spdlog and glog (time, CPU and memory)

BqLog is a cross-platform logging library open-sourced by Tencent two years ago. Since then it has gone through two more years of production use and improved a lot in performance, reliability, compatibility and developer experience. With 2.6.0 out, I'd like to introduce it here again.

BqLog is used in a number of Tencent's commercial products, including performance-sensitive mobile games such as Honor of Kings, as well as their server-side logic. It runs on more than 30 million devices every day, across a very wide range of hardware, networks and storage, so its stability and performance have held up in mature commercial products over a long time.

Design goals

Extreme speed is where BqLog starts, not where it stops. It is a mature, industrial-grade component, built for products that ship:

  • Content to play a supporting role. On a modern machine a logging system should take as little of the system as it can. The logging threads and the consumer thread alike should use as little CPU, memory and disk I/O as possible. We do not optimize for benchmark scores; every optimization targets real use.
  • Compression and encryption without giving up speed. The real-time compressed format is about 1/7 the size of text, and writing it is faster and uses less CPU than writing text. Hybrid RSA+AES encryption is supported and costs almost nothing in performance.
  • Compatible everywhere it runs. Windows, macOS, Linux, iOS, Android, HarmonyOS, OpenHarmony and the Unix family; C++, Java/Kotlin, C#, Python, TypeScript/ArkTS and Go sharing one core and even one log object; game engines, mobile toolchains without an STL, strict -Werror builds.
  • Built for the bad day. Logs written before a crash are recovered after it; a full disk neither crashes nor hangs the app; corrupted files are recovered as far as possible; log files can be encrypted to protect privacy.
  • Care about the coding experience. One line to create a log, one line to write; the internals stay as transparent as possible, without complicated configuration; every interface is friendly to IDE code completion; integration tools such as UE Blueprints are provided.

Performance

2.6.0 comes with a new, complete benchmark against quill, fmtlog, spdlog, glog and Log4j2, and every result reports time, CPU and memory together. In short:

  • Throughput: on macOS and Windows, BqLog has the shortest total time at every thread count. The compressed format is roughly 4 to 12 times faster than the fastest of the other libraries and also has the lowest CPU time; the text format is 1.5 to 4.6 times faster.
  • Cost per call on the logging thread: BqLog, quill and fmtlog are in the same tier, with BqLog averaging under 20 ns per call on all three platforms; spdlog is more than an order of magnitude slower.
  • Memory: with fixed-size buffers, BqLog's peak memory is in the lowest tier and barely grows with more threads; with growing buffers it is about half of quill's or less.
  • File size: the compressed format is about 1/7 the size of text.

On Linux only latency is listed for now. On the VMs we tried, throughput was dominated by the VM's disk scheduling and varied by up to 2x between rounds, so we left it out. The test scripts are in the repo, and if you have a bare-metal Linux box we'd be glad to see your numbers.

Methodology, library configurations and full data: https://github.com/Tencent/BqLog/blob/main/docs/BENCHMARK.md

Technical write-ups

If you're curious why BqLog is fast, there are three articles:

  1. High-Performance Realtime Compressed Log Format: https://github.com/Tencent/BqLog/blob/main/docs/Article%201_Why%20is%20BqLog%20so%20fast%20-%20High%20Performance%20Realtime%20Compressed%20Log%20Format.MD
  2. From Ring Buffer to Adaptive Data Bus: https://github.com/Tencent/BqLog/blob/main/docs/Article%202_Why%20is%20BqLog%20so%20fast%20-%20From%20Ring%20Buffer%20to%20Adaptive%20Data%20Bus.MD
  3. Optimizing the Compressed Log Pipeline: https://github.com/Tencent/BqLog/blob/main/docs/Article%203_Why%20is%20BqLog%20so%20fast%20-%20Optimizing%20the%20Compressed%20Log%20Pipeline.MD

Repo: https://github.com/Tencent/BqLog

If you think any library is configured unfairly, let us know and we'll fix it and rerun. Feedback and bug reports are very welcome.

31 Upvotes

28 comments sorted by

63

u/Chaosvex Oct 07 '26

Extreme speed is where BqLog starts, not where it stops.

Sigh.

18

u/Tc14Hd Oct 07 '26

I'm not using it until it starts at lightning-fast speed.

17

u/pdp10gumby Oct 07 '26

Lightning is proprietary. To avoid confusion, let’s use the easy-to-use simplified naming scheme of USB: basic speed, full speed, high speed, and bqlog 3.2 Gen 4x2

4

u/dzidol Oct 07 '26

Is it webscale though?

3

u/rileyrgham Oct 07 '26

Blazing is my goto.

1

u/SignificantNews7620 Oct 07 '26

Fair, that line reads like marketing copy. What I meant: call latency is about the same as quill; what we care about more is total CPU, memory ,file size and reliabilities, which is where the benchmark shows the difference.

30

u/Chaosvex Oct 07 '26

You mean what your LLM meant. Going to be honest, this post made me assume that the whole project is probably LLM produced, so that's an instant pass.

2

u/Fabulous-Meaning-966 Oct 08 '26

No, the LLM is explaining what the LLM meant.

-2

u/SignificantNews7620 Oct 08 '26

Project used on published project over 3 years ago, and open sourced 2 years ago, what LLM can do in 2023? Your judgement is probably faster than bqlog compression format.

12

u/Chaosvex Oct 08 '26

That's just what happens when you make the introduction to a library an AI post. Why do you deserve the benefit of the doubt when you don't respect our time enough to bother writing the post yourself?

7

u/matthieum Oct 07 '26

Built for the bad day. Logs written before a crash are recovered after it; a full disk neither crashes nor hangs the app; corrupted files are recovered as far as possible; log files can be encrypted to protect privacy.

I can feel the pain behind every point made (except the last).

May I guess you discovered them the hard way?

3

u/SignificantNews7620 Oct 08 '26

Almost all the modern log systems use asynchronous log to achive high performance. But the cost is that logs can not be flushed to disk immediately. Many times, when program was crashed(especially delivered client), what we need most is the last logs which can not save to disk when crash happened. This is true pain point in real production, and is a problem we must resolve or the log system is useless when you need it most.

We use the data holding ability of memory mapped files in modern OS. In most cases(Except Power Off or Kernel Crash), the data can be kept by the OS and written to disk later when process was crashed. And we designed a mechanism to validate the data correctness in it to avoid messed data.

According to our project, we found logs can be recovered in over 95% cases.

Bqlog is designed to match different types of projects, sometimes, the client program doesn't want its log to expose its information, so we supplied the encryption. It's based on RSA and AES.

1

u/matthieum Oct 08 '26

I definitely agree that in case of crash, the last few logs are typically the most critical to understand what went on.

In fact, this was the motivation for moving the last logger I wrote from in-process writing (multi-threading) to side-car writing (multi-processing, w/ shared memory for log queue).

1

u/RoyBellingan Oct 10 '26

that was a bliss to read, this is what it means to have a real product for real problem

5

u/delta_p_delta_x Oct 07 '26

No C++20 module interface found. Passing, since both quill and spdlog do.

2

u/UndefinedDefined Oct 11 '26

it's because nobody in industry really cares about this toy feature that burned maybe 100k man days for literally nothing.

1

u/delta_p_delta_x Oct 11 '26

It is not a 'toy feature'. Modules may have been underspecified, but the C/C++ model of dependency management is absolutely horrible. It was a problem that ought to have been solved with C++98.

3

u/UndefinedDefined Oct 12 '26

Dude, modules don't work in practice, did you know? The absence of macros makes it a dead end. Various serialization libraries and frameworks used by industry just need macros, and this means that maybe 90% of C++ codebases can never move to modules.

Damn, I cannot even do `#if THIRD_PARTY_LIBRARY_VERSION >= XXX` in a pure C++ modules project to support multiple versions in a single code-base, or to workaround a bug or something. Modules is a dead-end - a language fragmentation that C++ will never recover from. Pure C++ modules projects will never be used by the industry, so the code-base will always remain #include based with additional files to "support modules".

-2

u/SignificantNews7620 Oct 07 '26

Damn, we totally forgot about that. Too busy keeping it working on all the old projects out there. Noted for the next release.

1

u/usefulcat Oct 08 '26

The benchmarks seems focused on throughput rather than call site latency.

For my use case, I care a lot more about call site latency than throughput, so I would be interested to know how that compares. I currently use Quill.

2

u/SignificantNews7620 Oct 09 '26

https://github.com/Tencent/BqLog/blob/main/docs/BENCHMARK.md#3-latency-on-the-logging-thread, Here is the call site latency benchmark, it's on par with quill and fmtlog

1

u/SlowPokeInTexas Oct 07 '26

At a cursory glance, one concern I might have with the compression is having the log output be a different format than what was output in the code. Many times when I've had to diagnose things, all I had was log files and some code, and the process would work backwards from where the investigated event occurred and attempt to find that log string in the code.

4

u/SignificantNews7620 Oct 07 '26

Not sure I fully understand your concern. The compressed log can't be read directly; its advantages are small size and high performance. When you need to read it, you can decode it with the decoder tool in the repo. The result is a complete text log, byte-for-byte identical to what the text appender writes.

e.g. BqLog_LogDecoder file.logcompr -o out.txt

Decoder docs: https://github.com/Tencent/BqLog/blob/main/docs/API_REFERENCE.md#10-decode-binary-log-files

1

u/Adequat91 Oct 09 '26

On paper, all this seems very impressive. Congratulations. Does your library significantly increase compilation time, especially because of its use of templates?

0

u/[deleted] Oct 07 '26

[deleted] — view deleted comment

2

u/SignificantNews7620 Oct 08 '26

Got it, thanks.