Unless MariaDB is built with cmake -DPLUGIN_PERFSCHEMA=NO, there will be some measurable overhead related to some frequently invoked operations, such as mysql_mutex_lock() and mysql_mutex_unlock(). Take the latter for example. It would resolve to the following inline function:
{
|
int result;
|
|
#ifdef HAVE_PSI_MUTEX_INTERFACE
|
if (psi_likely(that->m_psi != NULL))
|
PSI_MUTEX_CALL(unlock_mutex)(that->m_psi);
|
#endif
|
|
#ifdef SAFE_MUTEX
|
result= safe_mutex_unlock(&that->m_mutex, src_file, src_line);
|
#else
|
result= pthread_mutex_unlock(&that->m_mutex);
|
#endif
|
|
return result;
|
}
|
The call to pfs_unlock_mutex_v1() via the function pointer PSI_MUTEX_CALL(unlock_mutex), as well as the condition preceding that call are executed within the critical section of the mutex.
It would be better to make use of function pointers, say,
return PSI_MUTEX_CALL(unlock_mutex)(that);
|
and make the function pointer PSI_server->unlock_mutex point to either pthread_mutex_unlock or pfs_unlock_mutex(). If the server is compiled with PLUGIN_PERFSCHEMA=NO, the macro can resolve bypass the function pointer, something like this:
#ifdef HAVE_PSI_MUTEX_INTERFACE
|
# define mysql_mutex_unlock(M) PSI_MUTEX_CALL(unlock_mutex)(M)
|
#elif defined SAFE_MUTEX
|
# define mysql_mutex_unlock(M) \
|
safe_mutex_unlock(M, __FILE__, __LINE__)
|
#else
|
# define mysql_mutex_unlock(M) pthread_mutex_unlock(M)
|
#endif
|
The function pointer would be set to pthread_mutex_unlock by static initialization, and assigned to the instrumented function at the end of pfs_init_func(). In this way, if the performance schema is disabled at runtime, mysql_mutex_unlock() would translate to a simple call to pthread_mutex_unlock() via a function pointer.
While we are at it, I would also consider removing memory bloat like this:
struct st_mysql_mutex
|
{
|
/** The real mutex. */
|
#ifdef SAFE_MUTEX
|
safe_mutex_t m_mutex;
|
#else
|
pthread_mutex_t m_mutex;
|
#endif
|
/**
|
The instrumentation hook.
|
Note that this hook is not conditionally defined,
|
for binary compatibility of the @c mysql_mutex_t interface.
|
*/
|
struct PSI_mutex *m_psi;
|
};
|
Which binary compatibility is this about? To my knowledge, all plugins are typically included in the MariaDB Server repository and compiled from source code.
- relates to
-
MDEV-24973
Performance schema duplicates rarely executed code for mutex operations
-
-
Closed
{"report":{"fcp":948.2999999523163,"ttfb":168.70000004768372,"pageVisibility":"visible","entityId":127158,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"d8705225-f31a-47dc-9d04-a77e5d145aa1","navigationType":0,"readyForUser":1010.1000001430511,"redirectCount":0,"resourceLoadedEnd":1235,"resourceLoadedStart":173.70000004768372,"resourceTiming":[{"duration":353.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":173.70000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":173.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":526.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":353,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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","startTime":173.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":173.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":526.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":361.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":174.10000014305115,"connectEnd":174.10000014305115,"connectStart":174.10000014305115,"domainLookupEnd":174.10000014305115,"domainLookupStart":174.10000014305115,"fetchStart":174.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":174.10000014305115,"responseEnd":535.7999999523163,"responseStart":535.7999999523163,"secureConnectionStart":174.10000014305115},{"duration":398.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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","startTime":174.10000014305115,"connectEnd":174.10000014305115,"connectStart":174.10000014305115,"domainLookupEnd":174.10000014305115,"domainLookupStart":174.10000014305115,"fetchStart":174.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":174.10000014305115,"responseEnd":572.7000000476837,"responseStart":572.7000000476837,"secureConnectionStart":174.10000014305115},{"duration":401.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":174.29999995231628,"connectEnd":174.29999995231628,"connectStart":174.29999995231628,"domainLookupEnd":174.29999995231628,"domainLookupStart":174.29999995231628,"fetchStart":174.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":174.29999995231628,"responseEnd":576.1000001430511,"responseStart":576.1000001430511,"secureConnectionStart":174.29999995231628},{"duration":402.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":174.29999995231628,"connectEnd":174.29999995231628,"connectStart":174.29999995231628,"domainLookupEnd":174.29999995231628,"domainLookupStart":174.29999995231628,"fetchStart":174.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":174.29999995231628,"responseEnd":576.6000001430511,"responseStart":576.6000001430511,"secureConnectionStart":174.29999995231628},{"duration":402.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":174.40000009536743,"connectEnd":174.40000009536743,"connectStart":174.40000009536743,"domainLookupEnd":174.40000009536743,"domainLookupStart":174.40000009536743,"fetchStart":174.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":174.40000009536743,"responseEnd":577,"responseStart":577,"secureConnectionStart":174.40000009536743},{"duration":402.90000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":174.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":174.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":577.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":402.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":174.60000014305115,"connectEnd":174.60000014305115,"connectStart":174.60000014305115,"domainLookupEnd":174.60000014305115,"domainLookupStart":174.60000014305115,"fetchStart":174.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":174.60000014305115,"responseEnd":577.2999999523163,"responseStart":577.2999999523163,"secureConnectionStart":174.60000014305115},{"duration":402.90000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":174.79999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":174.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":577.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":403,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":174.90000009536743,"connectEnd":174.90000009536743,"connectStart":174.90000009536743,"domainLookupEnd":174.90000009536743,"domainLookupStart":174.90000009536743,"fetchStart":174.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":174.90000009536743,"responseEnd":577.9000000953674,"responseStart":577.9000000953674,"secureConnectionStart":174.90000009536743},{"duration":1058.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":175.5,"connectEnd":175.5,"connectStart":175.5,"domainLookupEnd":175.5,"domainLookupStart":175.5,"fetchStart":175.5,"redirectEnd":0,"redirectStart":0,"requestStart":175.5,"responseEnd":1233.9000000953674,"responseStart":1233.9000000953674,"secureConnectionStart":175.5},{"duration":1055.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":179.90000009536743,"connectEnd":179.90000009536743,"connectStart":179.90000009536743,"domainLookupEnd":179.90000009536743,"domainLookupStart":179.90000009536743,"fetchStart":179.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":179.90000009536743,"responseEnd":1235,"responseStart":1235,"secureConnectionStart":179.90000009536743},{"duration":486.7999999523163,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":745.1000001430511,"connectEnd":745.1000001430511,"connectStart":745.1000001430511,"domainLookupEnd":745.1000001430511,"domainLookupStart":745.1000001430511,"fetchStart":745.1000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":745.1000001430511,"responseEnd":1231.9000000953674,"responseStart":1231.9000000953674,"secureConnectionStart":745.1000001430511}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":39,"responseStart":168,"responseEnd":172,"domLoading":171,"domInteractive":1290,"domContentLoadedEventStart":1290,"domContentLoadedEventEnd":1323,"domComplete":2163,"loadEventStart":2163,"loadEventEnd":2165,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1240.4000000953674},{"name":"bigPipe.sidebar-id.end","time":1241.1000001430511},{"name":"bigPipe.activity-panel-pipe-id.start","time":1241.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.end","time":1243.5},{"name":"activityTabFullyLoaded","time":1326.2999999523163}],"measures":[],"correlationId":"56a9f43c1bc7ff","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":74,"dbReadsTimeInMs":11,"dbConnsTimeInMs":18,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}