Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Presentation by David Yitzhak [email protected] DBAאפליקטיבי ותשתיתי של SQL Server, Oracle ,Sybase Anywhereמזה 18שנה התמחות בשיפור ביצועים, שרידות ,זמינות גבוהה ,רפלקציה (הגדולות בעולם ) ,תוספים גיאוגרפיים ,אבטחת מידע Business Intelligence , Data Mining,ואלגוריתמיקה ( Oracle Rומטלב) . עובד עם עיבוד מקבילי' אלגוריתמים ( )Microsoft HPCופתרונות .NoSQL מרכז את פורום DBAצפון של ilOUGעם הרצאות רבות על נושאים מתקדמים . http://www.iloug.org.il/DBA_NorthForum.php כותב ראשי ב .ildba.co.il -עשרות מאמרים על Oracleו. SQL Server - 2הרצאות בפורום משתמשי . SQL Serverהרצאה אחרונה על בפורום משתמשי BIעל .SQL 2014 Data Mining ב 2010-הרצאה ב Oracle Open world-על שילוב מתקדם של Data Guardו.ODP.NET - הכתבות שלי מתפרסמות בפורומים מקומיים :עיבוד מקבילי עתיר ביצועים ( )Microsoft HPCבשילוב Oracle),וSQL - , )SERVERהנדסת מערכת של תשתיות מחשוב (פרויקט זוכה פרס גון) ,ובעיתונות העולמית ( SQL Server .)magazine 3תארים מהטכניוןBSC :בהנדסת מערכות מידע ושני תארים שניים MBA :ו( ME -הנדסת מערכת). רקעHYBRID Transactional Analytical Processing – HTAP וHPC ושיפור ביצועיםDelayed Durability benchmark - ה.SQL 2014 -) בCCI( Clustered ColumnStore Index . האולטימטיבי בסביבה וירטואליתin Memory OLTP -שימוש ב Memory Optimized Tables -פתרונות זמינות גבוהה ותמיכתם ב Entity Framework בכלל ושילוב מולMemory Optimized Tables פיתוח מול demo –SQL 2014 - בHash Index - וMemory Optimized (MO) table כוונון של Demo -In-Memory OLTP Transaction isolation levels Demo – אופרטורIndex seek - וComposite hash indexes ...... נחמד אבל- SSD Buffer Pool Extension : לא יכוסה בהרצאה בגלל קוצר זמן למרות שהבטחתי Active Active cluster לעומתHigh Availability Group ????? – האומנם יש שיפורSQL 2014 בCardinality Estimator • HPC gives engineers the computation resources they need to speed research and development. Examples: ◦ Test simulations ◦ Modeling solutions ◦ Highly complex problems Computes nodes ◦ Dozens nodes oh HPC, Win 2008\2012R2. ◦ In future : Several thousands on Win 7 works stations ◦ Run Matlab and .Net APP process VS Oracle DB 12C/SQL 2014 . ◦ .Net APP use Oracle Data Access Components (ODAC) No of Processes running VS SQL Server ◦ Job can assigned per CPU Core . ◦ 12 cores per compute Nodes. ◦ Assume we have N Compute Nodes ◦ In Full utilization Job per core N X 12 =1200 processes of .NET APP vs DB . MATLAB Mechanical CAD : ◦ ABAQUS ◦ CST (Computer Simulation Technology) Monte Carlo Simulation The Heat Map view gives instant feedback on the health of the cluster-upwards of 1,000 nodes, without scrolling. Workstation NAS SAN Oracle /SQL Data file on HDS storage … Oracle (~10T Data) 12CR1 ,64 bit/ SQL 2014 … 4. Job finished ,response return to client 3. Compute Nodes run vs SQL Sever In memory OLTP Application network 2. Assigns nodes for client job … Head node Failover Head node Private network Enterprise network 1. User submits job. Dozens Compute nodes: , .Net ,Matlab for simulation data mining the results and real time analytics Win 2008/12 R2 Log file on shared Drives using CIFS Protocol to SATA disks . Identify simulation Objective Monitor Performance & recalibrate Understand Simulation data Deploy Model Prepare data on HPC Test Models Develop models to explore / analyze and predict data • Use Matalab , .Net App • Good starting points MSSQL data mining 10 The in-memory transaction log is flushed to disk when: ◦ A fully durable transaction in the same database makes a change in the database and successfully commits ◦ Executes sp_flush_log successfully ◦ The in-memory transaction log buffer fills up and automatically flushes to disk ALTER DATABASE … SET DELAYED_DURABILITY = { DISABLED | ALLOWED | FORCED } DELAYED_DURABILITY = { OFF | ON } (with NATIVE_COMPILED sprocs ONLY COMMIT [ { TRAN | TRANSACTION } ] [ transaction_name | @tran_name_variable ] ] [ WITH ( DELAYED_DURABILITY = { OFF | ON } ) ] start performance monitor Add the Log Flushes/sec counter of the SQL Server:Database object to the live running performance monitor. As you can see, This is not a busy database Delayed Durability has forced and there are currently no log flushes happening In order to ensure that the transaction and its data changes are hardened to the log and thus durable, run sp_flush_Log You can view the log flush in Performance Monitor The spike in the counter indicates the log flush. sets the Delayed Durability setting to Disabled This ensures all transactions will be durable in the AdventureWorks2014 database. The transaction flushed to the log and is thus durable at the time of the commit SQL Express+ Feature Transaction commits :fully durable or delayed durable Delayed transaction durability reduces the latency due to log I/O by keeping the transaction log records in memory and writing to the transaction log in batches, thus requiring fewer I/O operations Delayed Durability could be an option ◦ Accept some data loss in the event of a system crash or restart ◦ Performance of the system is more important.. ◦ Bottleneck on transaction log writes. ◦ A high contention workload: Remove the contention as it reduces the commit time and locks will be released faster. האינדקס יכול להיות על חלק מהעמודות. נבנה על גבי אחסון מסוג שורה ( )rowstoreולא אחסון מסוג עמודה (.)column store טבלה עם NCCIהיא לקריאה בלבד .במקרה של עדכון נדרש לבצע Dropלאינדקס ,טעינת נתונים ויצירת אינדקס .לחילופין , DISABLE...ALTER INDEXטעינת נתונים ובסיום ALTER INDEX... .ENABLE אלגוריתם הדחיסה הוא של B treeאו Heapולא יכול לנצל את היתרונות של אחסון מבוסס עמודה . ניתן ליצור NCCIאחד בלבד על טבלה . שאילתות מסוג שוויון ( )equalityושאילתות על טווח קצר ( )rang queriesיעילות יותר כי הם משתמשים ב. B tree - http://www.ildba.co.il/non-clustered-columnstore-indexes-sql-2012-2014/ : המאמרים שלי Clustered ColumnStore Index עבודה עם Clustered ColumnStore Index בדיקת ביצועים של – אשליהupdateable Clustered ColumnStore Index ?או אמת מגבלות והערות נוספותlustered ColumnStore Index ב – CCIהמידע מאוחסן בצורה דחוסה וע"פ חלוקה לעמודות בצורה כזו שניתן לבצע דחיסה בצורה יעילה ,לחסוך מקום במערכת האחסון ולשפר ביצועים ע"י צריכת זיכרון נמוכה ,כי רק העמודות הנדרשות מגיעות לזיכרון ובצורה דחוסה CCI .לא מאוחסן בצורה ממוינת כמו Clustered Indexרגיל ,למרות שמונח Clusteredמופיע בשם האינדקס. כל העמודות נדרשות עבור . CCIלא ניתן ליצור אינדקסים נוספים . טבלה עם CCIניתנות לעדכון INSERT, UPDATE, DELETE :ו.bulk load - ניתן לבצע שימוש ב Archival Compressionשמשפר את יחס הדחיסה עד . X10זהו אלגוריתם דחיסה משופר החל מ – . SQL 2014בפקודה ALTER INDEX … REBUILDהתווספה האופציה Archival Compression . COLUMNSTORE_ARCHIVEמיועד עבור כמויות מידע גדולות למטרות ארכיון, כאשר נדרש מצמום בשטח דיסק כשהתקורה הנוספת היא בזמן נוסף לצורך אחסון ואחזור לעומת אלגוריתם הדחיסה הרגיל של .CCI שאילתות מסוג שוויון ( )equalityושאילתות על טווח קצר ( )rang queriesפחות יעילות ויתכן וידרשו סריקה מלאה של הטבלה . ב SQL 2012 Data types -רבים לא נתמכו ע"י NCIכמו unique identifier ,binaryו decimals -עם . precision > 18ב SQL 2014 -כל ה Data types -שהם לא מסוג blobנתמכים ע"י columnstore indexמלבד geography , hierarchyid ,sql_variant , timestamp, rowversion , image , )n)text : xml , geometry ,ו.)n(Varchar(max) - CCIזמין בגרסאות Enterprise, Developerו Evaluation Edition -בלבד כלומר יש לו משמעות כספית מבחינת רישוי. כל העמודות חיבות להיות מוכלות ב CCIובעת היצירה אין צורך לציין את העמודות .אם ננסה לעשות זאת : בקטע הקוד הבא ניצור טבלה בשם , SalesOrdersניצור עליה CCIונבצע הכנסה של 2400000 שורות . .include actual execution plan - לturn on נבצע נריץ את השאילתה הבאה columnstore - ניתן לראות שיש שימוש בשאילתה ב : execution plan - בindex scan sys.column_store_row_groupsהוא DMVשמאפשר לראות את כל ה Row Groups -שב Delta Store -וב. Column Stores - לכל partitionבטבלה יש Delta Storeאחד לפחות . נשתמש ב DMVזה בשביל להחליט מה מספר ה. Delta stores - אנו משתמשים ב DMV -זה בשביל לבדוק את איכות ה . CCIאם יש Row Groupעם פחות 1Mשורות ,יש לבדוק למה ,כפי שאדגים להלן . הסבר :יש לנו Row Group 2שהם דחוסים ( state=3 ),state_description=COMPRESSEDו Delta Dtoreאחד ( state=1 , . )state_description=OPEN שימו לב שסכום העמודה row_countשווה ל 1048576+1048576+2848 סה"כ , 2,400,000שזה בדיוק מספר השורות שהכנסנו . ההסבר .כמו שצינתי מספר השורות המינימאלי עבורו יתבצע דחיסה ומעבר לפורמט של Column Storeהוא .1048076 אני כעת אעורר את תהליך ה , tuple mover -באופן א- סינכרוני ,ע"י שימוש בפקודה הבאה כדי לאלץ דחיסה של כל ה Row group -לפורמט של . Column Store sys.column_store_segmentsמאפשרים למצוא את טווח הערכים של העמודות עבור הדחיסה שמשתמש באלימינציה של סגמנטים ומידע על גודלו של כל segementו .sys.column_store_segments ל columnstoreיש row groups 2ואין אף delta storeאו . delete bitmap ניתן לראות את טווח הערכים עבור כל row groupsבעמודות min_data_idו max_data_idלמשל עבור העמודה עם column_id=1 בניה מחדש של האינדקס יכולה להתבצע ע"י האופציה ) , WITH (DROP_EXISTING = ONשזורקת את האינדקס הקיים ובונה אותו מחדש .שימו לב שאם האינדקס לא קיים תתקבל הודעת שגיאה . ב SQL 2014 -ל CCIיש אלגוריתם דחיסה נוסף ,מלבד האלגוריתם שמגיע כבררת מחדל ,בשם . Column Store Archivingהמחיר תקורה של CPUגבוהה יותר וזמן גישה איטי יותר .הדחיסה כאמור יכולה להיעשות פר partitionבטבלה .נוכל לבדוק מה גודל הטבלה שבנינו ע"י הפרוצדורה sp_spaceusedבאופן הבא : . SalesOrderNumber על השדהcluster index עם- SalesOrders_Clustered . SalesOrderNumber על השדהNCI עם- SalesOrders_NCCI נכניס לכל אחת. שכמו שראינו מכיל את כל העמודות, CCI – עםSalesOrders_CCI מיליון רשומות12 מהטבלאות . SalesOrderNumber על השדהNCI עם- SalesOrders_NCCI –SalesOrders_CCIעם , CCIשכמו שראינו מכיל את כל העמודות .נכניס לכל אחת מהטבלאות 12מיליון רשומות נריץ את קטע הקוד הבא שמבצע את אותה שאילתה עבור 3הטבלאות הנ"ל כ batch -אחד .יש לבחור באופציה Include Actual Execution PlanבSQL server - Management studioתחת התפריט .Query התוצאה עבור כל טבלה אפשר לראות להלן .תחת ה tab -בשם execution planנוכל לראות את המחיר היחסי באחוזי של כל שאילתה . תחת message Tabנוכל לראות כמה logical readעבור כל שאילתה .נסכם את התוצאות : ל columnstore indexיש 2סוגי אופרטורים batch mode :ו Batch mode . row mode -הוצג יחד columnstore indexב . SQL 2012 -מכיוון ש columnstore indexהוא מבוסס עמודות ,ע"י שימוש ב batch mode -נוכל לעבד שורות רבות במקביל ב batch -אחד ובצורה יעילה יותר .ל batch mode -היתרונות הבאים : מעבד בין 64עד 960שורות בו זמנית ולכן מאפשר משיכת מידע בכמות גדולה יותר ,ללא צורך בביצוע של . decompression מספר קריאות מערכת קטן יותר . זמין רק ב parallel plan -ב.columsstore - אין העתקה מיותרת של מידע . בשביל לראות אם columnstoreרץ ב batch mode -או , row modeעליך לבדוק את ה properties -של columnstore operationב execution plan -עבור הטבלה .. SalesOrders_CCI החל מ SQL 2008 -עמודות עם הרבה ערכים של , Nullיכולה להיות מאוחסנת כ – , Sparse Columnע"י ציון התכונה SPARSE לעמודות שהם , nullableבכדי לחסוך את התקורה של אחסון העמודות עם ערכי . NULLאי אפשר ליצור columnstore index על עמודה מסוג : Sparse https://msdn.microsoft.com/enus/library/%20dn529286(v=sql.120).aspx Without MO tables, 2 best practices: With MO tables ◦ MIN_SERVER_MEMORY- Assign only the amount of memory that is required so sufficient memory remains for other processes (thereby avoiding paging). ◦ Do not set the memory pre-allocation value too high. Other processes may not get sufficient memory at the time when they require it ->memory paging If you follow this advice you can run into an issue An attempt to restore and recover a database could result in the database being in a “Recovery Pending” state, even if you have sufficient memory to recover the database . When your SQL Server gets rebooted or the service restarted. It is possible for the database to get held in a recovery-pending state. Can impact the VM being able to use HA features that the Hypervisor ( live migration) Why? SQL Server loads the data into RAM more quickly than the hypervisor's dynamic memory allocation provides memory to the database. Set a memory reservation for the virtual machine on the hypervisor- ensuring that enough memory is allocated at startup pre-allocate sufficient memory to the database (MIN_SERVER_MEMORY) to recover or restart the database, not a Min value relying on dynamic memory to provide the additional memory when needed. Error Message insufficient system memory ◦ ◦ Msg 701, Level 17, State 103, Line 32 There is insufficient system memory in resource pool 'Pool_AdventureWorks2014' to run this query. High-Availability Technology Support for memory-optimized tables ◦ Fully supported : AlwaysOn Failover Cluster , Availability Groups, and LogShipping. FCI Failover ◦ Data from durable memory-optimized tables must be loaded Increase failover time. AlwaysOn Availability Groups ◦ Only durable memory-optimized tables are replicated to secondary nodes. ◦ Can access and query those tables on the readable secondary nodes. ◦ Data from non-durable memory-optimized tables is not replicated and will be lost in the case of a failover. Replication ◦ Can set up transactional replication on databases with memory-optimized tables; ◦ Those tables cannot be used as articles in publications. Mirror ◦ Not supported. ◦ In-memory OLTP is an Enterprise Edition feature; replace database mirroring with AlwaysOn Availability Groups. פיתוח מול MO Tablesלא שקוף למשתמש ,דורש שינוי בקוד .גרסה שתומכת ב Mo Table -וגרסה שלא תומכת .דוגמא בהמשך . לכן הוא בעיתי לספקי תוכנה בהיקף נרחב כי הוא דורש תקורה נוספת תחזוקת קוד . דורש חומרה חזקה ,עם הרבה זיכרון .אופציה מדהימה של Enterprise Editionולכן יש לו משמעות כספית מבחינת רישוי . אם אתה משתמש Enterprise Editionתוכל להשתמש בMO table - variablesאו non-durable MO table variablesבמקום on-disk . temporary tables שיפור ביצועים של החישובים ותהליכי ETLב , DW -ב HYBRID Transactional Analytical Processing – HTAPובסביבת הסימולציה . אפשרות נוספת להשתמש ב session state storageלאפלקציות ASP.Net או distributed cacheלאפליקציות clientבמקום פתרונות צד שלישי יקרים . תמיד לזכור שאורך השורה המכסימלי הוא . 8060 byte Model based מסוגEntity Data Model (EDM) נניח שבנינו פרויקט Setting the connection for an EDM Selecting database objects to be imported into an EDM. בסיס הנתונים יצטרך. LINQ to Entities Query (Direct SQL) אנו משתמשים ב IM OLTP להיות משוכתב פעמיים עם ובלי תמיכה The entity data model design surface in Visual Studio. Importing a function into the conceptual model. DEMO DEMO IM OLTP Transaction supports 3 : ◦ SNAPSHOT ◦ REPEATABLE READ ◦ SERIALIZABLE. Disk tables : Block or being blocked by sessions IM OLTP uses a completely different approach to enforce data consistency . ◦ IM OLTP validates data consistency at the transaction COMMIT time ◦ Throws an exception and rolling back the transaction if rules were violated. SERIALIZABLE isolation level prevents the session from committing a transaction when another session inserted a new row and violated the serializable validation. MO tables ◦ Other sessions able to modify data that was read by the active serializable/REPEATABLE READ transaction. ◦ Transaction aborts at the time of COMMIT. On-disk tables ◦ SERIALIZABLE transaction would successfully commit blocking other sessions until it is done. Works in a similar manner to on-disk tables Protects from Non-Repeatable Reads and Phantom Reads. It reduces the load on SQL Server- it does not need to perform repeatable read and serializabl Validations at the commit stage. Write/write conflicts work the same way regardless of the transaction isolation level in IM OLTP. SQL Server does not allow a transaction to modify rows that have been modified by other uncommitted transactions. In the example we use the SNAPSHOT isolation level, however the behavior does not change with different isolation level. DEMO Efficient only in the case of an equality search Our example : index on (LastName, FirstName) columns ◦ Composite hash indexes SQL Server calculates the hash value for the combined value of all key columns. A hash value calculated on a subset of the key columns would be different MO table requires queries to have equality predicates on both LastName and FirstName Different from indexes on on-disk tables: ◦ Index can be used for a Seek operation regardless of whether the predicate on the FirstName column is specified in the where clause of a query. Buffer Poll extensionב SQL 2014 -מאפשר הרחבה של הbuffer - Poolל . non-volatile storageכלומר לדיסק או מערך דיסקים מסוג . SSD רק דפים נקיים נרשמים ל BPE -בשביל למנוע איבוד מידע אפשרי . שיפור ביצועים הוא עבור סביבת OLTPעם קריאות מסיביות . יתרונות : זמין בגרסת ( SQL 2014 standard Editionלא מצריך רישוי גרסת )Enterprise טוב עבור עומסי קריאה אינטנסיביים בסביבת . OLTP Throughput גבוה אם משתמשים בדיסק .SSD סינטקס הוא פשוט ולא דורש שינוי בקוד . מגבלות: לא עבור מחסני נתונים ועומסי כתיבה אינטנסיביים . בארגונים גדולים שעובדים מול חוות אחסון בעיתי ,כי הכנסת דיסק SSDלמערך כזה או למשל מחשבי bladeהוא בעייתי . David Itshak ◦ [email protected] Ildba.co.il www.iloug.co.il