SQL Server 压力测试

2019-03-02 23:55|来源: 网路

Stress Testing Your SQL Server Databases - A Systematic Approach

Stress Testing your SQL Server environments is a practice that can yield great benefits. Stress Testing can be used for performance tuning, to uncover bottlenecks, and for capacity planning among other things. In this article we will use the terms 'Load Testing' and 'Stress Testing' interchangeably, even though by definition they are different. So for the sake of this article 'Load Testing' or 'Stress Testing' is simply running a large number of statements/transactions against a SQL Server database from various connections or threads - all to give the database server a good workout. Lastly, this article is not about HOW one physically throws a large number of statements at a server to stress test it, there are 3rd party tools on the market and available code on the web to help you do that. Instead we'll discuss what variables are needed and what questions need to be answered to ensure a successful and productive stress test environment.

WHY You Stress Test Drives HOW You Stress Test

The reasons for Stress Testing vary. You may be trying to determine the apparent cause of poor performance on a production server, or trying to plan for an increase of users, or trying to workout a new application that is not yet "live" to determine if it will be able to handle a production load. The reasons vary, but your specific reason will drive your approach to stress testing. For instance, your approach will vary greatly between a pre-production test and one for a live server.

Production Environments

If it is a performance problem in a production environment that you're dealing with, you can first try to determine your problem using Performance Counters sampled throughout your busy times of day (if possible). I realize that this is a Stress Testing article and I'm starting with a non-Stress Test approach, but in the real-world it is easier to start with performance monitoring before trying to gain approval for stress testing a production server. By comparing the gathered performance counter values with generally accepted thresholds you may be able to figure out your problem without running a Stress Test. We will cover some Microsoft listed thresholds later in the article. You may want to perform your monitoring several times during the week, as the load on Monday might be different from Wednesday's load.

One more note about stand-alone monitoring before we move on to our main focus: at times it can be beneficial to gather samples over a 24 hour period or even just at night if day-time sampling is forbidden. Sometimes your late-night SQL Server Jobs and back-ups can provide some insight. For instance, you may be running back-ups from across the network and notice that your Network Interfaces have less than favorable throughput.

If you can't take samples during peak times in your production environment, you will be best served by running off-hour stress tests using the tool of your choice to create the load. In this case you are still working out the hardware/software configurations on the server in question and capturing performance counter values that can lead you to the source of the problem if one exists. If the captured performance counter values do not lead to insight, then concentrating on the execution times of application stored procedures and scripts may help uncover the problem - perhaps dead-locking, or simply bad indexing. If needed, you can open up SQL Profiler for in-depth tracing information while your stress test is running.

If you're looking to see how your production environment will scale with an increase in users, then stress testing is the way to go. You can dial-up virtual users to hammer your server and monitor its response. In this scenario, as well as all others, you want to gather Performance Monitor samples and execution times. This is also a great way to validate the need for new hardware, walking into your boss' office with a stress test report shows that you have done your homework.

Non-Production Environments

For pre-production tests or any tests that won't be held in a live production environment, Stress Testing your database can be invaluable. You will want to run your tests in a production-like environment. Simulating that can be difficult, but with automated stress testing packages you can attempt to mimic the amount of load that your servers will face and scale that load up to really make your server work. Commercial Stress Testing applications like Agilist's SQL Stress Test or Quest's Benchmark Factory enable you to create a large number of virtual users that will execute the SQL commands of your choice. A good Stress Testing package will create separate threads for each virtual user and will avoid connection pooling. In a non-production environment you typically have a lot of freedom, nevertheless, there are still questions that you will want to think about for testing in both Production and Non-Production environments.

Pre-Stress Test Questions

Here are some questions to ask prior to running your tests:

  • How many virtual users will you want to test with? If this will be the back-end of a web or software application, then what is the maximum number of concurrent users that will be using it?
  • What are the main SQL statements and procedures that you will execute during the test? If you are testing the procedures called by an application then answering this question should not be difficult. Some third party Stress Testing Tools like Agilist's, will even record the sql statements being executed by users while they use the web or software front-end.
  • How long should each statement or procedure take to execute? I.e. what would be an acceptable return time?
  • If this is a pre-production database, does it contain a fair amount of data so that your tests are working in a production-like environment?
  • What location do you want to run the Stress Test and monitoring from? If monitoring from across the network you will incur some DCOM hit, if monitoring locally on the server you will eat up marginal resources.

A Good Stress Test is Measurable

Throwing a hail storm of statements at your SQL Server is only part of a productive Stress Test. First and foremost, the test must be measurable. So while giving our server a workout we must gather performance related statistics. Usually we'll gather Performance Counters and if possible the actual execution times of the statements themselves. You can gather Performance Counter statistics using Microsoft's Performance Monitor (PerfMon) or the 3rd party tool of your choice.

For these statistics to mean anything we must be able to measure them against something, usually these "somethings" are baselines that we have created some time in the past or accepted thresholds. Baselines are simply previously saved results that we can compare against. We also can compare our tests against thresholds listed by Microsoft and industry professionals as mentioned previously. You can create a baseline the first time you run a test, simply save your results and now you magically have a measurable baseline that can be recalled for future comparisons. As time goes by you will want to periodically create baselines for comparison purposes. Baselines are also great for trending and determining growth rates.

Which Performance Counters To Use?

When choosing Performance Counters we don't just want to know how our SQL Server software is performing, we also want to know how our hardware and network is performing. The best list of core counters that I have come across, and have been using for years, come from an article by Brad McGehee entitled "How to Perform a SQL Server Performance Audit ". I experiment with some other counters but always use the ones mentioned in the article as the foundation. The counters are:

  • Memory: Pages/sec
  • Memory: Available Bytes
  • Network Interface: Bytes Total/Sec
  • Physical Disk: % Disk time
  • Physical Disk: Avg. Disk Queue Length
  • Processor: % Processor Time
  • System: Processor Queue Length
  • SQL Server Buffer: Buffer Cache Hit Ratio
  • SQL Server General: User Connections
Which Thresholds To Use?

After monitoring your server, you will need to measure your captured counter values against trusted thresholds so that you know whether or not a problem may be at hand. I compiled a list of thresholds from Microsoft resources such as TechNet and others that match the list of Counters above. Below are the MS values along with some comments. When comparing your values to these you should always ask yourself if the value that you have collected was sustained over a period of time or if was just a spike - sustained values are obviously much more appropriate for comparison.

  • Memory: Pages/sec: If counter value is consistently > 5 you may likely have a memory issue.
  • Available Bytes: Values < 10 MB should raise a serious red flag for you.
  • Network Interface: Bytes Total/sec: Microsoft simply advises that if you notice this value dropping it may indicate network problems. By rule of thumb you can use a value of half of the available network interface bandwidth as being acceptable. So for a 100 MBS network adaptor, the value of the Bytes Total/sec performance counter can be 50 MBS or greater.
  • Physical Disk: Avg Disk Queue Length: You will need to calculate this value based on the number of physical drives. It is simply the monitor value / # of disks. A value greater than 2 might indicate an I/O bottleneck. The number of waiting I/O requests should be sustained at no more than 1.5 to 2 times the number of spindles making up the physical disk.
  • Physical Disk: % Disk time: The recommended numbers for this seem to vary, if the value is greater than 50% you should be concerned and investigate more. If the value is sustained above 80% it is a serious problem and you may have a memory leak or I/O issue at hand.
  • Processor: % Processor Time: Values in excess of 80% processor time per CPU are generally deemed to be a bottleneck.
  • System: Processor Queue Length: A sustained queue length > 2 (per processor), generally indicates a processor bottleneck. For instance, if you have 2 processors then a value of 4 or less is usually acceptable.
  • SQL Server Buffer: Buffer Cache Hit Ratio: A rate of 90 percent or higher is OK. The closer to 100% the better. Less than 85% indicates a problem.
  • SQL Server General: User Connections: This one varies of course. It should be tracked though so that you can determine what is "normal" for your environment. With this you can spot trends that may signal growing demand, or you may use it to explain spikes in other counters.

Additional Threshold and Monitoring Resources

There are many good articles that deal with monitoring activity and thresholds. Listed below are some worthwhile resources:

  • "Performance Monitoring - Basic Counters" - Steve Jones 
    http://www.sqlservercentral.com/columnists/sjones/performancemonitoringbasiccounters.asp
  • Monitoring Disk Activity - Microsoft 
    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sag_mpmonperf_19.mspx?mfr=true
  • Monitoring Memory - Microsoft 
    http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/prork/prec_evl_bzcl.mspx?mfr=true
  • Troubleshooting Performance in SQL Server 2005 - Microsoft 
    http://www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx
  • Performance Tuning Checklist 4.5 (NT Based Systems) - Microsoft 
    http://www.microsoft.com/technet/prodtechnol/bosi/maintain/optimize/bostune.mspx

Conclusion

There are many things to think about before stress testing your SQL Server databases. I hope that this article outlined many of those items in a manner that enables you to hit the ground running for your stress testing endeavors. A well-planned stress test can be extremely beneficial, among other things it enables you to test application/procedure/database performance before going into production, troubleshoot performance, and plan for the future.

Anthony Bressi is owner of Agilist Technologies Inc. which specializes in software for DBA's and SQL Server developers. Mr. Bressi has over 9 years of hands-on experience in the Microsoft SQL Server development environment.


转自:http://www.cnblogs.com/Amaranthus/archive/2011/09/16/2178596

相关问答

更多
  • SQL Server被设计为使用尽可能多的内存,以便通过在内存中缓存大量内容来提高性能。 建议使用专用的SQL Server机器,这使得这是一个非常有效的方法,因为它不会期望别人需要内存。 所以你不应该担心这个; 这很正常。 也就是说,如果你使用的是开发机器而不是实时环境,那么你可能希望限制内存的数量来阻止你的盒子被占用。 在这种情况下,最简单的方法是打开SQL Server Management Studio,右键单击服务器并选择“属性”,然后在“内存”选项卡上可以设置最大服务器内存。 SQL Serve ...
  • 在将postgresql从一个版本迁移到另一个没有工具的版本中,我只使用了一个工具,即unix的sed。 我的建议是简单地导出sql。 清理导出客户端特定的偏心(通常在注释中),然后尝试将其导入到sql数据库中,看看会发生什么。 错误是你的准则。 使用sed来通过mssql文件并输出修正错误的postgres sql文件。 一旦你在功能环境中,看看数据本身,有些事情可能不是你期望的。 经过测试和进一步改正,你很好走。 In migrating postgresql from one version to a ...
  • 创建安装程序,您可以检查是否已安装Sql server compact edition。 安装程序安装紧凑版本的选项很少。 从Windows更新或添加项目的dll。 阅读如何:使用应用程序部署SQL Server Compact 4.0数据库以获取更多信息。 不要求在服务器上安装sql server。 Create installer and you can check whether Sql server compact edition already installed or not. there ar ...
  • 登录是服务器级别的对象。因此,当您将实例从一台服务器迁移到另一台服务器或升级时,您也必须移动登录名,否则分配给这些登录名的用户将成为孤儿.. 微软提供了一个Storedproc,它可以帮助你完成这个过程。 此KB 如何传输SQL Server实例之间的登录名和密码包含一步一步的详细信息,如何做到这一点..我已包括在这里,以避免链接腐烂.. 1.打开一个新的查询编辑器窗口,然后运行以下脚本。 USE master GO IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL ...
  • 感谢您平时的快速回复。 当我决定深入研究Mitch Wheat的建议来验证SQL Server的配置时,我设法解决了这个问题。 事实证明问题出在SQL Server配置上。 这个优秀的网站也有解决方案,谢谢! 非常感激! 解决我的问题是这个。 (链接) thanks for your usual fast replies. I've managed to work a solution out when I decided to dig deeper into Mitch Wheat's recommend ...
  • 您应该查看查询执行计划 - 注意索引扫描或表扫描,您想要搜索。 在SSMS中 - >查询 - >包括实际执行计划。 再次运行查询,您将在选项卡中看到结果。 您看到您的结果正在优化 - 这也可能在生产中发生。 但是,您的查询也可能必须与其他生产系统竞争,这可能会不时地从缓存中删除您的查询结果。 http://www.sql-server-performance.com/tips/query_execution_plan_analysis_p1.aspx You should look at the query ...
  • 你不能使用简单的查询来缓存数据(正如你所提到的) 您需要使用不同的查询,这需要花费时间(至少几秒到几分钟)。 此外,您的查询应读取大量数据并将大量/少量数据返回给客户端。 我的建议是这样做的: 创建一个包含2列的表(id int, query nvarchar(max)) 。 使用不同的查询填充表格,简单到复杂,快速耗时。 您可能需要数百或数千个different查询。 编写一个多线程程序,每个线程随机读取不同行的查询并执行它。 您可能需要数百或数千个线程来查询数据库。 如果您的数据库是OLTP,并且用户更 ...
  • Azure提供常见Azure订阅和服务限制,配额和约束的列表。 您可以参考文档https://azure.microsoft.com/en-us/documentation/articles/azure-subscription-service-limits/来了解这些限制。 在Networking Limits部分中,VM的并发TCP连接有一个限制,默认限制为500K,请参见下图: 我搜索了MongoDB与SQL Server 2008的第三方性能摊牌报告,请转到http://blog.michaelck ...
  • 经过相当多的研究后,我开始使用jmeter进行大规模的REST调用。 这样我就可以在数据库上创建受控负载。 我使用node-inspector和native mongodb profiling进行分析。 对于那些喜欢对DB John Page的POCDriver(模拟客户端)进行更“直接”测试的人: https : //github.com/johnlpage/POCDriver可能很有趣。 配置文件可视化(来自日志文件)可以使用以下命令完成: https : //github.com/ruecksties ...