monitoring linux performance for the sql admin - · pdf filekernel resource management and...

46
Anthony E. Nocentino, Enterprise Architect, Centino Systems Monitoring Linux Performance for the SQL Server Admin

Upload: lebao

Post on 15-Mar-2018

230 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

AnthonyE.Nocentino,EnterpriseArchitect,CentinoSystems

MonitoringLinuxPerformancefortheSQLServerAdmin

Page 2: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

AnthonyE.NocentinoEnterpriseArchitect,CentinoSystems

[email protected]

ConsultantandTrainer

FounderandPresidentofCentino Systems

Specializeinsystemarchitectureandperformance

ComputerScience,M.S.andB.S.

MicrosoftMVP- DataPlatform

FriendofRedgate

LinuxFoundationCertifiedEngineer

MicrosoftCertifiedProfessional

Otherplacesonline…

Blog- www.centinosystems.com/blog

PluralsightAuthor

/nocentino @nocentino

Page 3: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• LinuxSystemArchitecture• SQLonLinuxArchitecture• SystemComponents

• CPU/Processes• Memory/Pages• Disk/FileSystems

• MonitoringTools

Agenda

Page 4: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• LinuxOSconcepts,howitworks!• Toolstoviewperformancedata• What’sgoodandwhat’sbad

Thingswe’regoingtocover

Thingswe’reNOTgoingtocover• SQLServerinternals• Performancetroubleshooting

Page 5: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

LinuxArchitecture

Kernel Resource Management and Access

Process, Pages and File Systems

ShellExecutes Your

Commands…Your Interface to the Kernel

Commands, Editors…any User Program

Hardware Physical Resources CPU, Memory and Disk

Users Interact with the Shell Cause Problems :)

Ker

nel

Spac

eU

ser S

pace

Page 6: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

SQLOS

PlacingtasksintoworkersandgettingaccesstotheCPU

Controllingaccesstosystemresources

SchedulingofI/Obothnetworkanddisk

Allocationofmemorytovarioussystemobjects

Scheduling Synchronization I/OMemoryManagement

PrimaryfunctionisresourcemanagementspecifictoRDBMS

“AnewplatformlayerinSQLServer2005toexploitnewhardwarecapabilitiesandtheirtrends”S.Oks

“OperatingSystemsupportforDatabaseManagement”M.Stonebraker

Page 7: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

SQLonLinuxArchitecture- Drawbridge

From:https://blogs.technet.microsoft.com/dataplatforminsider/2016/12/16/sql-server-on-linux-how-introduction/

Page 8: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

SQLonLinuxArchitecture- SQLPAL

From:https://blogs.technet.microsoft.com/dataplatforminsider/2016/12/16/sql-server-on-linux-how-introduction/

Page 9: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

SQLonLinuxArchitecture- ProcessLayout

From: https://blogs.technet.microsoft.com/dataplatforminsider/2016/12/16/sql-server-on-linux-how-introduction/

Page 10: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

SQLonLinuxArchitecture- SQLPAL

From:https://blogs.technet.microsoft.com/dataplatforminsider/2016/12/16/sql-server-on-linux-how-introduction/

AllotherCode

Win32HostedAPIs(LibOS) SQLOSAPI

SQLOSv2

HostExtension(Memory,Threads/Scheduling,I/O)

PerformanceSensitiveCode

LinuxKernelviaSystemCalls

Page 11: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• CalltablemapsWin32APIsemanticstoLinuxSystemcalls• ~45ABICalls• MemoryManagement• ThreadsandScheduling• SynchronizationPrimitives• I/ONetworkandDisk

• Wecarealotabouthostextensions…it’smorecode

SQLonLinuxArchitecture- HostExtensions

Page 12: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Processvirtualization(notmachine)• Presentinganotherenvironmentinsidetheprocess’contextthat’sdifferentthan

thatofthehardware’soperatingenvironment

• ButtheenvironmentispurposebuiltforSQLServer

• WeneedtounderstandthatthisisahybridWin32/Linuxprocessandhaveafirmgraspof• ResourceallocationandmanagementinSQLPAL• HowthatturnsintoLinuxOSperformance• Debugging

Shhhhhh- SQLPALisVirtualization;)

Page 13: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

CPUandProcesses

Page 14: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Process• Executingprogram,programcode,memoryandresources

• Thread(LWP)• Sharedaccesstoresources

• ProcessandThreadCreation• fork/exec - parentprocessyieldsachildprocesswithaPID• clone - sameaddressspaceasthreadcreator,cheapandfast!

• ProcessTree• Thehierarchyofparentandit’schildprocesses

WhatisaProcess

Page 15: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Process States

WhatisaProcess(con’t)

Running

Runnable

ZombieStopped

Sleeping

Page 16: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Signals• Methods of process control• kill and killall

• Niceness• Set the execution priority• nice and renice• Default 20, lower is less “nice”

ControllingProcesses

Page 17: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Contextswitching• KernelversusUserMode• CPUScheduling• HowisaSQLOSWorkerscheduledontotheCPU?• Createsathreadviapthreadandthat’spushedintothescheduler

• pthreads?

MoreonProcesses…

Page 18: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Unitofschedulingisthethread• DefaultschedulerisSCHED_OTHER/SCHED_NORMAL

• Timesharingscheduler• Preemptive• Dynamicprioritylist,basedonniceness• Calculatedquantumlengthbasedonpriority• kernel.sched_min_granularity_ns = 10000000 (10ms)- default• kernel.sched_wakeup_granularity_ns = 15000000 (15ms)- default

• NUMAAware,but…• kernel.numa_balancing = 0 - default

Process/ThreadScheduling

Page 19: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Percentageofwhat?• Loadaverage• RunqueuelengthandI/Owaits• Spikesaren’tbad• Longwaits• User• I/O- disklatencywilleffectaccesstotheCPU• System

CPU- Whattolookfor?

Page 20: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• top/htop• ps• mpstat/pidstat• dstat• procfs

Toolstouseforprocessmonitoring

Page 21: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Processesandthreads• RunloadaverageunderCPUsaturation• Exploringprocfs

Demos

Page 22: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

MemoryandPages

Page 23: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• MemoryLayoutandArchitecture• PhysicalandVirtualMemory• NUMA- freelistspernode• Pages(Anonymous)• DemandPaging• Swapout• TimeandPressure

• Swapin,MajorPageFault• Allocation,MinorPageFault

• FileSystemCacheandswappiness - http://red.ht/2cHg9Vk• vm.swappiness = 10 (default30,0disablesswapping)• vm.dirty_ratio = 40 (default 30)• vm.max_map_count = 262144 (default65530)

Memory

Page 24: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Regularpages- 4KB• Transparenthugepages- 2MB• IncreasesmemoryI/ObydecreasingTLBcachemisses

• SQLOSv2• CanrequestlargepagesinsideSQLServer…withtraceflag834• SQLwillallocatememoryonstartup• WhenSQLPALexposes8GB+toSQLServer

• Asoftoday,nolockedpages…butTF835ison?

Pages

Page 25: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• OnWindowsLockPagesinMemoryisAddressWindowExtensions(AWE)• AllocatescontiguousmappingstoPFNs.Logicallycontiguous,butnotguaranteedcontiguous

• LinuxwilltrytomaketheTHPscontiguous• ThenthosePFNsaremappingintotheprocess’virtualaddressspace

• WhyuseAWE?• Howaretheyunpageable?

HelloOldFriend…AWE

Page 26: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Highconsumersofspace• Physical• Virtual

• ExternalmemorypressureonSQLServer• Excessiveswapping• swappingin/out

Memory- Whattolookfor?

Page 27: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• /proc/meminfo• free• top/htop• ps• vmstat• pidstat

Toolstouseformemorymonitoring

Page 28: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Memorylayout• Isolatingamemoryhog• Identifyingexternalmemorypressure• ExternalmemorypressureonSQLServer

• Excessiveswapping• Swappingin/Swappingout

Demos

Page 29: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

DisksandFileSystems

Page 30: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Sectors(physical)• Actualstorageunitofthedisk,512Bor4KB

• Blocks(logical)• FundamentalunitofI/O,allocation

• Diskshavefiniteperformancecharacteristics• Bandwidth- howmuchdata• Latency- howfast

• StorageInterconnects• Internal• External

Disks

Page 31: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• XFS• Defaultfilesystem- http://red.ht/2dBXccx

• EXT4• Blocksize• Impactutilizationandperformancenominally• 4KBdefaultblocksize

• Mounttimeoptions• Accesstimes- noatime

FileSystems

Page 32: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• XFSandEXT4essentiallythesame• Files• i-nodes• Extents• Blocks

BlockAllocationinLinux

Page 33: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• StreamI/OviaNTUM

• FastI/Oviathehostextension• KernelasynchronousIO(kaio)• io_submit()• Returnstocallerimmediately,completionpollingisinuserspace

• O_DIRECT - bypassespagecacheandI/Ostaysinusermode• fsync()• “probablydesignedbyaderangedmonkeyonsomeseriousmind-controllingsubstances.”- Linus• man 2 open

I/OunderSQLPAL

Page 34: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Thisistheslowestthinginyourcomputer,sorryArgenis!:)

• SaturateddisksandI/Osubsystems• Swapping• Cachingisyourfriend(generally,butnotinanRDBMS)• Baseline!

Disks- Whattolookfor?

Page 35: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• iostat• iotop• pidstat• dstat

Toolstousefordiskmonitoring

Page 36: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• FindinghighI/Oprocesses• Measuringdisklatency(DMVsandcmdlinetools)• sys.dm_io_virtual_file_stats

Demos

Page 37: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

MonitoringTools

Page 38: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Nearlyeverythingwe’vetalkedaboutsofarhasbeenpointintime…whataboutbaselining?

• sar - SystemActivityReporter• dstat - writestoCSV

BaseliningTools

Page 39: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Youhaveallofthesametoolsyou’reusedtoforSQLServer• BecauseofSQLOSweget• DMVs• ExtendedEvents

ToolsforMonitoringSQLServer

Page 40: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• NewDMVs

• PSSDiag• https://blogs.msdn.microsoft.com/sqlcat/2017/08/11/collecting-performance-data-with-

pssdiag-for-sql-server-on-linux/• DBFS• https://github.com/Microsoft/dbfs• http://www.centinosystems.com/blog/sql/dbfs-command-line-access-to-sql-server-dmvs/

• Grafana• https://blogs.msdn.microsoft.com/sqlcat/2017/07/03/how-the-sqlcat-customer-lab-is-

monitoring-sql-on-linux/

NewToolsAvailableforSQLonLinux

Page 41: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• Don’tjustlistentome…here’swhatMicrosoftisinterestedin• CPU- mpstat,pidstat• Disk- iostat,iotop• Memory- free,sar• Network- sar• DMVData• Systemloginformation

MetricsCapturedbyPSSDiag

Page 42: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

• LinuxSystemArchitecture• SQLonLinuxArchitecture• SystemComponents

• CPU/Processes• Memory/Pages• Disk/FileSystems

• MonitoringTools

Review

Page 43: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

Needmoredata?

Blogwww.centinosystems.com/blog

PluralsightUnderstandingandUsingEssentialToolsforEnterpriseLinux7Linuxbasics,systemarchitecture,fileanddirectorymanagement

LFCE:AdvancedNetworkandSystemAdministrationsystemd,PerformanceandTools

Page 44: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

References

Manyofthemanpages

https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-performance-best-practices

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/performance_tuning_guide/index

https://www.kernel.org/doc/Documentation/

https://ext4.wiki.kernel.org/index.php/Clarifying_Direct_IO%27s_Semantics

Page 45: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

Sessionevaluations

DownloadtheGuideBookAppandsearch:PASSSummit2017

FollowtheQRcodelinkdisplayedonsessionsignagethroughouttheconferencevenueandinthe

programguide

Yourfeedbackisimportantandvaluable.

GotopassSummit.com

Submitby5pmFriday,November10th towinprizes.3WaystoAccess:

Page 46: Monitoring Linux Performance for the SQL Admin - · PDF fileKernel Resource Management and Access ... Primary function is resource management specific to RDBMS ... •System Components

ThankYouJoinmefortheBOFlunchfrom12P-2P

[email protected]@nocentino