Skip to content

Instantly share code, notes, and snippets.

@uttampawar
Created February 15, 2023 22:37
Show Gist options
  • Save uttampawar/2fb6d561cf684df68fd188fc3aa29e53 to your computer and use it in GitHub Desktop.
Save uttampawar/2fb6d561cf684df68fd188fc3aa29e53 to your computer and use it in GitHub Desktop.
40 - mongodb threads perf report
Children Self Command Shared Object Symbol
+ 12.26% 0.00% swapper [kernel.vmlinux] [k] 0xffffffffb46000d4
+ 12.24% 0.00% swapper [kernel.vmlinux] [k] start_secondary
+ 12.24% 0.04% swapper [kernel.vmlinux] [k] cpu_startup_entry
+ 12.12% 0.34% swapper [kernel.vmlinux] [k] do_idle
+ 7.63% 0.10% swapper [kernel.vmlinux] [k] call_cpuidle
+ 7.53% 0.04% swapper [kernel.vmlinux] [k] cpuidle_enter
+ 7.41% 0.16% swapper [kernel.vmlinux] [k] cpuidle_enter_state
+ 6.80% 0.12% swapper [kernel.vmlinux] [k] acpi_idle_enter
+ 6.67% 6.67% swapper [kernel.vmlinux] [k] acpi_processor_ffh_cstate_enter
+ 6.67% 0.01% swapper [kernel.vmlinux] [k] acpi_idle_do_entry
+ 1.75% 0.04% swapper [kernel.vmlinux] [k] schedule_idle
+ 1.65% 0.00% conn41 libpthread-2.31.so [.] start_thread
+ 1.65% 0.00% conn41 mongod [.] mongo::(anonymous namespace)::runFunc
+ 1.65% 0.00% conn41 mongod [.] mongo::unique_function<void ()>::makeImpl<mongo::launchServiceWorkerThread(mongo::unique_function<void ()>)::{lambda()#4}>(mongo::launchServiceWorkerThread(mongo::unique_function<void ()>)::{lambda()#4}&&)::SpecificImpl::call
+ 1.65% 0.00% conn41 mongod [.] mongo::unique_function<void ()>::makeImpl<mongo::transport::ServiceExecutorSynchronous::scheduleTask(mongo::unique_function<void ()>, mongo::transport::ServiceExecutor::ScheduleFlags)::{lambda()#2}>(mongo::transport::ServiceExec
+ 1.65% 0.00% conn41 mongod [.] mongo::unique_function<void ()>::makeImpl<mongo::transport::ServiceExecutor::schedule(mongo::unique_function<void (mongo::Status)>)::{lambda()#1}>(mongo::transport::ServiceExecutor::schedule(mongo::unique_function<void (mongo::S
+ 1.65% 0.00% conn41 mongod [.] mongo::unique_function<void (mongo::Status)>::makeImpl<mongo::transport::ServiceExecutorSynchronous::runOnDataAvailable(std::shared_ptr<mongo::transport::Session> const&, mongo::unique_function<void (mongo::Status)>)::{lambda(mo
+ 1.64% 0.00% conn41 mongod [.] mongo::unique_function<void (mongo::Status)>::makeImpl<mongo::transport::ServiceStateMachine::Impl::scheduleNewLoop(mongo::Status)::{lambda(mongo::Status)#1}>(mongo::transport::ServiceStateMachine::Impl::scheduleNewLoop(mongo::S
-----------
Couple of Call graphs for the connections (conn40 and conn41). All threads are showing up in mongo::runQuery() function
- 1.64% 0.00% conn40 mongod [.] mongo::unique_function<void ()>::makeImpl<mongo::transport::ServiceExecutor::schedule(mongo::unique_function<void (mongo::Status)>)::{lambda()#1}>(mongo::transport::ServiceExecutor::schedule(mongo::unique_function<void (mongo::▒
1.64% mongo::unique_function<void ()>::makeImpl<mongo::transport::ServiceExecutor::schedule(mongo::unique_function<void (mongo::Status)>)::{lambda()#1}>(mongo::transport::ServiceExecutor::schedule(mongo::unique_function<void (mongo::Status)>)::{lambda()#1}&&)::SpecificImpl::call ▒
- mongo::unique_function<void (mongo::Status)>::makeImpl<mongo::transport::ServiceExecutorSynchronous::runOnDataAvailable(std::shared_ptr<mongo::transport::Session> const&, mongo::unique_function<void (mongo::Status)>)::{lambda(mongo::Status)#1}>(mongo::transport::ServiceExecutorSynchronous:▒
- 1.64% mongo::unique_function<void (mongo::Status)>::makeImpl<mongo::transport::ServiceStateMachine::Impl::scheduleNewLoop(mongo::Status)::{lambda(mongo::Status)#1}>(mongo::transport::ServiceStateMachine::Impl::scheduleNewLoop(mongo::Status)::{lambda(mongo::Status)#1}&&)::SpecificImpl::c▒
- 1.63% mongo::transport::ServiceStateMachine::Impl::startNewLoop ▒
- 1.15% mongo::future_details::FutureImpl<mongo::future_details::FakeVoid>::then<mongo::transport::ServiceStateMachine::Impl::startNewLoop(mongo::Status const&)::{lambda()#2}>(mongo::transport::ServiceStateMachine::Impl::startNewLoop(mongo::Status const&)::{lambda()#2}&&) &&::{lambd▒
- 1.14% mongo::transport::ServiceStateMachine::Impl::processMessage ▒
- 0.83% mongo::ServiceEntryPointMongod::handleRequest ▒
- 0.82% mongo::ServiceEntryPointCommon::handleRequest ▒
- 0.79% mongo::(anonymous namespace)::SynchronousOpRunner::run ▒
- 0.78% mongo::(anonymous namespace)::QueryOpRunner::runSync ▒
0.71% mongo::runQuery
- 1.64% 0.00% conn41 mongod [.] mongo::unique_function<void (mongo::Status)>::makeImpl<mongo::transport::ServiceStateMachine::Impl::scheduleNewLoop(mongo::Status)::{lambda(mongo::Status)#1}>(mongo::transport::ServiceStateMachine::Impl::scheduleNewLoop(mongo::▒
- 1.64% mongo::unique_function<void (mongo::Status)>::makeImpl<mongo::transport::ServiceStateMachine::Impl::scheduleNewLoop(mongo::Status)::{lambda(mongo::Status)#1}>(mongo::transport::ServiceStateMachine::Impl::scheduleNewLoop(mongo::Status)::{lambda(mongo::Status)#1}&&)::SpecificImpl::call ▒
- 1.63% mongo::transport::ServiceStateMachine::Impl::startNewLoop ▒
- 1.15% mongo::future_details::FutureImpl<mongo::future_details::FakeVoid>::then<mongo::transport::ServiceStateMachine::Impl::startNewLoop(mongo::Status const&)::{lambda()#2}>(mongo::transport::ServiceStateMachine::Impl::startNewLoop(mongo::Status const&)::{lambda()#2}&&) &&::{lambda(mong▒
- 1.14% mongo::transport::ServiceStateMachine::Impl::processMessage ▒
- 0.83% mongo::ServiceEntryPointMongod::handleRequest ▒
- 0.83% mongo::ServiceEntryPointCommon::handleRequest ▒
- 0.79% mongo::(anonymous namespace)::SynchronousOpRunner::run ▒
- 0.79% mongo::(anonymous namespace)::QueryOpRunner::runSync ▒
0.71% mongo::runQuery
---------------------
Annotated mongo:runQuery() function
│ // How many results have we obtained from the executor?
│ int numResults = 0;
│ ResourceConsumption::DocumentUnitCounter docUnitsReturned;
│ lea vtable for mongo::ResourceConsumption::DocumentUnitCounter+0x10,%rax
0.02 │ movq $0x0,-0x818(%rbp)
0.13 │ mov %rax,-0x820(%rbp)
│ _ZN5mongo7BSONObjC4Ev():
│ _objdata = kEmptyObjectPrototype;
0.06 │ lea mongo::BSONObj::kEmptyObjectPrototype,%rax
│ mov %rax,-0x860(%rbp)
│ _ZNSt11atomic_flag12test_and_setESt12memory_order():
│ return __atomic_test_and_set (&_M_i, int(__m));
│ lea 0x58(%rbx),%rdx
0.06 │ mov $0x1,%eax
│ _ZN5mongo8runQueryEPNS_16OperationContextERNS_12QueryMessageERKNS_15NamespaceStringERNS_7MessageE():
│ movq $0x0,-0x810(%rbp)
│ _ZN5boost13intrusive_ptrIN5mongo12SharedBuffer6HolderEEC4Ev():
│ BOOST_CONSTEXPR intrusive_ptr() BOOST_SP_NOEXCEPT : px( 0 )
0.06 │ movq $0x0,-0x858(%rbp)
│ _ZNSt11atomic_flag12test_and_setESt12memory_order():
5.62 │ xchg %al,(%rdx)
│ _ZN5mongo8SpinLock4lockEv():
│ void unlock() override {
│ _locked.clear(std::memory_order_release);
│ }
At this point, it looks like some kind of atomic operation. Actually it looks like a constructor function initializing a variable.
I think this belongs to a private class member "_refCount". But I'm not very confident if this is correct code. Any way here is the class.
125 class Holder {
126 public:
127 explicit Holder(unsigned initial, size_t capacity)
128 : _refCount(initial), _capacity(capacity) {
129 invariant(capacity == _capacity);
130 }
131
132 // these are called automatically by boost::intrusive_ptr
133 friend void intrusive_ptr_add_ref(Holder* h) {
134 h->_refCount.fetchAndAdd(1);
135 }
136
137 friend void intrusive_ptr_release(Holder* h) {
138 if (h->_refCount.subtractAndFetch(1) == 0) {
139 // We placement new'ed a Holder in takeOwnership above,
140 // so we must destroy the object here.
141 h->~Holder();
142 free(h);
143 }
144 }
145
146 char* data() {
147 return reinterpret_cast<char*>(this + 1);
148 }
149
150 const char* data() const {
151 return reinterpret_cast<const char*>(this + 1);
152 }
153
154 bool isShared() const {
155 return _refCount.load() > 1;
156 }
157
158 AtomicWord<unsigned> _refCount;
159 uint32_t _capacity;
160 };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment