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

Reduce overhead of attaching THD to OS thread, in threadpool

Details

    Description

      To execute any command, a THD needs to be "attached" to the OS thread, which means, that
      some variables in THD needs to be reset. This includes :

      • set_current_thd() TLS variable, to thd
      • mysys_var TLS variable., to thd->mysys_var
      • THD::thread_stack and mysys_var.stack_ends_here
      • THD::thread_id (pthread_self) "for debugging"
      • os_thread_id (Linux only) - to be shown in SHOW PROCESSLIST. That's a system call
      • some PFS thread local storage

      Some of that is expensive, when run millions of times, specifically, getting the os_thread_id on Linux is a system call. pthread_self, while not as expensive is still a library call.

      Also, current code used in THD::store_globals does a lot more currently, than it should do for threadpool, making thread_attach() on Linux about half as expensive as the inevitable epoll_ctl().

      For simple commands like "do 1", thread_attaching can take as much as about 7% of the query execution overhead (excluding network IO)

      Attachments

        Activity

          wlad Vladislav Vaintroub created issue -
          wlad Vladislav Vaintroub made changes -
          Field Original Value New Value
          Description To execute any command, a THD needs to be "attached" to the OS thread, which means, that
          some variables in THD needs to be reset. This includes :
          * set_current_thd() TLS variable, to thd
          * mysys_var TLS variable. to thd->mysys_var
          * THD::thread_stack and mysys_var.stack_ends_here
          * THD::thread_id (pthread_self) "for debugging"
          * os_thread_id (Linux only) - to be shown in SHOW PROCESSLIST. That's a system call
          * some PFS thread local storage set and read from

          Some of that is expensive, when run millions of times, specifically, getting the os_thread_id on Linux is a system call. pthread_self, while not as expensive is still a library call.

          Also, current code used in THD::store_globals does a lot more currently, than it should do for threadpool, making thread_attach() on Linux about half as expensive as the inevitable epoll_ctl().

          For simple commands like "do 1", thread_attaching can take as much as about 7% of the query execution overhead (excluding network IO)
          To execute any command, a THD needs to be "attached" to the OS thread, which means, that
          some variables in THD needs to be reset. This includes :
          * set_current_thd() TLS variable, to thd
          * mysys_var TLS variable., to thd->mysys_var
          * THD::thread_stack and mysys_var.stack_ends_here
          * THD::thread_id (pthread_self) "for debugging"
          * os_thread_id (Linux only) - to be shown in SHOW PROCESSLIST. That's a system call
          * some PFS thread local storage
          *
          Some of that is expensive, when run millions of times, specifically, getting the os_thread_id on Linux is a system call. pthread_self, while not as expensive is still a library call.

          Also, current code used in THD::store_globals does a lot more currently, than it should do for threadpool, making thread_attach() on Linux about half as expensive as the inevitable epoll_ctl().

          For simple commands like "do 1", thread_attaching can take as much as about 7% of the query execution overhead (excluding network IO)
          wlad Vladislav Vaintroub made changes -
          Description To execute any command, a THD needs to be "attached" to the OS thread, which means, that
          some variables in THD needs to be reset. This includes :
          * set_current_thd() TLS variable, to thd
          * mysys_var TLS variable., to thd->mysys_var
          * THD::thread_stack and mysys_var.stack_ends_here
          * THD::thread_id (pthread_self) "for debugging"
          * os_thread_id (Linux only) - to be shown in SHOW PROCESSLIST. That's a system call
          * some PFS thread local storage
          *
          Some of that is expensive, when run millions of times, specifically, getting the os_thread_id on Linux is a system call. pthread_self, while not as expensive is still a library call.

          Also, current code used in THD::store_globals does a lot more currently, than it should do for threadpool, making thread_attach() on Linux about half as expensive as the inevitable epoll_ctl().

          For simple commands like "do 1", thread_attaching can take as much as about 7% of the query execution overhead (excluding network IO)
          To execute any command, a THD needs to be "attached" to the OS thread, which means, that
          some variables in THD needs to be reset. This includes :
          * set_current_thd() TLS variable, to thd
          * mysys_var TLS variable., to thd->mysys_var
          * THD::thread_stack and mysys_var.stack_ends_here
          * THD::thread_id (pthread_self) "for debugging"
          * os_thread_id (Linux only) - to be shown in SHOW PROCESSLIST. That's a system call
          * some PFS thread local storage

          Some of that is expensive, when run millions of times, specifically, getting the os_thread_id on Linux is a system call. pthread_self, while not as expensive is still a library call.

          Also, current code used in THD::store_globals does a lot more currently, than it should do for threadpool, making thread_attach() on Linux about half as expensive as the inevitable epoll_ctl().

          For simple commands like "do 1", thread_attaching can take as much as about 7% of the query execution overhead (excluding network IO)
          wlad Vladislav Vaintroub made changes -
          Priority Minor [ 4 ] Major [ 3 ]
          wlad Vladislav Vaintroub made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          wlad Vladislav Vaintroub made changes -
          issue.field.resolutiondate 2022-10-11 06:53:29.0 2022-10-11 06:53:29.404
          wlad Vladislav Vaintroub made changes -
          Fix Version/s 10.6.11 [ 28441 ]
          Fix Version/s 10.7.7 [ 28442 ]
          Fix Version/s 10.8.6 [ 28443 ]
          Fix Version/s 10.9.4 [ 28444 ]
          Fix Version/s 10.10.2 [ 28410 ]
          Fix Version/s 10.6 [ 24028 ]
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]

          People

            wlad Vladislav Vaintroub
            wlad Vladislav Vaintroub
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.