nginx静态资源 性能

Performance tuning is one of the most important and critical tasks that the SQL Server Database Administrator performs on a daily basis to keep a SQL Server running in a healthy state, by identifying the performance bottlenecks and fixing the main cause of these problems.

性能调优是SQL Server数据库管理员每天执行的最重要和关键的任务之一,通过识别性能瓶颈并解决这些问题的主要原因,以使SQL Server保持正常运行。

The best and safest way to tune your queries is to run them in a development environment. However, in most cases, the result you get from the development environment is completely different from the result that you get from production, giving you a misleading or even wrong indications about the query performance. This can be true even though you copy the same database with all indexes and statistics from the production environment to development.

调整查询的最佳和最安全的方法是在开发环境中运行它们。 但是,在大多数情况下,从开发环境中获得的结果与从生产环境中获得的结果完全不同,从而给您关于查询性能的误导甚至错误的指示。 即使您将具有所有索引和统计信息的相同数据库从生产环境复制到开发环境,这也可能是正确的。

These differences in the results mainly occur due to the hardware gap between the development environment and the production one, especially the Processor core counts and the server memory. These variables are involved heavily in the SQL Server Query Optimizer decision while creating the query execution plan, and therefore the parallel operators will not work in the same way.

结果的这些差异主要是由于开发环境和生产环境之间的硬件差距所致,尤其是处理器核心数和服务器内存。 这些变量在创建查询执行计划时会大量涉及SQL Server Query Optimizer决策,因此并行运算符将无法以相同的方式工作。

Planning to have identical development and production SQL Servers isn’t feasible, in most cases,, due to the cost that will be required in a server using for testing only. Then, in light of this, how could we over come this challenge and at least simulate production SQL queries in the development environment?

在大多数情况下,计划具有相同的开发和生产SQL Server是不可行的,因为在仅用于测试的服务器中将需要一定的成本。 然后,鉴于此,我们如何克服这一挑战并至少在开发环境中模拟生产SQL查询?

The undocumented command DBCC OPTIMIZER_WHATIF is a potential solution

未记录的命令DBCC OPTIMIZER_WHATIF是潜在的解决方案

The DBCC OPTIMIZER_WHATIF command, introduced in SQL Server 2005, allows you to simulate a production environment by hypothetically altering the SQL Server Query Optimizer perception of the SQL Server resources. What is required from you is to pass the logical CPU cores, the RAM amount and the Cost Threshold for Parallelism of the production environment to the DBCC OPTIMIZER_WHATIF command, and combine that command with the query to be tuned on the development SQL Server, you will get a near real estimates of the query execution plan on the production SQL Server. As the DBCC OPTIMIZER_WHATIF command changes how the SQL Server Query Optimizer see the server available resources.

SQL Server 2005中引入的DBCC OPTIMIZER_WHATIF命令允许您通过假设地更改SQL Server资源对SQL Server查询优化器的理解来模拟生产环境。 您需要将逻辑CPU内核,RAM量和生产环境的并行成本阈值传递给DBCC OPTIMIZER_WHATIF命令,并将该命令与要在开发SQL Server上进行调优的查询结合起来,您将获得生产SQL Server上查询执行计划的近乎真实的估计。 随着DBCC OPTIMIZER_WHATIF命令更改SQL Server查询优化器查看服务器可用资源的方式。

To see what information is available about this undocumented command, we will use the DBCC HELP command along with the Trace Flag 2588.

若要查看有关此未记录命令的可用信息,我们将使用DBCC HELP命令以及跟踪标志2588。


DBCC TRACEON (2588) WITH NO_INFOMSGS
DBCC HELP ('OPTIMIZER_WHATIF') WITH NO_INFOMSGS

The only information that will be retrieved about DBCC OPTIMIZER_WHATIF are the results below:

以下结果将是唯一有关DBCC OPTIMIZER_WHATIF的信息:

As you can see in the results, you need to provide it with the property name or number and the value for that property. Keep in your mind when using the property names in the DBCC OPTIMIZER_WHATIF command, that they are case sensitive, even in a case of insensitive installation. No error message will be shown if an invalid name or value is passed in, so you should be careful.

从结果中可以看到,您需要为其提供属性名称或编号以及该属性的值。 使用DBCC OPTIMIZER_WHATIF命令中的属性名称时,请记住,即使在不敏感安装的情况下,它们也区分大小写。 如果传入了无效的名称或值,则不会显示任何错误消息,因此请务必小心。

The valid properties that can be overridden using the DBCC OPTIMIZER_WHATIF command are:

可以使用DBCC OPTIMIZER_WHATIF命令覆盖的有效属性是:

  • Property Name: CPUs, Property number : 1. 属性名称:CPU,属性编号:1。
  • Property Name: MemoryMBs, Property number : 2. 属性名称:MemoryMBs,属性编号:2。
  • Property Name: Bits, Property number : 3. 属性名称:位,属性编号:3。
  • Property Name: ParallelCardThreshold, Property number : 4. 属性名称:ParallelCardThreshold,属性编号:4。
  • Property Name: ParallelCostThreshold, Property number : 5. 属性名称:ParallelCostThreshold,属性编号:5。
  • Property Name: ParallelCardCrossProd, Property number : 6. 属性名称:ParallelCardCrossProd,属性编号:6。

In SQL Server 2012 a new four properties were added to that command:

在SQL Server 2012中,向该命令添加了新的四个属性:

  • Property Name: LowCEThresholdFactorBy10, Property number : 7. 属性名称:LowCEThresholdFactorBy10,属性编号:7。
  • Property Name: HighCEThresholdFactorBy10, Property number : 8. 属性名称:HighCEThresholdFactorBy10,属性编号:8。
  • Property Name: CEThresholdFactorCrossover, Property number : 9. 属性名称:CEThresholdFactorCrossover,属性编号:9。
  • Property Name: DMLChangeThreshold, Property number: 10. 属性名称:DMLChangeThreshold,属性编号:10。

The current status of the properties that can be changed by the DBCC OPTIMIZER_WHATIF command can be viewed by passing the Status statement or number zero to that command as a single parameter. Before that, we should turn on the Trace Flag 3604 in order to see the command result on the screen. The generated result depends mainly on the SQL Server version.

通过将Status语句或数字零作为单个参数传递给该命令,可以查看DBCC OPTIMIZER_WHATIF命令可以更改的属性的当前状态。 在此之前,我们应该打开跟踪标志3604以便在屏幕上查看命令结果。 生成的结果主要取决于SQL Server版本。

The below command is used to check the status of these properties on my SQL Server 2016 instance:

以下命令用于检查我SQL Server 2016实例上这些属性的状态:


DBCC TRACEON(3604) WITH NO_INFOMSGS
DBCC OPTIMIZER_WHATIF(0) WITH NO_INFOMSGS;

It can be also written as:

它也可以写成:


DBCC TRACEON(3604) WITH NO_INFOMSGS
DBCC OPTIMIZER_WHATIF(Status) WITH NO_INFOMSGS;

Both queries will return the same result, which looks like the below in my case:

这两个查询将返回相同的结果,在我的情况下,如下所示:

You can also reset all the properties values and return it to its default values, if you are afraid that someone perform any change, by passing the ResetAll parameter to the DBCC OPTIMIZER_WHATIF command as follows:

如果您担心有人执行任何更改,还可以通过将ResetAll参数传递给DBCC OPTIMIZER_WHATIF命令,来重置所有属性值,并将其恢复为默认值,如下所示:


DBCC OPTIMIZER_WHATIF(ResetAll) WITH NO_INFOMSGS;

Let us start our demo.

让我们开始演示。

In this scenario, we will be working on a development SQL Server instance with 4 CPU cores and 8 GB RAM. We have been requested to tune the performance of the below query that is slow on the production SQL Server. The development team sent the query to us with the execution plan and then we executed it on the development SQL Server:

在这种情况下,我们将研究具有4个CPU内核和8 GB RAM的开发SQL Server实例。 我们被要求调整以下查询的性能,这些查询在生产SQL Server上很慢。 开发团队将查询与执行计划一起发送给我们,然后我们在开发SQL Server上执行了该查询:


USE SQLShackDemo
GO
SELECT  EMP.EmpName , EMP.EmpAddress , EMPD.DepName
FROM Employees EMP
CROSS APPLY Employee_Department EMPD
WHERE EMP.EmpName like '%Sanya%'
ORDER BY  EMPD.DepName
OPTION (RECOMPILE)

The generated execution plan for that query differs from the execution plan received from the production server:

为该查询生成的执行计划与从生产服务器接收的执行计划不同:

It took 54 ms to be executed and 16ms of the CPU time as follows:

执行时间为54毫秒,CPU时间为16毫秒,如下所示:

With 19,528 byes Memory Granted and 10.7688 Estimated Subtree Cost as in the SELECT operator properties window below:

具有19,528个byes的“内存已授予”权限和“ 10.7688”的估计子树开销,如下面的SELECT运算符属性窗口所示:

The query has no problem on the development SQL Server as you can see from the statistics shown previously. In order to check the real query performance, we should simulate it on the production environment. This can be done by changing the SQL Server Query Optimizer view of the development SQL Server resources that is achieved using the DBCC OPTIMIZER_WHATIF command.

从前面显示的统计信息中可以看到,该查询在开发SQL Server上没有问题。 为了检查实际的查询性能,我们应该在生产环境中对其进行仿真。 这可以通过更改使用DBCC OPTIMIZER_WHATIF命令实现的开发SQL Server资源SQL Server查询优化器视图来完成。

The below script allows the SQL Server Query optimizer to generate an execution plan for the submitted query assuming that the SQL instance is working on a server with 80 CPU cores.

下面的脚本允许SQL Server查询优化器为提交的查询生成执行计划,前提是该SQL实例在具有80个CPU内核的服务器上运行。

Take into consideration that the DBCC OPTIMIZER_WHATIF command should be combined with the query to be tuned in the same session, as this command is working on a session scope. We turned on the Trace Flag 3604 here in order to be able to query the current properties values of the DBCC OPTIMIZER_WHATIF command:

考虑到DBCC OPTIMIZER_WHATIF命令应与要在同一会话中调优的查询结合使用,因为该命令在会话范围内起作用。 我们在这里启用了跟踪标志3604,以便能够查询DBCC OPTIMIZER_WHATIF命令的当前属性值:


USE SQLShackDemo
GO
-- Simulate 80 CPU cores
DBCC OPTIMIZER_WHATIF(1,80)
-- To be able to see the result
DBCC TRACEON(3604) WITH NO_INFOMSGS
-- Check the current status
DBCC OPTIMIZER_WHATIF(Status) WITH NO_INFOMSGS;
-- The query to be tuned
SELECT  EMP.EmpName , EMP.EmpAddress , EMPD.DepName
FROM Employees EMP
CROSS APPLY Employee_Department EMPD
WHERE EMP.EmpName like '%Sanya%'
ORDER BY  EMPD.DepName
OPTION (RECOMPILE)

The Recompile option is added here to make sure that a new plan will be generated for the query with the new resources.

在此处添加了“重新编译”选项,以确保将使用新资源为查询生成新计划。

In the query Messages tab, you will see that the CPUs value of the DBCC OPTIMIZER_WHATIF command is changed to be 80 as follows:

在查询消息选项卡中,您将看到DBCC OPTIMIZER_WHATIF命令的CPU值更改为80,如下所示:

… and that it took 130ms on the live server to be executed, not 54ms as previously shown on the development server, and 109ms of the CPU time, not 16ms as in the previous result:

…在实时服务器上执行需要130毫秒,而不是之前在开发服务器上显示的54毫秒,而在CPU时间上是109毫秒,而不是上一个结果16毫秒:

This is the execution plan that we have received

这是我们收到的执行计划

You can compare the Sort operator weight in the new plan after modifying the number of CPUs, which is 37%, with the old result, which is 86%, and how it is enhanced:

您可以在修改CPU数量(占37%)和旧结果(占86%)之后,在新计划中比较“排序”运算符权重,以及如何对其进行增强:

Less memory is granted to the query after modifying the number of CPUs, with 6,656 bytes compared with the 19,528 byes Memory Granted with four CPU cores previously. The Estimated Subtree Cost of the SELECT operator has increased now to 11.8752, compared to the old value 10.7688 as below:

修改CPU数量后,授予查询的内存更少,为6,656字节,而之前具有四个CPU内核的19,528 byes内存授予。 与下面的旧值10.7688相比,SELECT运算符的估计子树成本现在已增加到11.8752:

DBCC OPTIMIZER_WHATIF command can be used to alter other SQL Server resources hypothetically, as mentioned previously. Assume that we need to simulate the 80 CPU cores, the 256 GB RAM and the 64-bit system of the production server on the development server to test our query again. The query below will alter the SQL Server resources for the SQL Server Query Optimizer with the specified values, showing the results:

如前所述,可以假设使用DBCC OPTIMIZER_WHATIF命令来更改其他SQL Server资源。 假设我们需要在开发服务器上模拟80个CPU内核,256 GB RAM和生产服务器的64位系统,以再次测试我们的查询。 下面的查询将使用指定的值更改SQL Server查询优化器SQL Server资源,并显示结果:


USE SQLShackDemo
GO
DBCC TRACEON(3604) WITH NO_INFOMSGS
DBCC OPTIMIZER_WHATIF(Status) WITH NO_INFOMSG
GO
DBCC OPTIMIZER_WHATIF(CPU,80)
-- DBCC OPTIMIZER_WHATIF(1,80)
GO
DBCC OPTIMIZER_WHATIF(MemoryMBs, 262144)
-- DBCC OPTIMIZER_WHATIF(2,262144)
GO
DBCC OPTIMIZER_WHATIF(Bits, 64)
-- DBCC OPTIMIZER_WHATIF(3,64)
GO
SELECT  EMP.EmpName , EMP.EmpAddress , EMPD.DepName
FROM Employees EMP
CROSS APPLY Employee_Department EMPD
WHERE EMP.EmpName like '%Sanya%'
ORDER BY  EMPD.DepName
OPTION (RECOMPILE)

The changed memory and system bits values will be like:

更改后的内存和系统位值将类似于:

After finishing the tuning process, we need to reset all properties back to the default values and show it again:

完成调整过程后,我们需要将所有属性重置为默认值,然后再次显示:


DBCC OPTIMIZER_WHATIF(ResetAll) WITH NO_INFOMSGS;
DBCC TRACEON(3604) WITH NO_INFOMSGS
DBCC OPTIMIZER_WHATIF(Status) WITH NO_INFOMSGS;

Back to defaults again:

再次回到默认值:

结论 (Conclusion)

DBCC OPTIMIZER_WHATIF gives us a near real estimation about how the query will perform in the production environment by spoofing the production SQL Server resources on the development SQL Server, which helps us in tuning our queries more efficiently.

DBCC OPTIMIZER_WHATIF通过在开发SQL Server上欺骗生产SQL Server资源,为我们提供了有关查询在生产环境中的性能的近乎真实的估计,这有助于我们更有效地调整查询。

In this article, you saw practically how it works and how we can get benefits from it in our performance tuning tasks.

在本文中,您实际上了解了它如何工作以及如何在性能调整任务中从中获得收益。

翻译自: https://www.sqlshack.com/how-to-spoof-production-environment-resources-for-performance-tuning/

nginx静态资源 性能

nginx静态资源 性能_如何欺骗生产环境资源以进行性能调整相关推荐

  1. Nginx静态资源优化配置之tcp_nopush和tcp_nodelay

    (2)tcp_nopush:该指令必须在sendfile打开的状态下才会生效,主要是用来提升网络包的传输'效率' 语法 tcp_nopush on|off; 默认值 tcp_nopush off; 位置 ...

  2. nginx ---- 静态资源部署

    Nginx静态资源概述 上网去搜索访问资源对于我们来说并不陌生,通过浏览器发送一个HTTP请求实现从客户端发送请求到服务器端获取所需要内容后并把内容回显展示在页面的一个过程.这个时候,我们所请 求的内 ...

  3. nginx静态资源服务器简单配置

    传统的web项目,一般都将静态资源存放在 webroot的目录下,这样做很方便获取静态资源,但是如果说web项目很大,用户很多,静态资源也很多时,服务器的性能 或许就会很低下了.这种情况下一般都会需要 ...

  4. Nginx静态资源部署

    目录 Nginx静态资源概述 Nginx静态资源的配置指令 listen指令 server_name指令 location指令 设置请求资源的目录root / alias index指令 error_ ...

  5. Nginx静态资源优化、压缩、缓存

    这一篇记录一下Nginx压缩缓存相关的指令,各位看到此博客的小伙伴,如有不对的地方请及时通过私信我或者评论此博客的方式指出,以免误人子弟.多谢! 目录 优化 sendfile tcp_nopush tc ...

  6. Nginx 静态资源缓存配置

    示例 # Media: images, icons, video, audio, HTC location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|m ...

  7. nginx静态资源反向代理

    nginx静态资源反向代理 server { listen 80; server_name music.didi365.com; index index.php index.html index.ht ...

  8. 请求nginx静态资源报403

    [README] 请求nginx静态资源报403: [1]原因 静态资源防止在某个家目录下,如 /root 目录下 [2] 解决方法1 nginx.conf 文件没有指定用户 # user nobod ...

  9. nginx 静态资源优化配置

    前言 在很多公司,nginx不仅作为反向代理服务器使用,而且承载着一部分静态资源存储的功能,比如将图片等静态资源放在nginx目录下,比较熟悉的是,在一些前后端分离的网站中,某些情况下,为了能充分提升 ...

最新文章

  1. VMTK学习——02.基本的PYPES教程
  2. 【学习笔记】SAP FI 业务范围的概念
  3. 计算机应用基础电子毕业考试,计算机应用基础-上海电子信息职业技术学院.PDF...
  4. write up 杂项:telenet
  5. 【BZOJ1452】[JSOI2009]Count(树状数组)
  6. 系统软键盘Android在外接物理键盘时,如何强制调用系统软键盘?
  7. dell服务器启动顺序如何设置_如何即时设置一个静态文件服务器
  8. 一台电脑安装多个Redis服务
  9. angularjs源码笔记(4)--scope
  10. [python]-asyncio异步通信之websockets
  11. Python爬取58同城租房数据,完美解决字体加密
  12. 计算机在会计中的应用书籍,Excel在会计和财务中的应用
  13. 复盘报告书写规范之一
  14. 虚拟示波器软件 JSCOPE -- 使用 jlink 仿真器来查看变量
  15. stm32上常用的几个通信协议简介及相关代码
  16. 如何使用Proteus进行电路设计仿真?
  17. 强一致性 弱一致性 最终一致性
  18. 安装MinIO和使用MinIO Java SDK实现对文件的基本操作
  19. sfml-tutorials 官方教程的嘟嘟翻译 windows篇
  20. TN3399 rk3399自用说明记录

热门文章

  1. oo第一次博客-三次表达式求导的总结与反思
  2. 【LGP5161】WD与数列
  3. win7下文本文档不能直接修改后缀是为什么?怎么办?
  4. 二叉树:通过前序遍历与中序遍历序列输出二叉树的后序遍历序列
  5. 探索安卓中有意义的动画!
  6. VB6.0 GetTcpTable 使用详解
  7. MariaDB Centos7 下安装MariaDB
  8. 【转贴】CSS Sticky Footer: 完美的CSS绝对底部
  9. ES6——函数参数默认值
  10. 【博客项目】—案例初始化(二)