RafaGago / mini-async-log-c

Mini async log C port. Now with C++ wrappers.
BSD 3-Clause "New" or "Revised" License
71 stars 7 forks source link

Production Ready? #2

Closed andrewkcorcoran closed 4 years ago

andrewkcorcoran commented 4 years ago

Is this library production ready or should the original mal be used instead? Which branch is best to be used? It looks like there's no ci builds etc for this.

RafaGago commented 4 years ago

I'm planning to merge the cpp11-dev branch as soon as I get everything to compile on Windows. It doesn't bring a lot of changes for C11 users, but for C++ it's better.

What's the intended usage? platforms, language, type of application, etc.

andrewkcorcoran commented 4 years ago

Looking to integrate logging on Linux with C++17 in an application with low latency call site requirements but not particularly large throughput. I was also looking at PlatformLab/NanoLog which looks very interesting. I had no luck building your benchmark repo to compare though, it looks like it references repos external to GitHub which is probably the cause of the failures.

On Thu, 19 Dec 2019, 6:52 pm RafaGago, notifications@github.com wrote:

I'm planning to merge the cpp11-dev branch as soon as I get everything to compile on Windows. It doesn't bring a lot of changes for C11 users, but for C++ it's better.

What's the intended usage? platforms, language, type of application, etc.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RafaGago/mini-async-log-c/issues/2?email_source=notifications&email_token=AL5LS3GPMERSJXQVEECQEFTQZODDZA5CNFSM4J5FPUN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHJ24OQ#issuecomment-567520826, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL5LS3BGJRXG45RA7HXRR5DQZODDZANCNFSM4J5FPUNQ .

RafaGago commented 4 years ago

The benchmark project is definitely referencing external projects, as some of the loggers benchmarked aren't hosted on GitHub.

On Linux you should be able to compile the benchmarks with.

mkdir build && cd build && cmake .. -DNANOLOG=on -DMALC=on && make -j

If this doesn't compile then it's broken and I'd like to know how to be able to fix it.

From the synthetic testing I have done on my obsolete AMD Phenon 965 x4 on Ubuntu Server 18.04 using the "performance" cpu governor with a peak of 100000 mesages, malc using thread local storage is 1,5-2x faster than nanolog on the single-threaded case, they get more or less equal with 8 threads, and after that nanolog wins, as it scales almost linearly with the number of threads, while malc degrades.

On this same test, when passing 8MB as a tls buffer size to malc (which is enough to handle the 100000 messages peak), malc peak memory consumption was 13MB . nanolog 32MB.

As the benchmark is just launching threads continuously logging in a loop, one has to interpret its significance when running in an application. I guess that a textual logger is almost always uncontended.

If you own the threads that are going to log, you can enable a buffer on thread local storage on malc. This makes logging wait-free as long as there is space on that thread local storage buffer. Then if you don't want to drop messages on a full buffer, as fallback you can use the heap, a shared bounded buffer or both. On nanolog there are cases that take mutexes or initialize data the first time a logging site is hit.

I'm completely biased, so it's hard for me to tell what you should be using. Consider that this is a textual logger and nanolog is binary.

For C++ usage under Linux I'd take the cpp11-dev branch, it's not going to change much more before it's merged to master.

andrewkcorcoran commented 4 years ago

I finally got around to try and testing this a bit more throughly.

[120/121] Compiling C++ object 'subprojects/base_library/b3ec909@@bl-nonblock-mpmc-bpm-relacy@exe/test_src_bl_mpmc_bpm_relacy_mpmc_bpm_relacy.cpp.o'.

FAILED: subprojects/base_library/b3ec909@@bl-nonblock-mpmc-bpm-relacy@exe/test_src_bl_mpmc_bpm_relacy_mpmc_bpm_relacy.cpp.o

c++ -Isubprojects/base_library/b3ec909@@bl-nonblock-mpmc-bpm-relacy@exe -Isubprojects/base_library -I../subprojects/base_library -I../subprojects/base_library/include -I../subprojects/base_library/src -I../subprojects/base_library/test/src -I../subprojects/base_library/dep/install/include -I../subprojects/base_library/gitmodules/relacy -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++11 -g -pthread -MD -MQ 'subprojects/base_library/b3ec909@@bl-nonblock-mpmc-bpm-relacy@exe/test_src_bl_mpmc_bpm_relacy_mpmc_bpm_relacy.cpp.o' -MF 'subprojects/base_library/b3ec909@@bl-nonblock-mpmc-bpm-relacy@exe/test_src_bl_mpmc_bpm_relacy_mpmc_bpm_relacy.cpp.o.d' -o 'subprojects/base_library/b3ec909@@bl-nonblock-mpmc-bpm-relacy@exe/test_src_bl_mpmc_bpm_relacy_mpmc_bpm_relacy.cpp.o' -c ../subprojects/base_library/test/src/bl/mpmc_bpm_relacy/mpmc_bpm_relacy.cpp

In file included from /opt/rh/devtoolset-8/root/usr/include/c++/8/map:61,

                 from ../subprojects/base_library/gitmodules/relacy/relacy/pch.hpp:48,

                 from ../subprojects/base_library/gitmodules/relacy/relacy/base.hpp:16,

                 from ../subprojects/base_library/gitmodules/relacy/relacy/relacy.hpp:17,

                 from ../subprojects/base_library/test/src/bl/mpmc_bpm_relacy/mpmc_bpm_relacy.cpp:304:

/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/stl_map.h: In instantiation of ‘class std::map<void*, long unsigned int, std::less<void*>, rl::raw_allocator<std::pair<void*, long unsigned int> > >’:

../subprojects/base_library/gitmodules/relacy/relacy/memory.hpp:178:30:   required from here

/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/stl_map.h:122:21: error: static assertion failed: std::map must have the same value_type as its allocator

       static_assert(is_same<typename _Alloc::value_type, value_type>::value,

                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/stl_map.h: In instantiation of ‘class std::map<const void*, long unsigned int, std::less<const void*>, rl::raw_allocator<std::pair<const void*, long unsigned int> > >’:

../subprojects/base_library/gitmodules/relacy/relacy/context_addr_hash.hpp:55:45:   required from here

/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/stl_map.h:122:21: error: static assertion failed: std::map must have the same value_type as its allocator

In file included from ../subprojects/base_library/gitmodules/relacy/relacy/base.hpp:17,

                 from ../subprojects/base_library/gitmodules/relacy/relacy/relacy.hpp:17,

                 from ../subprojects/base_library/test/src/bl/mpmc_bpm_relacy/mpmc_bpm_relacy.cpp:304:

../subprojects/base_library/gitmodules/relacy/relacy/platform.hpp:247:30: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]

#   define RL_THROW_SPEC(ex) throw(ex)

                              ^~~~~

../subprojects/base_library/gitmodules/relacy/relacy/context.hpp:1256:41: note: in expansion of macro ‘RL_THROW_SPEC’

inline void* operator new (size_t size) RL_THROW_SPEC(std::bad_alloc)

                                         ^~~~~~~~~~~~~

../subprojects/base_library/gitmodules/relacy/relacy/platform.hpp:247:30: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]

#   define RL_THROW_SPEC(ex) throw(ex)

                              ^~~~~

../subprojects/base_library/gitmodules/relacy/relacy/context.hpp:1264:44: note: in expansion of macro ‘RL_THROW_SPEC’

inline void* operator new [] (size_t size) RL_THROW_SPEC(std::bad_alloc)
RafaGago commented 4 years ago

I was moving some things from malc to the submodule under pressure (family) and I got it wrong. I was tired. I will be fixing this soon.

RafaGago commented 4 years ago

I fixed the submodule.

It seems that the error is related to the relacy race detector. My source the only thing that does is to #include <relacy/relacy.hpp> Unfortunately I can't reproduce.

The file failing is a test that I did for checking the correctness of a queue, it is totally unnecesary for malc, so it is safe to comment out the 'bl-nonblock-mpmc-bpm-relacy' executable on the "meson.build" file if you want to keep things going.

There is the "bare" meson option that I added that just compiles the libraries and skips all the tests. too.

If I remember correctly, I bumped "relacy" recently to see if I could get rid of those throw warnings.

I'm on gcc 7.4 myself.

andrewkcorcoran commented 4 years ago

That's great thanks, both branches compile and tests pass once the relacy executable is disabled.

RafaGago commented 4 years ago

7f27e6daf8ec9b5ae27b185fe2abf49775506c77 Fixes the relacy issue. I was going to submit a fix for relacy when I realized that it was already submitted upstream.

RafaGago commented 4 years ago

The C++11 branch is merged. Closing this.