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

WSREP_ON is unnecessarily expensive to evaluate

    XMLWordPrintable

Details

    Description

      The macro WSREP_ON used to be defined simply as an alias the global Boolean variable global_system_variables.wsrep_on. A more complex variant that invokes strcmp was introduced, in MDEV-16799 renamed to WSREP_ON_NEW, and related to MDEV-16405 (Galera 4) in 10.4.2 the more efficient macro WSREP_ON was replaced altogether.

      The following looks grossly inefficient:

      #define WSREP_ON                         \
        ((global_system_variables.wsrep_on) && \
         wsrep_provider                     && \
         strcmp(wsrep_provider, WSREP_NONE))
       
      /* use xxxxxx_NNULL macros when thd pointer is guaranteed to be non-null to
       * avoid compiler warnings (GCC 6 and later) */
      #define WSREP_NNULL(thd) \
        (thd->variables.wsrep_on && WSREP_ON)
       
      #define WSREP(thd) \
        (thd && WSREP_NNULL(thd))
      

      Why does the Boolean predicate WSREP_ON have to be so complex? We should be able to compute one global Boolean variable, something like this:

      extern my_bool WSREP_ON;
      #define WSREP_NNULL(thd) (WSREP_ON && thd->variables.wsrep_on)
      #define WSREP(thd) (thd && WSREP_NNULL(thd))
      

      The Boolean variable WSREP_ON would be updated by the update callback functions that would be attached to global_system_variables.wsrep_on and wsrep_provider.

      There are rather many checks for WSREP_ON, so this could affect performance, especially starting with MariaDB Server 10.4. I feel that this is important, because the code is being invoked even when Galera is not being used.

      MDEV-7962 was filed for performance regressions due to a similar check that is implemented in a non-inlined function wsrep_on(). Could we replace that one with an efficient implementation of the macro WSREP_ON?

      Attachments

        1. MDEV-22203.ods
          54 kB
        2. sysbench_read_only.png
          sysbench_read_only.png
          5 kB
        3. sysbench_read_write.png
          sysbench_read_write.png
          6 kB
        4. sysbench_update_index.png
          sysbench_update_index.png
          6 kB
        5. sysbench_update_non_index.png
          sysbench_update_non_index.png
          6 kB
        6. sysbench_write_only.png
          sysbench_write_only.png
          6 kB

        Issue Links

          Activity

            People

              jplindst Jan Lindström (Inactive)
              marko Marko Mäkelä
              Votes:
              1 Vote for this issue
              Watchers:
              5 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.