sql-server-2005 - 如何在大型 SQL Server 查询中使用多核?

标签 sql-server-2005

我有两台 SQL Server,一台用于生产,另一台用作存档。每天晚上,我们都有一个 SQL 作业运行并将当天的生产数据复制到存档中。随着我们的成长,这个过程需要的时间越来越长。当我观察运行归档进程的归档服务器的利用率时,我发现它只使用了一个内核。而且由于这个盒子有八个核心,这是一种巨大的资源浪费。作业在凌晨 3 点运行,因此它可以免费使用它可以找到的任何和所有资源。

因此,如果弄清楚如何构建 SQL Server 作业以便它们可以利用多个内核,我需要做什么,但我找不到任何关于解决此问题的文献。我们正在运行 SQL Server 2005,但如果 2008 解决了这个问题,我当然可以插入升级。

最佳答案

您是否有自动维护计划来更新统计信息、重建索引等?如果没有,SQL Server 可能仍在根据较小表的旧统计信息构建其查询计划。

如果满足某些条件,SQL Server 会自动生成并行查询计划。来自 article on MSDN :

1.Is SQL Server running on a computer with more than one microprocessor or CPU, such as a symmetric multiprocessing computer (SMP)? Only computers with more than one CPU can use parallel queries.

2.What is the number of concurrent users active on the SQL Server installation at this moment? SQL Server monitors CPU usage and adjusts the degree of parallelism at the query startup time. Lower degrees of parallelism are chosen if CPU usage is high.

3.Is there sufficient memory available for parallel query execution? Each query requires a certain amount of memory to execute. Executing a parallel query requires more memory than a nonparallel query. The amount of memory required for executing a parallel query increases with the degree of parallelism. If the memory requirement of the parallel plan for a given degree of parallelism cannot be satisfied, SQL Server decreases the degree of parallelism automatically or completely abandons the parallel plan for the query in the given workload context and executes the serial plan.

4.What is the type of query executed? Queries heavily consuming CPU cycles are the best candidates for a parallel query. For example, joins of large tables, substantial aggregations, and sorting of large result sets are good candidates. Simple queries, often found in transaction processing applications, find the additional coordination required to execute a query in parallel outweigh the potential performance boost. To distinguish between queries that benefit from parallelism and those that do not benefit, SQL Server compares the estimated cost of executing the query with the cost threshold for parallelism value. Although not recommended, users can change the default value of 5 using sp_configure.

5.Is there a sufficient amount of rows processed in the given stream? If the query optimizer determines the number of rows in a stream is too low, it does not introduce exchange operators to distribute the stream. Consequently, the operators in this stream are executed serially. Executing the operators in a serial plan avoids scenarios when the startup, distribution, and coordination cost exceeds the gains achieved by parallel operator execution.



其他因素:

Is SQL Server configured to have affinity to a single processor?

Is the max degree of parallelism option is set to 1?

- 编辑 -

你试过分析这个过程吗?看到 SQL Server 生成的查询计划会很有趣。

你有可以发布的示例代码吗?

如果您有自动夜间备份作业,是否可以简单地将备份恢复到存档?

关于sql-server-2005 - 如何在大型 SQL Server 查询中使用多核?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2913180/

相关文章:

sql-server - 在 SQL Server 中创建审核触发器

sql - 今天最新和昨天最新记录

sql-server-2005 - 我的 SQL 命令有什么问题?

sql - 连接字符串时VARCHAR(MAX)表现得很奇怪

sql - IF EXISTS 不工作

c# - 存储过程 : pass XML as an argument and INSERT (key/value pairs)

sql - 如何使用 sql server management studio 将 blob 插入数据库

sql - SQL Server 2005 中 VARBINARY 字段的大小

sql-server - 数据库和模式之间的区别

sql - SQL触发器: On update of primary key,如何确定哪个 “deleted”记录对应于哪个 “inserted”记录?