מצב היום של MySQL 5.7
MySQL 5.7 אינו מושלם מבחינת המיגוי. התרשים הבא ממחיש את יחסית הדחיפות בין דחיפות התשואה של TPC-C והמתנהגויות בMySQL 5.7.39 תחת הגדרות ספציפיות. זה כולל הגדרת רמת הבידוד של העסקה ל "Read Committed" והגדרת הפרמטר innodb_spin_wait_delay
כדי למנוע דחיפות קיצונית.
תרשים 1: בעיות המיגוי בMySQL 5.7.39 בעוד בדיקות BenchmarkSQL
מתוך התרשים, ברור שבעיות המיגוי מגבילות בעליה הדחיפות של MySQL. לדוגמא, אחרי 100 מתנהגויות, הדחיפות מתחילה לירד.
כדי לטפל בבעיה הזאת של התמוטטות הביצועים, השתמש באגף ה线程 של Percona. התרשים הבא ממחיש את היחסים בין הדחיפות של TPC-C והמתנהגויות אחרי הגדרת אגף ה线程 של Percona.
תרשים 2: אגף ה线程 של Percona ממלא בעיית המיגוי בMySQL 5.7.39
למרות שהאגף הוציא חומר נדליף והייצוג הגבוה צנח, הוא ממלא את בעיית התמוטטות הביצועים תחת מתנהגויות גבוהות.
מצב היום של MySQL 8.0
בואו נסתכל על המאמצים של MySQL 8.0 בנוגע למיגוי.
עידוד עידוד רעיון השיפור הראשון
השיפור הראשון הגדול הוא עידוד עידוד רעיון [3].
commit 6be2fa0bdbbadc52cc8478b52b69db02b0eaff40
Author: Paweł Olchawa <[email protected]>
Date: Wed Feb 14 09:33:42 2018 +0100
WL#10310 Redo log optimization: dedicated threads and concurrent log buffer.
0. Log buffer became a ring buffer, data inside is no longer shifted.
1. User threads are able to write concurrently to log buffer.
2. Relaxed order of dirty pages in flush lists - no need to synchronize
the order in which dirty pages are added to flush lists.
3. Concurrent MTR commits can interleave on different stages of commits.
4. Introduced dedicated log threads which keep writing log buffer:
* log_writer: writes log buffer to system buffers,
* log_flusher: flushes system buffers to disk.
As soon as they finished writing (flushing) and there is new data to
write (flush), they start next write (flush).
5. User threads no longer write / flush log buffer to disk, they only
wait by spinning or on event for notification. They do not have to
compete for the responsibility of writing / flushing.
6. Introduced a ring buffer of events (one per log-block) which are used
by user threads to wait for written/flushed redo log to avoid:
* contention on single event
* false wake-ups of all waiting threads whenever some write/flush
has finished (we can wake-up only those waiting in related blocks)
7. Introduced dedicated notifier threads not to delay next writes/fsyncs:
* log_write_notifier: notifies user threads about written redo,
* log_flush_notifier: notifies user threads about flushed redo.
8. Master thread no longer has to flush log buffer.
...
30. Mysql test runner received a new feature (thanks to Marcin):
--exec_in_background.
Review: RB#15134
Reviewers:
- Marcin Babij <[email protected]>,
- Debarun Banerjee <[email protected]>.
Performance tests:
- Dimitri Kravtchuk <[email protected]>,
- Daniel Blanchard <[email protected]>,
- Amrendra Kumar <[email protected]>.
QA and MTR tests:
- Vinay Fisrekar <[email protected]>.
ניסוי אחד שהשווה בין הדחיפות של TPC-C עם רמות שונות של מתנהגו
תרשים 3: השפעת אופטימיזציית יומן השחזור ברמות שונות של תחרות
התוצאות בתרשים מראות שיפור משמעותי בתפוקה ברמות תחרות נמוכות.
אופטימיזציית Lock-Sys באמצעות חלוקת נועל לשברים
השיפור השני המשמעותי הוא אופטימיזציית lock-sys [5].
commit 1d259b87a63defa814e19a7534380cb43ee23c48
Author: Jakub Łopuszański <[email protected]>
Date: Wed Feb 5 14:12:22 2020 +0100
WL#10314 - InnoDB: Lock-sys optimization: sharded lock_sys mutex
The Lock-sys orchestrates access to tables and rows. Each table, and each row,
can be thought of as a resource, and a transaction may request access right for
a resource. As two transactions operating on a single resource can lead to
problems if the two operations conflict with each other, Lock-sys remembers
lists of already GRANTED lock requests and checks new requests for conflicts in
which case they have to start WAITING for their turn.
Lock-sys stores both GRANTED and WAITING lock requests in lists known as queues.
To allow concurrent operations on these queues, we need a mechanism to latch
these queues in safe and quick fashion.
In the past a single latch protected access to all of these queues.
This scaled poorly, and the managment of queues become a bottleneck.
In this WL, we introduce a more granular approach to latching.
Reviewed-by: Pawel Olchawa <[email protected]>
Reviewed-by: Debarun Banerjee <[email protected]>
RB:23836
בהתבסס על התוכנית לפני ואחרי האופטימיזציה עם lock-sys, באמצעות BenchmarkSQL להשוואת תפוקת TPC-C עם תחרות, התוצאות הספציפיות מוצגות בתרשים הבא:
תרשים 4: השפעת אופטימיזציית lock-sys ברמות שונות של תחרות
מהתרשים ניתן לראות שאופטימיזציית lock-sys משפרת באופן משמעותי את התפוקה בתנאי תחרות גבוהים, בעוד שההשפעה פחות מורגשת בתחרות נמוכה עקב פחות התנגשויות.
חלוקת נועל לשברים עבור trx-sys
השיפור השלישי המשמעותי הוא חלוקת נועל לשברים עבור trx-sys.
commit bc95476c0156070fd5cedcfd354fa68ce3c95bdb
Author: Paweł Olchawa <[email protected]>
Date: Tue May 25 18:12:20 2021 +0200
BUG#32832196 SINGLE RW_TRX_SET LEADS TO CONTENTION ON TRX_SYS MUTEX
1. Introduced shards, each with rw_trx_set and dedicated mutex.
2. Extracted modifications to rw_trx_set outside its original critical sections
(removal had to be extracted outside trx_erase_lists).
3. Eliminated allocation on heap inside TrxUndoRsegs.
4. [BUG-FIX] The trx->state and trx->start_time became converted to std::atomic<>
fields to avoid risk of torn reads on egzotic platforms.
5. Added assertions which ensure that thread operating on transaction has rights
to do so (to show there is no possible race condition).
RB: 26314
Reviewed-by: Jakub Łopuszański [email protected]
בהתבסס על האופטימיזציות האלה לפני ואחרי, באמצעות BenchmarkSQL להשוואת תפוקת TPC-C עם תחרות, התוצאות הספציפיות מוצגות בתרשים הבא:
תרשים 5: השפעת חלוקת נועל לשברים ב-trx-sys ברמות שונות של תחרות
מהתרשים ניתן לראות ששיפור זה משפר באופן משמעותי את תפוקת TPC-C, ומגיע לשיאו ב-200 תחרויות. ראוי לציין שההשפעה פוחתת ב-300 תחרויות, בעיקר עקב בעיות הרחבה מתמשכות במערכת המשנה trx-sys הקשורות ל-MVCC ReadView.
שיפור MySQL 8.0
השיפורים הנותרים הם השיפורים העצמאיים שלנו.
שיפורים במבנה MVCC ReadView
השיפור הראשון היה במבנה MVCC ReadView [1].
נעשו בדיקות של השוואה בין ביצועי הTPC-C עם רמות שונות של הקונקרטיות, לפני ואחרי שינוי במבנה MVCC ReadView.
ציון 6: שוואה בין הביצועים לפני ואחרי אימוץ המבנה המערבי החדש בסבך NUMA
מהציון מבין שהשינוי הזה מעדכן בעיקר את הסקאליביות ושיפר את הדרישה המירבית של MySQL בסבך NUMA.
מניעת בעיות הלוך-חזרה הכפול
השיפור השני שעשינו הוא לטיפול בבעיית הלוך-חזרה הכפול, בהסבר, "הלוך-חזרה הכפול" מתייחסת לדרישה למאגר הלוך-חזרה הגלובלי על ידי view_open
ו view_close
[1].
באמצעות הגרסה מותאמת לMVCC ReadView, שוואת ביצועי TPC-C עם השינויים. הפרטים נראים בציון הבא:
ציון 7: שיפור בביצועים אחרי הסירת המעבר המוגבל של הלוך-חזרה הכפול
מהציון רואים שהשינוי משפר בעיקר את הסקאליביות תחת תנאי קונקרטיות גבוהות.
מנגנון מגבלת העברות
השיפור האחרון הוא היישום של מנגנון מגבלת העברות כדי לשמור על מנת להימנע מקריסה בביצועים תחת רמות קריסטיות של הקונקרטיות [1] [2] [4].
המפה הבאה מדגימה את בעיית ההתפשטות של TPC-C אחרי היציאה לפעולה של בלוקים על העסקאות. המבחן נבצע בסידור בו ה NUMA BIOS דיסבלב, מגביל את הנכנס עד ל-512 תהליכים משתמש לתוך מערכת העסקאות.
ציון 8: הדרישה הגבוהה ביותר של TPC-C בבנקמרד SQL עם מנגנונים לבלוק על העסקאות
מהמפה, ניתן לראות שהיציאה לפעולה של בלוקים על העסקאות משפרת בהרבה את הסקאלביליות של MySQL.
סקירה
בסה"כ, נראה שלמעשה מיועד לMySQL לשמור על ביצועים מוצלחים ללא קריסה עם עשרות אלפים קישורים קונקורטים בסידורים בעלי קונפליקט נמוך בבנקמרד SQL TPC-C.
מפתחות
- בין וואng (2024). האמנות של פתרון בעיות בהנדסת תוכנה: איך לעשות את MySQL טוב יותר.
- הבאיריה החדשה של MySQL
- פאול אולצהובה. 2018. MySQL 8.0: עיצוב חדש של הגדרות בלי בלוקים, סקיליבלי של WAL. ארכיון הבלוג של MySQL.
- שיאנג' יאו. ביקורת של בקרת המקורים עם אלפים תהליכים. דוקטורטו, מכללת מסצוסוס, 2015.
- מדריך המידע על MySQL 8.0
Source:
https://dzone.com/articles/mysql-scalability-improvement-for-benchmarksql