lock_sys is one of three major InnoDB scalability bottlenecks. Scalability issues are especially obvious under sysbench OLTP update index/non-index benchmarks.
There's no clarity on how exactly it should be optimised yet.
Attachments
Issue Links
blocks
MDEV-21452Use condition variables and normal mutexes instead of InnoDB os_event and mutex
Closed
causes
MDEV-24861Assertion `trx->rsegs.m_redo.rseg' failed in innodb_prepare_commit_versioned
Closed
MDEV-35708lock_rec_get_prev() returns only the first record lock
Closed
includes
MDEV-24731Excessive mutex contention in DeadlockChecker::check_and_resolve()
Closed
is blocked by
MDEV-24671Assertion failure in lock_wait_table_reserve_slot()
Closed
relates to
MDEV-11392AliSQL: [perf] Issue#31 OPTIMIZE CHECK/GRANT OF INNODB TABLE LOCK
Also srv_slot_t can be removed and the locality of reference improved by storing trx->lock.wait_lock and trx->lock.cond in adjacent addresses.
Marko Mäkelä
added a comment - Also srv_slot_t can be removed and the locality of reference improved by storing trx->lock.wait_lock and trx->lock.cond in adjacent addresses.
Marko Mäkelä
added a comment - - edited zhaiwx1987 , I adapted the MDEV-11392 idea from MySQL Bug #72948 , but I introduced a single counter dict_table_t::n_lock_x_or_s . There is actually quite a bit of room for improvement in lock_sys , in addition to what was done in MySQL 8.0.21 WL#10314 .
The lock_wait() refactoring was causing some assertion failures in the start/stop que_thr_t bookkeeping. I think that it is simplest to remove that bookkeeping along with removing some unnecessary data members or enum values. Edit: This was done in MDEV-24671. As an added bonus, innodb_lock_wait_timeout is enforced more timely (no extra 1-second delay).
It turns out that the partitioned lock_sys.mutex will not work efficiently with the old DeadlockChecker. It must be refactored, similar to what was done in Oracle Bug #29882690 in MySQL 8.0.18.
Marko Mäkelä
added a comment - - edited The lock_wait() refactoring was causing some assertion failures in the start/stop que_thr_t bookkeeping. I think that it is simplest to remove that bookkeeping along with removing some unnecessary data members or enum values. Edit: This was done in MDEV-24671 . As an added bonus, innodb_lock_wait_timeout is enforced more timely (no extra 1-second delay).
It turns out that the partitioned lock_sys.mutex will not work efficiently with the old DeadlockChecker . It must be refactored, similar to what was done in Oracle Bug #29882690 in MySQL 8.0.18.
As a minimal change, I moved the DeadlockChecker::search() invocation to lock_wait(). A separate deadlock checker thread or task might still be useful. For that, I do not think that there is a need to introduce any blocking_trx data member. In our code, it should be safe to follow the chain of trx->lock.wait_lock->trx while holding lock_sys.wait_mutex and possibly also trx->mutex.
Marko Mäkelä
added a comment - As a minimal change, I moved the DeadlockChecker::search() invocation to lock_wait() . A separate deadlock checker thread or task might still be useful. For that, I do not think that there is a need to introduce any blocking_trx data member. In our code, it should be safe to follow the chain of trx->lock.wait_lock->trx while holding lock_sys.wait_mutex and possibly also trx->mutex .
We replaced lock_sys.mutex with a lock_sys.latch (MDEV-24167) that is 4 or 8 bytes on Linux, Microsoft Windows or OpenBSD. On other systems, a native rw-lock or a mutex and two condition variables will be used.
The entire world of transactional locks can be stopped by acquiring lock_sys.latch in exclusive mode.
Scalability is achieved by making most users use a combination of a shared lock_sys.latch and a lock-specific dict_table_t::lock_mutex or lock_sys_t::hash_latch that is embedded in each cache line of the lock_sys.rec_hash, lock_sys.prdt_hash, or lock_sys.prdt_page_hash. The lock_sys_t::hash_latch is always 4 or 8 bytes. On other systems than Linux, OpenBSD, and Microsoft Windows, the lock_sys_t::hash_latch::release() will always acquire a mutex and signal a condition variable. This is a known scalability bottleneck and could be improved further on such systems, by splitting the mutex and condition variable. (If such systems supported a lightweight mutex that is at most sizeof(void*), then we could happily use that.)
Until MDEV-24738 has been fixed, the deadlock detector will remain a significant bottleneck, because each lock_wait() would acquire lock_sys.latch in exclusive mode. This bottleneck can be avoided by setting innodb_deadlock_detect=OFF.
Marko Mäkelä
added a comment - We replaced lock_sys.mutex with a lock_sys.latch ( MDEV-24167 ) that is 4 or 8 bytes on Linux, Microsoft Windows or OpenBSD. On other systems, a native rw-lock or a mutex and two condition variables will be used.
The entire world of transactional locks can be stopped by acquiring lock_sys.latch in exclusive mode.
Scalability is achieved by making most users use a combination of a shared lock_sys.latch and a lock-specific dict_table_t::lock_mutex or lock_sys_t::hash_latch that is embedded in each cache line of the lock_sys.rec_hash , lock_sys.prdt_hash , or lock_sys.prdt_page_hash . The lock_sys_t::hash_latch is always 4 or 8 bytes. On other systems than Linux, OpenBSD, and Microsoft Windows, the lock_sys_t::hash_latch::release() will always acquire a mutex and signal a condition variable. This is a known scalability bottleneck and could be improved further on such systems, by splitting the mutex and condition variable. (If such systems supported a lightweight mutex that is at most sizeof(void*) , then we could happily use that.)
Until MDEV-24738 has been fixed, the deadlock detector will remain a significant bottleneck, because each lock_wait() would acquire lock_sys.latch in exclusive mode. This bottleneck can be avoided by setting innodb_deadlock_detect=OFF .
People
Marko Mäkelä
Sergey Vojtovich
Votes:
2Vote for this issue
Watchers:
12Start 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":1162.5999999046326,"ttfb":306.09999990463257,"pageVisibility":"visible","entityId":79014,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":0.5,"journeyId":"3fbaa7a0-61f2-4f76-a04d-484b0f3da542","navigationType":0,"readyForUser":1312.5,"redirectCount":0,"resourceLoadedEnd":1413.7999997138977,"resourceLoadedStart":312.09999990463257,"resourceTiming":[{"duration":195.7999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":312.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":312.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":507.8999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":196.80000019073486,"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":312.3999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":312.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":509.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":272.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":312.59999990463257,"connectEnd":312.59999990463257,"connectStart":312.59999990463257,"domainLookupEnd":312.59999990463257,"domainLookupStart":312.59999990463257,"fetchStart":312.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":312.59999990463257,"responseEnd":584.6999998092651,"responseStart":584.6999998092651,"secureConnectionStart":312.59999990463257},{"duration":419.40000009536743,"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":312.7999997138977,"connectEnd":312.7999997138977,"connectStart":312.7999997138977,"domainLookupEnd":312.7999997138977,"domainLookupStart":312.7999997138977,"fetchStart":312.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":312.7999997138977,"responseEnd":732.1999998092651,"responseStart":732.1999998092651,"secureConnectionStart":312.7999997138977},{"duration":422.5,"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":313.09999990463257,"connectEnd":313.09999990463257,"connectStart":313.09999990463257,"domainLookupEnd":313.09999990463257,"domainLookupStart":313.09999990463257,"fetchStart":313.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":313.09999990463257,"responseEnd":735.5999999046326,"responseStart":735.5999999046326,"secureConnectionStart":313.09999990463257},{"duration":422.90000009536743,"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":313.19999980926514,"connectEnd":313.19999980926514,"connectStart":313.19999980926514,"domainLookupEnd":313.19999980926514,"domainLookupStart":313.19999980926514,"fetchStart":313.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":313.19999980926514,"responseEnd":736.0999999046326,"responseStart":736.0999999046326,"secureConnectionStart":313.19999980926514},{"duration":423,"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":313.3999996185303,"connectEnd":313.3999996185303,"connectStart":313.3999996185303,"domainLookupEnd":313.3999996185303,"domainLookupStart":313.3999996185303,"fetchStart":313.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":313.3999996185303,"responseEnd":736.3999996185303,"responseStart":736.3999996185303,"secureConnectionStart":313.3999996185303},{"duration":465.5,"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":313.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":313.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":779,"responseStart":0,"secureConnectionStart":0},{"duration":423.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":313.59999990463257,"connectEnd":313.59999990463257,"connectStart":313.59999990463257,"domainLookupEnd":313.59999990463257,"domainLookupStart":313.59999990463257,"fetchStart":313.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":313.59999990463257,"responseEnd":736.7999997138977,"responseStart":736.7999997138977,"secureConnectionStart":313.59999990463257},{"duration":465.30000019073486,"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":313.7999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":313.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":779.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":423.5,"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":313.8999996185303,"connectEnd":313.8999996185303,"connectStart":313.8999996185303,"domainLookupEnd":313.8999996185303,"domainLookupStart":313.8999996185303,"fetchStart":313.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":313.8999996185303,"responseEnd":737.3999996185303,"responseStart":737.3999996185303,"secureConnectionStart":313.8999996185303},{"duration":886,"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":315.7999997138977,"connectEnd":315.7999997138977,"connectStart":315.7999997138977,"domainLookupEnd":315.7999997138977,"domainLookupStart":315.7999997138977,"fetchStart":315.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":315.7999997138977,"responseEnd":1201.7999997138977,"responseStart":1201.7999997138977,"secureConnectionStart":315.7999997138977},{"duration":1098,"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":315.7999997138977,"connectEnd":315.7999997138977,"connectStart":315.7999997138977,"domainLookupEnd":315.7999997138977,"domainLookupStart":315.7999997138977,"fetchStart":315.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":315.7999997138977,"responseEnd":1413.7999997138977,"responseStart":1413.7999997138977,"secureConnectionStart":315.7999997138977},{"duration":382.19999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":820.0999999046326,"connectEnd":820.0999999046326,"connectStart":820.0999999046326,"domainLookupEnd":820.0999999046326,"domainLookupStart":820.0999999046326,"fetchStart":820.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":820.0999999046326,"responseEnd":1202.2999997138977,"responseStart":1202.2999997138977,"secureConnectionStart":820.0999999046326},{"duration":365.19999980926514,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1144.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1144.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1509.7999997138977,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":117,"responseStart":306,"responseEnd":307,"domLoading":309,"domInteractive":1448,"domContentLoadedEventStart":1448,"domContentLoadedEventEnd":1508,"domComplete":1704,"loadEventStart":1704,"loadEventEnd":1704,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1417.8999996185303},{"name":"bigPipe.sidebar-id.end","time":1418.6999998092651},{"name":"bigPipe.activity-panel-pipe-id.start","time":1418.8999996185303},{"name":"bigPipe.activity-panel-pipe-id.end","time":1420.6999998092651},{"name":"activityTabFullyLoaded","time":1528}],"measures":[],"correlationId":"1dd7c9d0128007","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":131,"dbReadsTimeInMs":35,"dbConnsTimeInMs":47,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Also srv_slot_t can be removed and the locality of reference improved by storing trx->lock.wait_lock and trx->lock.cond in adjacent addresses.