Giter Club home page Giter Club logo

Comments (8)

Lastique avatar Lastique commented on September 2, 2024 1

BTW, see these:

https://stackoverflow.com/a/15008330/4636534
https://stackoverflow.com/a/12909560/4636534

So I seriously doubt GetCurrentThreadId is the problem.

from log.

Lastique avatar Lastique commented on September 2, 2024

GetCurrentThreadId could be called from anywhere, including the standard library. Is there a problem with it being called? Did you collect any backtraces from where it is called?

from log.

UMU618 avatar UMU618 commented on September 2, 2024

Refer to folly, GetCurrentThreadId is slow.
https://github.com/facebook/folly/blob/2d9c0a3c720238ae2ef1337348b6a72778024961/folly/system/ThreadId.cpp#L41

from log.

UMU618 avatar UMU618 commented on September 2, 2024

It's called from a boost::log::aux::exclusive_lock_guard in function feed_record file boost\log\sinks\basic_sink_frontend.hpp

// Feed the record
BOOST_LOG_EXPR_IF_MT(boost::log::aux::exclusive_lock_guard< BackendMutexT > lock(backend_mutex);)
backend.consume(rec, context->m_FormattedRecord);

from log.

UMU618 avatar UMU618 commented on September 2, 2024

I believe it originates from Boost.Thread.

boost::recursive_mutex *backend_mutex;

image

from log.

Lastique avatar Lastique commented on September 2, 2024

Refer to folly, GetCurrentThreadId is slow.

That link does not indicate that GetCurrentThreadId is slow. It does cache its value in one code path, but it also provides getCurrentThreadID that uses GetCurrentThreadId on Windows that doesn't cache its value.

Do you have any profiling data that shows that GetCurrentThreadId is indeed a problem? If so, I would like to see the benchmark.

I believe it originates from Boost.Thread.

You should probably report it there, along with the benchmark, and, if possible, your suggestions on optimizing it.

from log.

UMU618 avatar UMU618 commented on September 2, 2024

The cached impl from folly is 2x faster then the API in release configuration.

from log.

Lastique avatar Lastique commented on September 2, 2024

Here's a benchmark for different types of mutexes:

test_mutex.cpp.txt

Compile with MSVC 14.3:

cl /O2 /EHsc /I . /DNDEBUG /MD test_mutex.cpp /link /LIBPATH:stage\lib

On Windows 10, on my system it produces these results:

boost::recursive_mutex: 1000000 iterations, 1 threads, 17603 us, 5.68085e+07 iterations per second
boost::recursive_mutex: 2000000 iterations, 2 threads, 58395 us, 3.42495e+07 iterations per second
boost::recursive_mutex: 4000000 iterations, 4 threads, 115647 us, 3.4588e+07 iterations per second
boost::recursive_mutex: 8000000 iterations, 8 threads, 243507 us, 3.28533e+07 iterations per second
std::recursive_mutex: 1000000 iterations, 1 threads, 14036 us, 7.12454e+07 iterations per second
std::recursive_mutex: 2000000 iterations, 2 threads, 25280 us, 7.91139e+07 iterations per second
std::recursive_mutex: 4000000 iterations, 4 threads, 57344 us, 6.97545e+07 iterations per second
std::recursive_mutex: 8000000 iterations, 8 threads, 154457 us, 5.17944e+07 iterations per second
critical_section(0): 1000000 iterations, 1 threads, 11456 us, 8.72905e+07 iterations per second
critical_section(0): 2000000 iterations, 2 threads, 91314 us, 2.19024e+07 iterations per second
critical_section(0): 4000000 iterations, 4 threads, 307022 us, 1.30284e+07 iterations per second
critical_section(0): 8000000 iterations, 8 threads, 1001230 us, 7.99017e+06 iterations per second
critical_section(10): 1000000 iterations, 1 threads, 11411 us, 8.76347e+07 iterations per second
critical_section(10): 2000000 iterations, 2 threads, 65629 us, 3.04743e+07 iterations per second
critical_section(10): 4000000 iterations, 4 threads, 156023 us, 2.56372e+07 iterations per second
critical_section(10): 8000000 iterations, 8 threads, 473790 us, 1.68851e+07 iterations per second
critical_section(100): 1000000 iterations, 1 threads, 11058 us, 9.04323e+07 iterations per second
critical_section(100): 2000000 iterations, 2 threads, 104436 us, 1.91505e+07 iterations per second
critical_section(100): 4000000 iterations, 4 threads, 247020 us, 1.6193e+07 iterations per second
critical_section(100): 8000000 iterations, 8 threads, 877609 us, 9.11568e+06 iterations per second
critical_section(1000): 1000000 iterations, 1 threads, 11201 us, 8.92777e+07 iterations per second
critical_section(1000): 2000000 iterations, 2 threads, 93654 us, 2.13552e+07 iterations per second
critical_section(1000): 4000000 iterations, 4 threads, 307327 us, 1.30155e+07 iterations per second
critical_section(1000): 8000000 iterations, 8 threads, 1252495 us, 6.38725e+06 iterations per second

So, boost::recursive_mutex is a close second after std::recursive_mutex. Note that std::recursive_mutex also uses GetCurrentThreadId internally.

Considering that the test exhibits much stronger contention than what is expected in Boost.Log, and literally tests mutex performance with next to no other useful code, I expect all of these mutex types to perform roughly the same in the real application. Still, since C++11 is now the minimum, I might switch to std::recursive_mutex in the future.

I'm not sure what your problem is with GetCurrentThreadId, but I don't see it as a performance problem. And I don't see what I could do about it in the context of Boost.Log anyway. If you can suggest a more optimal implementation of boost::recursive_mutex, please file a PR for Boost.Thread.

from log.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.