Comments (8)
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.
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.
Refer to folly, GetCurrentThreadId
is slow.
https://github.com/facebook/folly/blob/2d9c0a3c720238ae2ef1337348b6a72778024961/folly/system/ThreadId.cpp#L41
from log.
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.
I believe it originates from Boost.Thread.
boost::recursive_mutex *backend_mutex;
from log.
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.
The cached impl from folly is 2x faster then the API in release configuration.
from log.
Here's a benchmark for different types of mutexes:
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)
- Boost.Log rotation may throw boost::filesystem::filesystem_error HOT 10
- How to add timezone info for log entries and log filename HOT 3
- Formatting TimeStamp HOT 1
- Boost 1.82, boost\Log\trivial unresolved external symbol error if included after curl HOT 3
- Log Formatting [Conan 2.x, C++20, Boost 1.83] HOT 2
- 1.82.0 compiled for XP uses AcquireSRWLockExclusive HOT 2
- How to append log to same log file after program restarts? HOT 1
- CMake integration for Xcode universal 2 builds HOT 1
- boost日志在动态库里被使用,再次在主程序中使用会崩溃 HOT 1
- Boost stopped printing logs after changing the system time HOT 4
- Redundent call to boost_install() HOT 1
- An infinite loop occurs when boost writes to the log file (Debug Mode, Medium size file) HOT 1
- Consider switching dependency from MPL to MP11 HOT 2
- Please consider improving the documentation and examples HOT 1
- Linking failure after upgrading boost to 1.82 from 1.69 HOT 2
- advanced instruction sets HOT 1
- About Scope %f HOT 1
- boost/1.85.0 compile issues with msm::front::state_machine_def on llvm/clang++ 18.1.5 with std=c++20 HOT 4
- Crash when FreeLibrary a dll uses Boost.Log HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from log.