SqlServer2005 性能调校之 利用Sql Server Profiler捕捉阻塞事件
在SQLServer2005之前,从不同的来源可以得到很多可用的脚本,来捕获哪些数据库进程产生 阻塞 以及哪些进程被 阻塞 。然而,这些脚本需要手工执行。sp_blocker就是一个实例。 然而,我们可以 利用 Sql Server Profiler ,来自动的捕获被 阻塞 的进程。要用Sql
在SQLServer2005之前,从不同的来源可以得到很多可用的脚本,来捕获哪些数据库进程产生阻塞以及哪些进程被阻塞。然而,这些脚本需要手工执行。sp_blocker就是一个实例。
然而,我们可以利用Sql Server Profiler ,来自动的捕获被阻塞的进程。要用Sql Server Profiler捕获这些进程,我们需要用到Sql Server Profiler 的Blocked Process Report事件。
.Blocked Process Report:这表示一个任务被阻塞的时间已经超出了特定时间长度。这个事件类不包含系统任务或等待非死锁可检测(non-deadlock-detectable)资源的任务。
为了配置Sql Server Profiler,我们必须在SqlServer中为捕获阻塞事件配置一个阈值。
现在我通过一个例子来实现,利用Sql Profiler捕捉阻塞事件:
一.配置Blocked Process Report
1.打开Sql Server Profiler工具 如图:
2.新建跟踪 如图:
3.选择要跟踪的数据实例,如图:
4.选择跟踪模板,为空白,如图:
5.选择Blocked Process Report 事件,如图:
为了配置阈值及生产报表的频度,可使用sp_configure命令来配置Blocked Process Report选项,默认情况下是不产生阻塞进程报表的。在代码实例中,Blocked Process Report配置为5秒钟报告一次阻塞事件,配置之后,再次执行sp_configure验证是否配置成功:
--<span>首先执行以下语句配置 sp_configure </span><span>'</span><span>show advanced options</span><span>'</span>,<span>1</span><span> GO RECONFIGURE GO sp_configure </span><span>'</span><span>blocked process threshold</span><span>'</span>,<span>5</span><span> GO RECONFIGURE GO </span>--<span>然后再执行 sp_configure</span>
如上图,出现如红色的行,证明配置成功了。
二.通过示例里数据库PerformanceDB来实现阻塞事件做个实验。
我们为实验开两个查询窗口:
1.第一个窗口中,执行如下UPDATE语句,这段代码有意令事务保持打开,从而可以触发阻塞事件。
<span>USE PerformanceDB BEGIN TRAN UPDATE dbo.Orders_new SET EmpID</span>=<span>445</span>,Filler=<span>'</span><span>b</span><span>'</span> WHERE orderId=<span>430</span>
2.第二个窗口中,执行相同条件的数据行。由于数据已经被UPDATE 事务阻塞,因此这个查询将会被阻塞
SELECT * FROM dbo.Orders_new WHERE orderId=<span>430</span>
但满足阻塞事件的阈值(在sp_configuer中为5秒)之后,Sql Profiler 会自动捕获每个阻塞事件。对于Sql Profiler中捕获的每个阻塞事件,Sql Profiler为阻塞者记录下执行语句,它会精确的定位哪个进程是阻塞者以及哪个进程被阻塞。这些数据会以XML格式显示,如图(会5秒钟捕捉一次):
配置Sql Profiler来捕捉阻塞事件,使得性能监视以及调校任务比以前容易了很多,我们测量阻塞事件的发生频度以及每天发生的阻塞事件数目,将会提供性能数据的定量检测。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

The performance comparison of PHP array key value flipping methods shows that the array_flip() function performs better than the for loop in large arrays (more than 1 million elements) and takes less time. The for loop method of manually flipping key values takes a relatively long time.

Performance comparison of different Java frameworks: REST API request processing: Vert.x is the best, with a request rate of 2 times SpringBoot and 3 times Dropwizard. Database query: SpringBoot's HibernateORM is better than Vert.x and Dropwizard's ORM. Caching operations: Vert.x's Hazelcast client is superior to SpringBoot and Dropwizard's caching mechanisms. Suitable framework: Choose according to application requirements. Vert.x is suitable for high-performance web services, SpringBoot is suitable for data-intensive applications, and Dropwizard is suitable for microservice architecture.

Effective techniques for optimizing C++ multi-threaded performance include limiting the number of threads to avoid resource contention. Use lightweight mutex locks to reduce contention. Optimize the scope of the lock and minimize the waiting time. Use lock-free data structures to improve concurrency. Avoid busy waiting and notify threads of resource availability through events.

The performance of different PHP functions is crucial to application efficiency. Functions with better performance include echo and print, while functions such as str_replace, array_merge, and file_get_contents have slower performance. For example, the str_replace function is used to replace strings and has moderate performance, while the sprintf function is used to format strings. Performance analysis shows that it only takes 0.05 milliseconds to execute one example, proving that the function performs well. Therefore, using functions wisely can lead to faster and more efficient applications.

In PHP, the conversion of arrays to objects will have an impact on performance, mainly affected by factors such as array size, complexity, object class, etc. To optimize performance, consider using custom iterators, avoiding unnecessary conversions, batch converting arrays, and other techniques.

A way to benchmark the performance of Java functions is to use the Java Microbenchmark Suite (JMH). Specific steps include: Adding JMH dependencies to the project. Create a new Java class and annotate it with @State to represent the benchmark method. Write the benchmark method in the class and annotate it with @Benchmark. Run the benchmark using the JMH command line tool.

According to benchmarks, for small, high-performance applications, Quarkus (fast startup, low memory) or Micronaut (TechEmpower excellent) are ideal choices. SpringBoot is suitable for large, full-stack applications, but has slightly slower startup times and memory usage.
