SqlServer performance testing and optimization tools and detailed performance test SqlServer Optimizer uses Details

Original: SqlServer performance testing and optimization tools Details

 

Tools Summary    

    If your database application system, there are a large number of tables, views, indexes, triggers, functions, stored procedures, sql statement, and so on, and poor performance, and hard to force you have to optimize it, then how can you do ? Brother to teach you, first of all you need to know where is the problem? If you want to know where the problem, and find him, we can use this article to tell the performance testing tool --sql server profiler (in sql installation files - Performance Tools --sql server profiler)

    If you know where it problems, but if you are peerless master, of course, may be the key straight in, writing sections of the code to deal with to get rid of, but if you can not, you can not, then it does not matter, you can use the power of brother to you Solve the problem. Give your brother a secret martial arts Heart is --- Database Engine Tuning Advisor (in sql installation files - Performance Tools - Database Engine Tuning Advisor)

sql server profiler function 

    This tool Bike Nan also Conan, because he can detect the database every move, even if you do not move him, he is also watching you, he was very cheap. He not only monitor, but also monitored in great detail, how detailed one will say, also monitors the content is recorded in the database or file, complain to your wife say where you put the database performance out of how bad, but he also will give you a good record, good and bad of course, you need to analyze, in fact, he is also a very Conan 2.

Database Engine Tuning Advisor functionality 

    This martial arts, is superior martial arts. Like Qian Kun Da Nuo Zhang Wuji, first accept the sql server profiler detected the sql, views, stored procedures, data structures, etc., and then he analyzes himself, and then two laps in his arms, felt turn hey, give the power to throw a more energetic, better indexing, statistics, etc. recommended partition information. Let you bear, happly death. . Below brother to listen to you talk about our very first 2 Conan.

Use of sql server profiler

Open the main menu --sqlserver several performance tools --- --- >> sql server profiler; stupid gentile, did not find? Brother while waiting for you, give you a map to open Zhang after he let you see. .

Then File - New Tracking - Tracking Properties window display

That is TextData% First select a filter monitoring. That% is a wildcard, which means that his opening statement select screening. Of course, this can easily define your own, such as update%, delete% .....

That does not exclude the row containing the value to be put on, and then determine the run. And then run a select in the database. You will find that he detected it.

Each column of this right from the start EventClass, I tell you about is what.

Event classification, applied for a statement, the application name, operating system user, database user, cpu occupancy rate, the number of database read and write database once said, when executing the script with the application process ID, start time, end time.

Select the event, you put the mouse put up, he notes below Chinese. A good look at yourself, and then according to your own need to check up event.

Then file - >> Save As, you can save the monitored data to a file or data table.

analysis:

1. Find the longest query

Under normal circumstances, there is reason for the longest time query query is the most affecting performance. It not only takes a lot of time database engine, but also a waste of system resources, but also affect the speed of the interactive database application system. During which data can be used to optimize application system, first find him, their optimization, when creating a track, hook TSQL-SQL: BatchCompleted with Stored Procedures-RPC:. Completed. So you can find out the maximum amount of time a query and analyze optimization.

select TextData, Duration, CPU from <tracking tables> 
WHERE the EventClass = 12 - 12 represent equal BatchCompleted events 
and CPU <(0.4 * Duration) - NOTE If cpu occupancy time, less than 40% sql statement execution time, the statement wait too long

2. The most system resources query

就是占用cpu时间,跟读写IO的次数。建议事件包含Connect、Disconnect、ExistingConnection、SQL:BatchCompleted、RPC:completed,列包含writes,reads,cpu。

3.检测死锁

在访问量,并发量都很大的数据库中,如果设计稍不合理,就有可能造成死锁,给系统性能带来影响。事件包含:RPC:Starting、SQL:BatchStarting、Lock:DeadLock(死锁事件)、Lock:DeadLockChaining(死锁的事件序列)。

使用数据库引擎优化顾问分析解决数据库性能

打开系统主菜单--sqlserver几---性能工具--->>数据库引擎优化顾问,界面如下

 

 

打开之后,你在上一个工具中保存的的文件,你就在这里的工作负荷中选文件,表就选表。选后别急。

把要分析的数据库跟数据库的表选上,也就是下面的用于工作负荷分析的数据库选择,跟下面的要优化的数据库和表,慢慢扣,把他选对。

然后选则你想要的优化选项

根据需要,选上,高级选项里面通常可以默认。确定。。

然后点左上角有一个开始分析。

分析完成

工具概要    

    如果你的数据库应用系统中,存在有大量表,视图,索引,触发器,函数,存储过程,sql语句等等,又性能低下,而苦逼的你又要对其优化,那么你该怎么办?哥教你,首先你要知道问题出在哪里?如果想知道问题出在哪里,并且找到他,咱们可以借助本文中要讲述的性能检测工具--sql server profiler(处在sql安装文件--性能工具--sql server profiler)

    如果知道啦问题出现在哪里,如果你又是绝世高手,当然可以直中要害,写段代码给处理解决掉,但是如果你不行,你做不到,那么也无所谓,可以借助哥的力量给你解决问题。哥给你的武功的秘诀心法是---数据库引擎优化顾问(处在sql安装文件--性能工具--数据库引擎优化顾问)

sql server profiler功能 

    此工具比柯南还柯南,因为他能检测到数据库中的一举一动,即便你不动他,他也在监视你,他很贱的。他不但监视,还监视的很详细,有多详细一会再说,还把监视的内容记录到数据库或者是文件中,给你媳妇告状说你把数据库哪里的性能搞的多么不好,不过他也会把好的给你记录下来,好与不好这当然需要你来分析,其实他也是个很2的柯南。

数据库引擎优化顾问功能 

    此武功,乃上乘武功。像张无忌的乾坤大挪移,先是接受sql server profiler检测出来的sql,视图,存储过程,数据结构等等,然后他再自己分析,然后再在怀中转两圈,感觉自己转的差不多啦,就给抛出来个威力更炫,更好的索引,统计,分区等等建议信息。让你承受不住,happly致死。。下面听哥给你先讲讲咱们的很2柯南。

sql server profiler的使用

打开系统主菜单--sqlserver几---性能工具--->>sql server profiler;笨样儿,找到没?哥等你会儿,给你上张打开他后的图,让你看看。。

然后文件--新建跟踪--显示跟踪属性窗口

首先那个select%是个筛选监测的TextData。那个%是个通配符,他的意思就是筛选select开口的语句。当然这你自己可以随便定义,如update%,delete%....。

把那个排除不包含值的行也给带上,然后确定,运行。然后在数据库中运行一句select。你会发现他检测到啦。

每列以此向右,从EventClass开始,我给你讲讲都是什么。

事件分类,申请了语句,应用程序名称,操作系统用户,数据库用户,cpu占用率,读数据库次数,写数据库次说,执行脚本用时,应用程序进程号,开始时间,结束时间等。

事件选择,你就把鼠标放上去,他下面有中文的注释。自己好好看看,然后根据你自己的需要把事件勾选上来。

然后文件-->>另存为,可以把这些监测到的数据保存为文件,或数据表。

分析:

1.查找持续时间最长的查询

一般情况下,最长查询时间的查询语句就是最影响性能的原因存在。它不仅占用数据库引擎大量的时间,还浪费系统资源,还影响数据库应用系统的交互速度。再对数据用应用系统进行优化时,先找出他,对其优化,在创建跟踪时,勾上TSQL-SQL:BatchCompleted.跟Stored Procedures-RPC:completed。这样就能找出来这个最长时间查询然后对其进行分析优化。

select TextData,Duration,CPU from <跟踪的表>
where EventClass=12 -- 等于12表示BatchCompleted事件
and CPU<(0.4*Duration)  --如果cpu的占用时间,小于执行sql语句时间的40%,说明该语句等待时间过长

2.最占用系统资源的查询

就是占用cpu时间,跟读写IO的次数。建议事件包含Connect、Disconnect、ExistingConnection、SQL:BatchCompleted、RPC:completed,列包含writes,reads,cpu。

3.检测死锁

在访问量,并发量都很大的数据库中,如果设计稍不合理,就有可能造成死锁,给系统性能带来影响。事件包含:RPC:Starting、SQL:BatchStarting、Lock:DeadLock(死锁事件)、Lock:DeadLockChaining(死锁的事件序列)。

使用数据库引擎优化顾问分析解决数据库性能

打开系统主菜单--sqlserver几---性能工具--->>数据库引擎优化顾问,界面如下

 

 

打开之后,你在上一个工具中保存的的文件,你就在这里的工作负荷中选文件,表就选表。选后别急。

把要分析的数据库跟数据库的表选上,也就是下面的用于工作负荷分析的数据库选择,跟下面的要优化的数据库和表,慢慢扣,把他选对。

然后选则你想要的优化选项

根据需要,选上,高级选项里面通常可以默认。确定。。

然后点左上角有一个开始分析。

分析完成

Guess you like

Origin www.cnblogs.com/zhang1f/p/11953695.html