Skip to content

Instantly share code, notes, and snippets.

@feuGeneA
Last active March 20, 2022 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feuGeneA/9eabe0e2d2441d5cd50916d02584a3e5 to your computer and use it in GitHub Desktop.
Save feuGeneA/9eabe0e2d2441d5cd50916d02584a3e5 to your computer and use it in GitHub Desktop.

Is monerod wasting time in handle_incoming_txs during initial node synchronization?

I wondered if there might be some way to speed up the initial node synchronization, so I profiled it with perf. I discovered that the cryptonote_protocol_handler function is reportedly spending 58% of its time in cryptonote::core::handle_incoming_txs, and only 40% of its time in cryptonote::core::handle_incoming_block. I'm still new to Monero, but shouldn't a still-synchronizing node be ignoring incoming transactions until it is fully synchronized?

(An explanation of those 58% and 40% numbers: See in the perf report below the line 43.77% cryptonote::t_cryptonote_protocol_handler, indicating that monerod spent 43.77% of its time in that function. Then see the subsequent two lines, 25.47% cryptonote::core::handle_incoming_txs and 17.65% cryptonote::core::handle_incoming_block. 24.47 is 58% of 43.77, and 17.65 is 40% of 43.77.)

Code in use

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

	both modified:   README.md

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   CMakeLists.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	TODO.md
	external/unbound/
	perf.data
	perf.data.old

no changes added to commit (use "git add" and/or "git commit -a")
$ git show HEAD
commit d562deaaa950979b7a31a441a8f02a00013e26d6 (HEAD -> master, origin/master, origin/HEAD)
Merge: 27f1d4354 b8beac3ec
Author: luigi1111 <luigi1111w@gmail.com>
Date:   Wed Mar 2 18:54:06 2022 -0500

    Merge pull request #8161
    
    b8beac3 Fix typos in docs (Robert Theis)
$ git diff CMakeLists.txt
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e21fbb65b..27d645798 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -338,7 +338,7 @@ endif()
 if(WIN32 OR ARM OR PPC64LE OR PPC64 OR PPC)
   set(OPT_FLAGS_RELEASE "-O2")
 else()
-  set(OPT_FLAGS_RELEASE "-Ofast")
+  set(OPT_FLAGS_RELEASE "-Ofast -fno-omit-frame-pointer")
 endif()
 
 # BUILD_TAG is used to select the build type to check for a new version

monerod output

$ perf record -g build/Linux/master/release/bin/monerod 
Lowering default frequency rate to 1250.
Please consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
2022-03-20 22:23:49.712	I Monero 'Oxygen Orion' (v0.17.0.0-d562deaaa)
2022-03-20 22:23:49.712	I Initializing cryptonote protocol...
2022-03-20 22:23:49.712	I Cryptonote protocol initialized OK
2022-03-20 22:23:49.712	I Initializing core...
2022-03-20 22:23:49.713	I Loading blockchain from folder /home/gene/.bitmonero/lmdb ...
2022-03-20 22:23:50.646	I Loading checkpoints
2022-03-20 22:23:50.646	I Core initialized OK
2022-03-20 22:23:50.646	I Initializing p2p server...
2022-03-20 22:23:50.653	I p2p server initialized OK
2022-03-20 22:23:50.653	I Initializing core RPC server...
2022-03-20 22:23:50.653	I Binding on 127.0.0.1 (IPv4):18081
2022-03-20 22:23:50.653	I core RPC server initialized OK on port: 18081
2022-03-20 22:23:50.654	I Starting core RPC server...
2022-03-20 22:23:50.654	I core RPC server started ok
2022-03-20 22:23:50.655	I Starting p2p net loop...
2022-03-20 22:23:51.656	I 
2022-03-20 22:23:51.656	I **********************************************************************
2022-03-20 22:23:51.656	I The daemon will start synchronizing with the network. This may take a long time to complete.
2022-03-20 22:23:51.656	I 
2022-03-20 22:23:51.656	I You can set the level of process detailization through "set_log <level|categories>" command,
2022-03-20 22:23:51.656	I where <level> is between 0 (no details) and 4 (very verbose), or custom category based levels (eg, *:WARNING).
2022-03-20 22:23:51.656	I 
2022-03-20 22:23:51.656	I Use the "help" command to see the list of available commands.
2022-03-20 22:23:51.656	I Use "help <command>" to see a command's documentation.
2022-03-20 22:23:51.656	I **********************************************************************
[1647815031] libunbound[30291:0] error: local-data in redirect zone must reside at top of zone, not at 0xproject.localhost A 127.0.0.1
2022-03-20 22:23:53.241	I [92.205.62.235:18080 OUT] Sync data returned a new top block candidate: 2309327 -> 2584050 [Your node is 274723 blocks (1.0 years) behind] 
2022-03-20 22:23:53.241	I SYNCHRONIZATION started
2022-03-20 22:24:05.491	I Version 0.17.3.0 of monero for source is available: https://downloads.getmonero.org/source/monero-source-v0.17.3.0.tar.bz2, SHA256 hash 2ee1b5f857c4ba14f13fcf4ebcccd1635ba09988cfa32de7a92a9c6712aacf29
2022-03-20 22:24:15.185	I Synced 2309347/2584050 (89%, 274703 left)
2022-03-20 22:24:36.452	I Synced 2309367/2584050 (89%, 274683 left)
2022-03-20 22:24:59.858	I Synced 2309387/2584050 (89%, 274663 left)
2022-03-20 22:25:05.743	I Synced 2309407/2584050 (89%, 274643 left)
2022-03-20 22:25:26.572	I Synced 2309427/2584050 (89%, 274623 left)
2022-03-20 22:25:48.838	I Synced 2309447/2584050 (89%, 274603 left)
2022-03-20 22:25:53.896	I Synced 2309467/2584050 (89%, 274583 left)
2022-03-20 22:26:18.888	I Synced 2309487/2584050 (89%, 274563 left, 0% of total synced, estimated 3.0 days left)
2022-03-20 22:26:24.945	I Synced 2309507/2584050 (89%, 274543 left)
2022-03-20 22:26:43.426	I Synced 2309527/2584050 (89%, 274523 left)
2022-03-20 22:26:54.255	I Synced 2309547/2584050 (89%, 274503 left)
2022-03-20 22:27:03.516	I Synced 2309567/2584050 (89%, 274483 left)
2022-03-20 22:27:15.355	I Synced 2309587/2584050 (89%, 274463 left)
2022-03-20 22:27:22.408	I Synced 2309607/2584050 (89%, 274443 left)
2022-03-20 22:27:28.985	I Synced 2309627/2584050 (89%, 274423 left)
2022-03-20 22:27:41.598	I Synced 2309647/2584050 (89%, 274403 left)
2022-03-20 22:27:50.661	I Synced 2309667/2584050 (89%, 274383 left)
2022-03-20 22:27:59.277	I Synced 2309687/2584051 (89%, 274364 left)
2022-03-20 22:28:22.688	I Synced 2309707/2584051 (89%, 274344 left, 0% of total synced, estimated 2.3 days left)
[ perf record: Woken up 496 times to write data ]
2022-03-20 22:28:46.226	I p2p net loop stopped
2022-03-20 22:28:46.310	I Stopping core RPC server...
2022-03-20 22:28:46.311	I Node stopped.
2022-03-20 22:28:46.311	I Deinitializing core RPC server...
2022-03-20 22:28:46.312	I Deinitializing p2p...
2022-03-20 22:28:46.339	I Deinitializing core...
2022-03-20 22:28:46.563	I Stopping cryptonote protocol...
2022-03-20 22:28:46.564	I Cryptonote protocol stopped successfully
[ perf record: Captured and wrote 124.869 MB perf.data (635922 samples) ]

perf report

$ perf report -g 'graph,0.5,caller'
Samples: 635K of event 'cycles:ppp', Event count (approx.): 965582914136                                                                                                                                                                                        
  Children      Self  Command  Shared Object              Symbol                                                                                                                                                                                                
-   96.48%     0.00%  monerod  libboost_thread.so.1.67.0  [.] 0x00007fb88fbe3615                                                                                                                                                                               ◆
   - 0x7fb88fbe3615                                                                                                                                                                                                                                            ▒
      + 51.94% tools::threadpool::run                                                                                                                                                                                                                          ▒
      - 44.51% epee::net_utils::boosted_tcp_server<epee::levin::async_protocol_handler<nodetool::p2p_connection_context_t<cryptonote::cryptonote_connection_context> > >::worker_thread                                                                        ▒
         - 44.50% boost::asio::detail::scheduler::run                                                                                                                                                                                                          ▒
            - 44.49% boost::asio::detail::scheduler::do_run_one                                                                                                                                                                                                ▒
               - 44.23% boost::asio::detail::epoll_reactor::descriptor_state::do_complete                                                                                                                                                                      ▒
                  - 44.22% boost::asio::detail::reactive_socket_recv_op<boost::asio::mutable_buffers_1, boost::asio::detail::wrapped_handler<boost::asio::io_context::strand, boost::_bi::bind_t<void, boost::_mfi::mf2<void, epee::net_utils::connection<epee:▒
                     - 44.22% boost::asio::detail::strand_service::dispatch<boost::asio::detail::rewrapped_handler<boost::asio::detail::binder2<boost::asio::detail::wrapped_handler<boost::asio::io_context::strand, boost::_bi::bind_t<void, boost::_mfi::mf2▒
                        - 44.22% boost::asio::detail::wrapped_handler<boost::asio::io_context::strand, boost::_bi::bind_t<void, boost::_mfi::mf2<void, epee::net_utils::connection<epee::levin::async_protocol_handler<nodetool::p2p_connection_context_t<crypt▒
                           - 44.22% boost::asio::detail::strand_service::dispatch<boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, epee::net_utils::connection<epee::levin::async_protocol_handler<nodetool::p2p_connection_context▒
                              - 44.21% epee::net_utils::connection<epee::levin::async_protocol_handler<nodetool::p2p_connection_context_t<cryptonote::cryptonote_connection_context> > >::handle_read                                                          ▒
                                 - 44.15% epee::levin::async_protocol_handler<nodetool::p2p_connection_context_t<cryptonote::cryptonote_connection_context> >::handle_recv                                                                                     ▒
                                    - 44.12% nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >::notify                                                                                                                       ▒
                                       - 44.12% nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >::handle_invoke_map<nodetool::p2p_connection_context_t<cryptonote::cryptonote_connection_context> >                         ▒
                                          - 43.81% cryptonote::t_cryptonote_protocol_handler<cryptonote::core>::handle_response_get_objects                                                                                                                    ▒
                                             - 43.77% cryptonote::t_cryptonote_protocol_handler<cryptonote::core>::try_add_next_blocks                                                                                                                         ▒
                                                + 25.47% cryptonote::core::handle_incoming_txs                                                                                                                                                                 ▒
                                                + 17.65% cryptonote::core::handle_incoming_block                                                                                                                                                               ▒
                                                + 0.59% cryptonote::core::prepare_handle_incoming_blocks                                                                                                                                                       ▒
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment