Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-32537

Set thread names for MariaDB Server threads

Details

    Description

      Multi-threaded Linux programs (like Firefox or MySQL since 8.0.27 or so) usually set a name for each thread. This name will appear in the output of top and other utilities and would help to answer questions like "What thread uses most of CPU" etc.

      Consider this example of MySQL 8.0.29:

      openxs@ao756:~/dbs/8.0$ for task in $(ls /proc/$(pidof mysqld)/task/); do name=$(cat /proc/$(pidof mysqld)/task/${task}/comm); echo "TASK: ${task} (${name})"; done
      TASK: 567049 (mysqld)
      TASK: 567079 (ib_io_ibuf)
      TASK: 567080 (ib_io_log)
      TASK: 567081 (ib_io_rd-1)
      TASK: 567082 (ib_io_rd-2)
      TASK: 567083 (ib_io_rd-3)
      TASK: 567084 (ib_io_rd-4)
      TASK: 567085 (ib_io_wr-1)
      TASK: 567086 (ib_io_wr-2)
      TASK: 567087 (ib_io_wr-3)
      TASK: 567088 (ib_io_wr-4)
      TASK: 567089 (ib_pg_flush_co)
      TASK: 567096 (ib_log_checkpt)
      TASK: 567097 (ib_log_fl_notif)
      TASK: 567098 (ib_log_flush)
      TASK: 567099 (ib_log_wr_notif)
      TASK: 567100 (ib_log_writer)
      TASK: 567114 (ib_srv_lock_to)
      TASK: 567115 (ib_srv_err_mon)
      TASK: 567116 (ib_srv_mon)
      TASK: 567117 (ib_buf_resize)
      TASK: 567118 (ib_src_main)
      TASK: 567119 (ib_dict_stats)
      TASK: 567120 (ib_fts_opt)
      TASK: 567122 (xpl_worker-1)
      TASK: 567123 (xpl_worker-2)
      TASK: 567124 (xpl_accept-1)
      TASK: 567893 (ib_buf_dump)
      TASK: 567894 (ib_clone_gtid)
      TASK: 567895 (ib_srv_purge)
      TASK: 567896 (ib_srv_wkr-1)
      TASK: 567897 (ib_srv_wkr-2)
      TASK: 567898 (ib_srv_wkr-3)
      TASK: 567899 (evt_sched)
      TASK: 567900 (sig_handler)
      TASK: 567902 (xpl_accept-3)
      TASK: 567903 (gtid_zip)
      

      For MariaDB (10.6 here for example) we get:

      openxs@ao756:~/dbs/maria10.6$ for task in $(ls /proc/$(pidof mariadbd)/task/); do name=$(cat /proc/$(pidof mariadbd)/task/${task}/comm); echo "TASK: ${task} (${name})"; done
      TASK: 568093 (mariadbd)
      TASK: 568095 (mariadbd)
      TASK: 568096 (mariadbd)
      TASK: 568097 (mariadbd)
      TASK: 568098 (mariadbd)
      TASK: 568099 (mariadbd)
      TASK: 568104 (mariadbd)
      TASK: 568105 (mariadbd)
      openxs@ao756:~/dbs/maria10.6$
      

      See also https://bugs.mysql.com/bug.php?id=70858

      It makes sense to use the same thread name as used in Performance Schema.

      Attachments

        Activity

          wlad Vladislav Vaintroub added a comment - - edited

          About Windows threads that do not have "correct" names - those are the threads that did not run our code yet, or maybe never will.
          When I just start the mysqld.exe, and set breakpoint in main(), there are already 2 threads created by default process threadpool, probably when loading shared libraries.

          There is some discussion about it in https://stackoverflow.com/questions/34822072/why-does-windows-10-start-extra-threads-in-my-program

          wlad Vladislav Vaintroub added a comment - - edited About Windows threads that do not have "correct" names - those are the threads that did not run our code yet, or maybe never will. When I just start the mysqld.exe, and set breakpoint in main(), there are already 2 threads created by default process threadpool, probably when loading shared libraries. There is some discussion about it in https://stackoverflow.com/questions/34822072/why-does-windows-10-start-extra-threads-in-my-program

          About "one_connection" as thread name - unlike in MySQL, thread names are synchronized with performance schema, so it is just the result of this.

          wlad Vladislav Vaintroub added a comment - About "one_connection" as thread name - unlike in MySQL, thread names are synchronized with performance schema, so it is just the result of this.

          wlad serg maybe later we can add a build-time option to add more details into a thread name, what'd you say?

          Sometimes it's tricky to find a thread that executes your query. Okay in thread-per-connection mode it's fine, but in tpool you'll have to traverse all thread stacks to find one, if, say, you're just pausing the execution in gdb.

          I solve this problem with parallel stacks in clion, it looks like this:

          Yet I would definitely love to rely on such mouse-addicted interface less.

          nikitamalyavin Nikita Malyavin added a comment - wlad serg maybe later we can add a build-time option to add more details into a thread name, what'd you say? Sometimes it's tricky to find a thread that executes your query. Okay in thread-per-connection mode it's fine, but in tpool you'll have to traverse all thread stacks to find one, if, say, you're just pausing the execution in gdb. I solve this problem with parallel stacks in clion, it looks like this: Yet I would definitely love to rely on such mouse-addicted interface less.

          I solve this problem with Visual Studio, and others solve this problem with "SHOW PROCESSLIST", if they need an id. the os thread id is also there. Is thread-per-connection much better? How do you find your thread with 100 of threads?

          wlad Vladislav Vaintroub added a comment - I solve this problem with Visual Studio, and others solve this problem with "SHOW PROCESSLIST", if they need an id. the os thread id is also there. Is thread-per-connection much better? How do you find your thread with 100 of threads?

          @nikita, I would say, changing thread name twice per query (as in threadpool, to indicate thread ID, and to indicate "idle/waiting" state without THD) would be too expensive for optimized binary. For debug, it probably does not make any difference, so personally I would not care (but I did not care about thread names being perfschema-compatible in the first place, just did it on @serg's request)

          wlad Vladislav Vaintroub added a comment - @nikita, I would say, changing thread name twice per query (as in threadpool, to indicate thread ID, and to indicate "idle/waiting" state without THD) would be too expensive for optimized binary. For debug, it probably does not make any difference, so personally I would not care (but I did not care about thread names being perfschema-compatible in the first place, just did it on @serg's request)

          People

            wlad Vladislav Vaintroub
            valerii Valerii Kravchuk
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.