简体   繁体   English

SQL Server 2008性能问题

[英]SQL Server 2008 Performance Question

I have a table with 30 columns and about 3.4 million records. 我有一个包含30列的表格,大约有340万条记录。 Is it reasonable for SELECT * FROM [Table]; SELECT * FROM [Table]是否合理 to take 8 to 12 minutes to return all 3.4 million results? 需要8到12分钟才能返回所有340万个结果?

If not, where's a good place/resource to begin diagnosing my problem? 如果没有,哪里可以开始诊断我的问题?

Yes, is reasonable. 是的,很合理。 For a system that finely tunned and runing optimally can deliver 3.4 mil rows in about 12 minutes, this is exactly the expected result... 对于经过微调和最佳运行的系统,它可以在大约12分钟内交付340万行,这恰好是预期的结果...

None the less, some places to look for to improve performance: 尽管如此,还是需要一些地方来提高性能:

  • Does the table fit in the buffer pool? 该表是否适合缓冲池? Ie. 就是 do you have enough RAM to store your entire database? 您是否有足够的RAM存储整个数据库? If no, then you're going to hit the disk for IO. 如果否,那么您将在磁盘上进行IO。 Page life expectancy counter is a good indicator. 页面预期寿命计数器是一个很好的指标。
  • How fast is your disk I/O subsystem? 您的磁盘I / O子系统有多快? Are we talking about a 5000 RPM second hand IDE drive or a RamSAN-500? 我们是在谈论5000 RPM二手IDE驱动器还是RamSAN-500? What is the throughput reported by sqliosim ? sqliosim报告的吞吐量是多少 How about perf counters, Avg. 性能计数器的平均值如何? Disk Queue Length, Avg. 磁盘队列长度,平均 Disk Sec/Transfer on the physical disks? 物理磁盘上的磁盘秒/传输? Is it different for Reads vs. Writes? 读与写有区别吗?
  • How fragmented is the table? 表格有多分散? A scan performance is affected first and foremost by read-ahead efficiency and read-ahead size is determined by hobt fragment size. 扫描性能首先受到预读效率的影响,而预读大小则由hobt片段大小决定。 Perhaps you need to optimize the ETL of the table, follow the FastTrack methodology. 也许您需要按照FastTrack方法优化表的ETL。
  • any contention going on? 有什么争论吗? Have you measured lock wait times? 您测量过锁等待时间了吗? Perhaps snasphot isolation can aleviate the problem. 隔离快照可能可以缓解此问题。
  • Can the client receive the 3.4 mil rows in time? 客户能否及时收到340万行? Does the server block on client buffers availability? 服务器是否阻止客户端缓冲可用性? Again, wait stats can indicate this. 同样,等待统计可以表明这一点。

Another good place to start is to follow the Wait and Queues methodology. 另一个不错的起点是遵循“ 等待和排队”方法。

It's most likely that SQL server is doing its best to get the data you asked for. SQL Server很可能会尽力获取所需的数据。 It's not unreasonable to assume at least 1K/record for 30 columns. 假设30列的每条记录至少1K并非没有道理。 3.4M x 1K = 3.4Gb. 3.4M x 1K = 3.4Gb。

Just reading 3.4Gb from the disk could take minutes on an average machine (do not forget that this is not just reading, there's obviously some SQL processing overhead in it. 在普通计算机上,仅从磁盘读取3.4Gb可能要花费几分钟的时间(请记住,这不仅是读取,而且其中显然还有一些SQL处理开销。

But of course in a real world scenario you don't want to retrieve all the data... 但是,当然,在现实世界中,您不想检索所有数据...

The best place to start diagnosing your problem is to determine whether you have a problem at all. 开始诊断问题的最佳位置是确定您是否有问题。 Set a specific, measurable, business-oriented performance goal, and define exactly how long you think is reasonable for returning the data. 设定特定的,可测量的,面向业务的性能目标,并准确定义返回数据的合理时间。

If your answer is 8-12 minutes, then you don't have a problem, which is always a good thing. 如果您的回答是8到12分钟,那么您就没有问题,这总是一件好事。

If your answer is less than that, then you now know that you have a problem, and how big the problem is (if you said 5 minutes then it's maybe not such a big problem, if you said 10 seconds then it's a much bigger issue). 如果您的回答不那么多,那么您现在知道自己有问题以及问题有多严重(如果您说5分钟,那么这可能不是一个大问题,如果您说10秒,那么这是一个更大的问题)。 In this case, you'll probably want to start looking at the database performance counters to see whether it's got CPU/IO/memory/network bottlenecks, and looking at the execution plan for the query to see whether it could be improved by indexes (though this is unlikely for a SELECT *). 在这种情况下,您可能需要开始查看数据库性能计数器,以查看是否存在CPU / IO /内存/网络瓶颈,并查看查询的执行计划,以查看是否可以通过索引来改善它(尽管这对于SELECT *不太可能。

There are so many questions that could be asked relating to disk IO, size of the columns and other setup related things. 关于磁盘IO,列的大小以及其他与设置有关的事情,可能要问的问题太多了。 Bottom line unless you are on a really really slow disk and slow network it should not take 12 minutes. 最重要的是,除非您使用的是非常慢的磁盘和慢速的网络,否则应该不需要12分钟。

The first place to look is at the Execution plan. 首先要看的是执​​行计划。 This should give you an idea of how SQL Server is handling things. 这应该使您了解SQL Server如何处理事情。

Couple things I would ask to better troubleshoot? 我想问几件事以更好地解决问题? Is there a primary key? 有主键吗? Is it clustered? 它是集群的吗? Is there an order by? 有命令吗?

It might be more interesting to asses the queries your system is actually running. 评估系统实际正在运行的查询可能会更有趣。 The Profiler tool that comes with SQL Server can make a log of all the queries your system is running. SQL Server附带的Profiler工具可以记录系统正在运行的所有查询。 Let it run over a given period (assuming you have a good amount of extra disk space) and it will record what queries are being run, and the parameters given. 让它在给定的时间内运行(假设您有大量的额外磁盘空间),它将记录正在运行的查询以及给定的参数。 It will also tell you how long they all took to execute. 它还会告诉您它们都花了多长时间执行。

Looking at this and figuring out what queries are using up your CPU time will help you figure out where to go for performance tuning - for instance, If Query A takes 60 seconds to run, and runs only once a day, it might have big impact on that specific app to tune it, but tuning that one query wont make your SQL Server faster. 查看此信息并弄清楚哪些查询正在占用您的CPU时间,这将帮助您找出性能调整的目标-例如,如果查询A需要60秒才能运行,并且每天仅运行一次,则可能会产生很大的影响在该特定应用上进行调优,但调优一个查询不会使您的SQL Server更快。 But if Query B takes 2 seconds to run and runs 4,000 times per day, tuning it may have a bigger overall impact. 但是,如果查询B需要2秒钟才能运行并且每天运行4,000次,则对其进行调整可能会产生更大的总体影响。

Often adding relevant indexes and performance tuning your "big offender" queries can make a very serious positive impact on performance. 通常,添加相关索引和性能调整“大罪犯”查询可能会对性能产生非常严重的积极影响。 What the profiler shows you about who those queries are might surprise you. 探查器向您显示的有关那些查询是谁的信息可能会让您感到惊讶。

Reasonable compared to what? 相比之下合理吗?

  1. How wide are the rows? 行有多宽?
  2. How fast is your CPU? 您的CPU多快?
  3. How much RAM do you have? 你有多少RAM?
  4. Is the table already in RAM when you start the query? 启动查询时表已经在RAM中了吗?
  5. Are you delivering the results over a network? 您是否正在通过网络传递结果? If so, how fast is it? 如果是这样,速度有多快?
  6. How fast is the client that's retrieving the rows? 客户端检索行的速度有多快?
  7. How fast are your disks? 您的磁盘有多快?
  8. How fragmented is the table? 表格有多分散?
  9. Is the DB machine doing anything else at the same time? DB机是否在同时执行其他任何操作?

I agree with you, I just brought back 20 million rows of data from a SQL 2008 server in less than 3 minutes - the hardware cost less than the SQL license. 我同意您的看法,我仅用了不到3分钟的时间就从SQL 2008服务器中取出了2000万行数据-硬件成本比SQL许可证还低。

Unless your hardware / network really sucks then there is a performance gain to be made somewhere. 除非您的硬件/网络真的糟透了,否则某个地方的性能将有所提高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM