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?
I ran some standard sysbench workloads on MariaDB 10.4.12 with WSREP compiled in or not compiled in. As expected, disabling WSREP gives a small performance improvement. Also as expected, this improvement is bigger for write-intensive workload. The improvement is however small, in the order of 2%.
Axel Schwenke
added a comment - I ran some standard sysbench workloads on MariaDB 10.4.12 with WSREP compiled in or not compiled in. As expected, disabling WSREP gives a small performance improvement. Also as expected, this improvement is bigger for write-intensive workload. The improvement is however small, in the order of 2%.
Axel, did you test with and without binary logging?
In any case, to make performant code, all code should have a decent quality without 'obvious' bottlenecks.
The current code is an obvious bottleneck and anyone who would look at it would believe that we don't care about performance, which is definitely not the case.
Code like this should never be produced under any circumstances and especially not for something that is called many times during one statement execution.
The proper and only acceptable fix is to change the code to use a Boolean variable for the check.
If possible, I would argue that this variable is not allowed to change during a running transactions. If this is true, then the current state of wsrep should be stored in thd at start of transaction and the WSREP macros that are using thd should ONLY look at the thd during the execution of the transaction.
Michael Widenius
added a comment - Axel, did you test with and without binary logging?
In any case, to make performant code, all code should have a decent quality without 'obvious' bottlenecks.
The current code is an obvious bottleneck and anyone who would look at it would believe that we don't care about performance, which is definitely not the case.
Code like this should never be produced under any circumstances and especially not for something that is called many times during one statement execution.
The proper and only acceptable fix is to change the code to use a Boolean variable for the check.
If possible, I would argue that this variable is not allowed to change during a running transactions. If this is true, then the current state of wsrep should be stored in thd at start of transaction and the WSREP macros that are using thd should ONLY look at the thd during the execution of the transaction.
I updated the attachments with results from the benchmark; rerun with binlogging enabled. The general numbers dropped with binlogging enabled (as expected). It also looks like the difference between WITH_WSREP=1 and WITH_WSREP=0 gets smaller when binlogging is enabled. This is also expected. Binlogging adds latency to query processing (at least while waiting for the disk), so any constant overhead (we expect such overhead for WSREP=On checks) will look smaller in relation to the overall processing time.
Axel Schwenke
added a comment - I updated the attachments with results from the benchmark; rerun with binlogging enabled. The general numbers dropped with binlogging enabled (as expected). It also looks like the difference between WITH_WSREP=1 and WITH_WSREP=0 gets smaller when binlogging is enabled. This is also expected. Binlogging adds latency to query processing (at least while waiting for the disk), so any constant overhead (we expect such overhead for WSREP=On checks) will look smaller in relation to the overall processing time.
Before 10.4, WSREP only reads a global variable, and WSREP_ON_NEW was always unused. MDEV-16799 essentially reverted the definition of WSREP_ON to what it used to be.
I will port some cleanup (and the addition of an unlikely() hint to 10.1. There is not much more than can be done there.
Marko Mäkelä
added a comment - Before 10.4, WSREP only reads a global variable, and WSREP_ON_NEW was always unused. MDEV-16799 essentially reverted the definition of WSREP_ON to what it used to be.
I will port some cleanup (and the addition of an unlikely() hint to 10.1. There is not much more than can be done there.
People
Jan Lindström (Inactive)
Marko Mäkelä
Votes:
1Vote for this issue
Watchers:
5Start 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.
{"report":{"fcp":1115.3000001907349,"ttfb":319.5,"pageVisibility":"visible","entityId":85269,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"53b81cd9-6029-46f0-b440-58e995dfdade","navigationType":0,"readyForUser":1215,"redirectCount":0,"resourceLoadedEnd":1261.8000001907349,"resourceLoadedStart":324.80000019073486,"resourceTiming":[{"duration":241.39999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":324.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":324.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":566.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":241.39999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":325.1000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":325.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":566.5,"responseStart":0,"secureConnectionStart":0},{"duration":250.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":325.19999980926514,"connectEnd":325.19999980926514,"connectStart":325.19999980926514,"domainLookupEnd":325.19999980926514,"domainLookupStart":325.19999980926514,"fetchStart":325.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":325.19999980926514,"responseEnd":576,"responseStart":575.9000005722046,"secureConnectionStart":325.19999980926514},{"duration":338.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":325.4000005722046,"connectEnd":325.4000005722046,"connectStart":325.4000005722046,"domainLookupEnd":325.4000005722046,"domainLookupStart":325.4000005722046,"fetchStart":325.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":325.4000005722046,"responseEnd":664.1000003814697,"responseStart":664.1000003814697,"secureConnectionStart":325.4000005722046},{"duration":342.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":325.6000003814697,"connectEnd":325.6000003814697,"connectStart":325.6000003814697,"domainLookupEnd":325.6000003814697,"domainLookupStart":325.6000003814697,"fetchStart":325.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":325.6000003814697,"responseEnd":668.1999998092651,"responseStart":668.1999998092651,"secureConnectionStart":325.6000003814697},{"duration":342.79999923706055,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":325.9000005722046,"connectEnd":325.9000005722046,"connectStart":325.9000005722046,"domainLookupEnd":325.9000005722046,"domainLookupStart":325.9000005722046,"fetchStart":325.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":325.9000005722046,"responseEnd":668.6999998092651,"responseStart":668.6999998092651,"secureConnectionStart":325.9000005722046},{"duration":343.0999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":326.1000003814697,"connectEnd":326.1000003814697,"connectStart":326.1000003814697,"domainLookupEnd":326.1000003814697,"domainLookupStart":326.1000003814697,"fetchStart":326.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":326.1000003814697,"responseEnd":669.1999998092651,"responseStart":669.1999998092651,"secureConnectionStart":326.1000003814697},{"duration":394.8999996185303,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":326.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":326.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":721.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":343.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":326.4000005722046,"connectEnd":326.4000005722046,"connectStart":326.4000005722046,"domainLookupEnd":326.4000005722046,"domainLookupStart":326.4000005722046,"fetchStart":326.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":326.4000005722046,"responseEnd":669.6000003814697,"responseStart":669.5,"secureConnectionStart":326.4000005722046},{"duration":394.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":326.6000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":326.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":721.4000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":343.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":326.80000019073486,"connectEnd":326.80000019073486,"connectStart":326.80000019073486,"domainLookupEnd":326.80000019073486,"domainLookupStart":326.80000019073486,"fetchStart":326.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":326.80000019073486,"responseEnd":670.1000003814697,"responseStart":670.1000003814697,"secureConnectionStart":326.80000019073486},{"duration":519.2999992370605,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":332.4000005722046,"connectEnd":332.4000005722046,"connectStart":332.4000005722046,"domainLookupEnd":332.4000005722046,"domainLookupStart":332.4000005722046,"fetchStart":332.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":332.4000005722046,"responseEnd":851.6999998092651,"responseStart":851.6999998092651,"secureConnectionStart":332.4000005722046},{"duration":928.6000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":332.5,"connectEnd":332.5,"connectStart":332.5,"domainLookupEnd":332.5,"domainLookupStart":332.5,"fetchStart":332.5,"redirectEnd":0,"redirectStart":0,"requestStart":332.5,"responseEnd":1261.1000003814697,"responseStart":1261.1000003814697,"secureConnectionStart":332.5},{"duration":118.40000057220459,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":733.6999998092651,"connectEnd":733.6999998092651,"connectStart":733.6999998092651,"domainLookupEnd":733.6999998092651,"domainLookupStart":733.6999998092651,"fetchStart":733.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":733.6999998092651,"responseEnd":852.1000003814697,"responseStart":852.1000003814697,"secureConnectionStart":733.6999998092651},{"duration":254.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1007.3000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1007.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1261.8000001907349,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":143,"responseStart":319,"responseEnd":323,"domLoading":322,"domInteractive":1287,"domContentLoadedEventStart":1287,"domContentLoadedEventEnd":1333,"domComplete":1973,"loadEventStart":1973,"loadEventEnd":1974,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1264.6000003814697},{"name":"bigPipe.sidebar-id.end","time":1265.4000005722046},{"name":"bigPipe.activity-panel-pipe-id.start","time":1265.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":1267.1000003814697},{"name":"activityTabFullyLoaded","time":1359.6000003814697}],"measures":[],"correlationId":"cc3db03c1cb53","effectiveType":"4g","downlink":9.4,"rtt":0,"serverDuration":116,"dbReadsTimeInMs":17,"dbConnsTimeInMs":26,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
I ran some standard sysbench workloads on MariaDB 10.4.12 with WSREP compiled in or not compiled in. As expected, disabling WSREP gives a small performance improvement. Also as expected, this improvement is bigger for write-intensive workload. The improvement is however small, in the order of 2%.