9个必须掌握的Linux性能调优命令和工具.docx

上传人:夺命阿水 文档编号:1085087 上传时间:2024-03-15 格式:DOCX 页数:13 大小:393.88KB
返回 下载 相关 举报
9个必须掌握的Linux性能调优命令和工具.docx_第1页
第1页 / 共13页
9个必须掌握的Linux性能调优命令和工具.docx_第2页
第2页 / 共13页
9个必须掌握的Linux性能调优命令和工具.docx_第3页
第3页 / 共13页
9个必须掌握的Linux性能调优命令和工具.docx_第4页
第4页 / 共13页
9个必须掌握的Linux性能调优命令和工具.docx_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《9个必须掌握的Linux性能调优命令和工具.docx》由会员分享,可在线阅读,更多相关《9个必须掌握的Linux性能调优命令和工具.docx(13页珍藏版)》请在课桌文档上搜索。

1、目录前言top命令htop命令PS命令free命令vmstat命令iosat命令netstat命令df命令du命令附LinUX性能工具全景图前言一般来说,LinUX性能调优涉及CPU、内存和10,包括进程、线程、程序堆栈、内存、Swap、CPU调度、内存调度、网络连接和IO读写等。本文介绍了LinUX查看资源使用情况和性能调优常用的命令,包括top、htop、ps、free、vmstatiostat、netstatdf和du命令。top命令top命令用来监控系统的资源使用情况,包括CPU、内存、Swap、进程和线程等。命令:#运行toptop#显示进程的完整命令topY推荐使用下面的htop命

2、令来代替top命令。htop命令htop命令用来监控系统的资源使用情况,包括CPU、内存、Swap、进程和线程等。相比top命令,htop命令更能更强大,显示也更加直观。命令:#运行htophtop概要信息说明:CPU使用率:数字1、2、.表示CPU有几个核,后面的进度条用不同颜色来表示不同维度的CPU使用率,最后是CPU使用率;内存使用率:Mem后面的进度条用不同颜色来表示不同维度的内存使用率(绿色:used,蓝色:buffers,橙色:cache),最后是内存使用率(used/total);Swap使用率:Swap后面的进度条显示已用的Swap,最后是Swap使用率(used/total)

3、,如果系统关闭了SWap,则进度条为空,SWaP使用率为0K/0K;进程和线程统计:Tasks:进程数,thr:线程数,running:正在运行的进程数;系统平均负载统计:LOadaVerage:前1分钟平均负载、前5分钟平均负载和前15分钟平均负载;负载越低说明CPU越空闲,负载越高说明CPU越忙:负载低于0.7*CPU核数:CPU使用率正常;(道路通畅)负载高于0.7*CPU核数:CPU使用率较高,需要关注;(道路堵车,需要交警到场疏导交通)负载高于I*CPU核数:CPU使用率过高,需要关注;(道路严重堵车,可能发生了交通事故,需要交警马上到现场处理)负载高于5*CPU核数:系统超负荷运转

4、,无法正常响应;(交通瘫痪,可能道路己经被水淹无法通行,需要投入抢险力量恢复交通)系统已连续运行时间:Uptime后面为系统从上次启动后,己连续运行时间,可以倒推系统上次启动时间;详细信息说明:P1D:进程ID;USER:进程所有者;PRh进程优先级;NLniCe值,负值表示高优先级,正值表示低优先级;VIRT:进程使用的虚拟内存(VirtUalmemory);RES:进程使用的物理内存(PhySiCalmemory);SHR:进程使用的共享内存(sharedmemory);S:进程状态,R(Running)正在运行的进程、S(SIeePing)休眠的进程、TS(TracedSK)PPed)已

5、停止或中止的进程或Z(Zommbie)僵尸进程;CPU%:进程使用的CPU时间百分比;MEM%:进程使用的内存百分比;TIME+:进程己连续运行时间;Command:进程的执行命令;常用快捷键:上下箭头:上下滚动查看进程;u:显示指定用户的进程;P:按照进程使用的CPU时间百分比排序;M:按照进程使用的内存百分比排序;T:按照进程已连续运行时间排序;参考:PS命令# 查看java进程# e(every)所有进程# f(fullformat)完整输出格式ps-efIgrepnginx# 不显示grep本身PS-efIgrepnginxgrep-vgrep# 获取指定进程的PIDPS-efIgre

6、pjavagrepjenkinsgrep-vgrepawk,print$2# 根据进程的PID中止进程PS-efIgrepjavagrepjenkinsgrep-vgrepawk,print$2)*xargskill-9# 查看进程堆栈# p(path)显示完整路径PmaP-p# 查看9091端口是哪个容器进程dockerPSgrep9091PS-ef格式:UID:进程的UlD(用户)PID:进程IDPPID:父进程IDC:CPU使用时间百分比STIMETTYTIMECMD:启动进程的命令free命令free命令用来查看内存和Swap的使用情况。命令:#以适合阅读的形式输出(h:human)f

7、ree-h#以MB格式输出(m:MB)free-m# 合计Mem和Swap(t:total)free-h-t# 统计3次,每秒1次(c:count)free-h-c3# 统计5次,每2秒统计1次(s:second)free-h-t-c5-s2说明:Total:TheamountofRAMinstalledinyoursystem.Used:EqualtoTotal-(Free+Buffers+Cache).Free:Theamountofmemorycompletelyunusedbyanything.Shared:Memorytakenbythetrnpfsfilesystems.Buffe

8、r:ThedatastructuresthataremaintainedtoprovideanindexforeverythingstoredinCache.Cache:Datareadfromtheharddrive,modifieddatawaitingtobewrittenbacktotheharddrive,andothercomputedvalues.Available:Whatsreallyfree.AnestimateofthememoryinFree,Buffer,andCachethatcouldbeusedtosatisfyamemoryrequest.简单来说,total

9、是系统总内存,USed就是系统已用内存,total-used就是系统可用内存。参考:vmstat命令VmStat命令用来统计进程、内存、Swap、IO和CPU等信息。命令:#运行VmStatVmstat# 每5秒统计1次vmstat5# 每5秒统计1次,共统计4次vmstat54# 以MB格式输出内存使用情况vmstat54-SM# 显示统计概要信息vmstat-s说明:Procr:Thenumberofrunnableprocesses.Theseareprocessesthathavebeenlaunchedandareeitherrunningorarewaitingfortheirne

10、xttime-slicedburstofCPUcycles.b:Thenumberofprocessesinuninterruptiblesleep.Theprocessisn,tsleeping,itisperformingablockingsystemcall,anditcannotbeinterrupteduntilithascompleteditscurrentaction.Typicallytheprocessisadevicedriverwaitingforsomeresourcetocomefree.Anyqueuedinterruptsforthatprocessarehand

11、ledwhentheprocessresumesitsusualactivity.Memoryswpd:theamountofvirtualmemoryused.Inotherwords,howmuchmemoryhasbeenswappedout.,free:theamountofidle(currentlyunused)memory.buff:theamountofmemoryusedasbuffers.cache:theamountofmemoryusedascache.Swapsi:Amountofvirtualmemoryswappedinfromswapspace.so:Amoun

12、tofvirtualmemoryswappedouttoswapspace.IObi:Blocksreceivedfromablockdevice.ThenumberofdatablocksusedtoswapvirtualmemorybackintoRAM.bo:Blockssenttoablockdevice.ThenumberofdatablocksusedtoswapvirtualmemoryoutofRAMandintoswapspace.Systemin:Thenumberofinterruptspersecond,includingtheclock.cs:Thenumberofc

13、ontextswitchespersecond.Acontextswitchiswhenthekernelswapsfromsystemmodeprocessingintousermodeprocessing.CPUThesevaluesareallpercentagesofthetotalCPUtime.us:Timespentrunningnon-kernelcode.Thatis,howmuchtimeisspentinusertimeprocessingandinnicetimeprocessing.sy:Timespentrunningkernelcode.id:Timespenti

14、dle.wa:Timespentwaitingforinputoroutput.st:Timestolenfromavirtualmachine.Thisisthetimeavirtualmachinehastowaitforthehypervisortofinishservicingothervirtualmachinesbeforeitcancomebackandattendtothisvirtualmachine.参考:iosat命令iostat命令用来统计磁盘IO和CPU等信息。命令:# isiostatiostat# 以MB格式输出iostat-m# 查看指定磁盘(分区)iostat

15、-m-pvda# 每2秒统计一次,共统计3次iostat-m23说明:CPU信息:user:ItshowsthepercentageofCPUbeingutilizationthatwhileexecutingattheuserlevel.nice:ItshowsthepercentageofCPUutilizationthatoccurredwhileexecutingattheuserlevelwithanicepriority.system:ItshowsthepercentageofCPUutilizationthatoccurredwhileexecutingatthesystem(

16、kernel)level.iowait:ItshowsthepercentageofthetimethattheCPUorCPUswereidleduringwhichthesystemhadanoutstandingdiskI/Orequest.steal:ItshowsthepercentageoftimebeingspentininvoluntarywaitbythevirtualCPUorCPUswhilethehypervisorwasservicingbyanothervirtualprocessor.idle:ItshowsthepercentageoftimethattheCP

17、UorCPUswereidleandthesystemdidnothaveanoutstandingdiskI/Orequest.磁盘信息:Device:Thedeviceartitionnameislistedindevdirectory.tps:Thenumberoftransferspersecondthatwereissuedtothedevice.Highertpsmeanstheprocessorisbusier.Blk_read/s:Itshowstheamountofdatareadfromthedeviceexpressedinanumberofblocks(kilobyte

18、s,megabytes)persecond.Blk_wrtn/s:Theamountofdatawrittentothedeviceexpressedinanumberofblocks(kilobytes,megabytes)persecond.Blk_read:Itshowsthetotalnumberofblocksread.Blk_wrtn:Itshowsthetotalnumberofblockswritten.参考:netstat命令netstat命令用来统计网络连接和端口等信息。命令:# 显示在侦听的TCP/UDP网络连接,包括程序和端口信息# U(UDP)# t(TCP)# n(

19、port)# 1(listen)# p(program)netstat-Utnlp# 只显示在侦听的TCP网络连接,包括程序和端口信息netstat-tnlp# 查看某个端口被哪个进程使用# a(all)netstat-anpgrep6379# 查看某个进程在哪个端口netstat-anpgrepredis# 查看docker启动的进程在哪个端口dockerPSgrepjenkinsdf命令df命令用来统计磁盘使用情况。命令:# 查看全部文件系统的磁盘使用情况df-h# 查看指定目录所在的文件系统的磁盘使用情况df-h-# 不显示docker文件系统df-hIgrep-vdockerdu命令d

20、u命令用来统计指定目录的大小。命令:# 统计某个目录大小du-sh# 统计目录下各个子目录和文件的大小du-h# 统计目录下各个子目录和文件的大小,并显示合计大小du-ch# 只统计下一级目录大小du-h-max-depth1# 只统计下一级目录大小,单位为MB,从大到小排序du-m-max-depth1sort-rn# 只统计下一级目录大小,单位为MB,从大到小排序,返回最大的10个文件(目录)du-m-max-depth1sort-rnhead-111.inUX系统性能调优涉及多个方面,包括内核参数调整、文件系统优化、网络设置等。1 .内核参数调整:通过调整内核参数来提高系统性能。例如,调

21、整进程调度策略、内存管理参数等。2 .文件系统优化:使用性能更好的文件系统,如ext4.XFS等。同时,进行文件系统缓存设置、磁盘读写速度调整等操作。3 .网络设置:优化网络参数,如缓冲区大小、接收发送速度等。使用更高效的传输协议,如TCP/IP。4 .进程优先级调整:为关键任务设置更高的进程优先级,提高系统响应速度。5 .内存管理:合理分配内存,避免内存资源竞争,提高系统吞吐量。6 .进程调度:通过调整进程调度策略,提高系统响应速度和并发能力。7 .软件卸载与安装:避免安装不必要的软件,卸载无用的系统组件,减轻系统负担。.定期清理系统日志和其他垃圾文件,释放系统资源。1.inux性能调优需要

22、综合考虑系统硬件配置、应用场景和用户需求等因素。以下是Linux性能调优常见工具和堆栈解析,供读者参考:1.inuxStorageStack图解TheLinuxStorageStackDiagram(LinuxKernel6.2)ThtUMIShWO0rm0ivmVwmas4tenncomWft*klieu._Sorpe.31K*_0grmDwqnWmnf.MQpod勃CtwtophHMgRichartMtggerMLftWCCY-SA)0ff199fwcemw31.inux文件系统堆栈性能调优图解NewtoolsdevelopedforthebookBPFPerformanceTools:L

23、inuxSystemandApplicationObservabilitybyBrendanGregg(AddisonWesley.2019),whichalsocoverspriorBPFtoolsfiletopopensnoopc*java*node*phpfilliffilslowrvfscontvfsstatpython*ruby*javatbreadsgethostlatencyeaklfsnoopRuntimesjnistackslsniffmyqld_q1owrdbstatdbslowerbashradlinnysqldclatbahfuncbashfnclatIoprofile

24、BCXM1ApplicationsSocketsTCP/UDPVolumeManageofdsnoopsockstatsofami:statsnoopsyncsnooplatncy!resultfiltyfsrwstatvfsizKMpfileeVritesynccchtatcchtopdcsttdcsnoopInountsnoopucallsuflowQobjnewustatUthreadsugcicttbufgrowreadaheadthradsnoopPadOCkPmheIdyscountkillsnoopshellsnoopsignalsnaptiMprmstuidnoopwritba

25、cktracargdistfunccountfunclowrfUnclatencytackcountprofilebtrfditbtrfsslowret4distxt4slowernfeelowerXfsslowersfsslowrovrlayfsMdflushbiotopbiosnoopbiolatencybitesize1.egend:priortoolnvtoolskisbiopttrnbiostacksbxorxIoschedblkthrotSystemLibrariesSystemCallInterfaceexcsnoopitnooppidpreccpudistcpuwalkrunq

26、latrvnqlnrunqslowerCpuunclaimeddeadlockFileSystemsBlockDevicesoconnctaocktioSoconnlatkbdropbpftrace/eBPF工具说明bpftrace/eBPFTools工802:USUannVMlatencySchedulerOffCPUtiMwakptinOffwaketiMsoftirqsOffcpuhistthreadedpidnssSftlockBheldSBpcallsworkq*.SlabratetopoomkillnemleakehasnoopdrsnoopknekpagesnummoveMBap

27、snoopbrkstackfaultsffaultfnapfaulthfaultsVMcMswapinIPNetDeviceDeviceDriversnttlatntsisx、pcnuprpingqdisc-fqtcptoptcpliftcptracrtcpconncttcpccpttcpconnlattcprtransYtcpubnttcpdropsoaccptaocksissolstbytskbliftCpstatootcpsynbltcpvintCpnagletcprtUdpconnectOther:SPAblQnhyprkVMxitshardirqaCriticalstatIttysn

28、oopIlotatICPUScpufreqopensnoopstatsnoopbashreadlinLinuxbcc/BPFTracingIdolsCiltopopnnoop c* jav* nod*fillif filslowr tatnoop php python* vfcount vfsstatcachtat cachtDevice DriversI/O Bridge /I/O ControllerNetwork ControllerHardwareApplicationssysbenchSockets perf bench hping3Iperf ttcp-UnixBench Ched

29、uIerXSystem LibrariesSystem Call InterfaceVarious:ptsMLPerfGPUs TPUsCPUsDRAMHBMI PortJ I Port POrt SMCFansLinux文件系统性能统计工具1.inuxStaticPerformancefoolsAppConfigOperatingSystemVarious:HardwareLinuxPerformanceObservabilityToolsopensnoopstraceOperatingSystemHardware!tracessnstatIsoffatracefilelifepcstatp

30、erfFtrace1.TTngBCCbpftraceext4dist/ext4slower(&forbtrfsnfs,fs,zfs)iostatbiosnoopbiolatencybiotopblktracetcpdump/perfmdflushtiptopI/OControllerI/OBridgeVarious:sar/procdmesgdstatgethostlatencympstatprofilerunqlentopatoppspidstatturbostatshowboostCPUStcplifetcpretransUdpconnectvmstatslabtopfreehardirqsCriticalstatNetworkControllerIDiSitIIDiSkIISiSkPo:PorttiptopperfDRAMnunastatnicstatnetstat

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 在线阅读 > 生活休闲


备案号:宁ICP备20000045号-1

经营许可证:宁B2-20210002

宁公网安备 64010402000986号