Table of Contents
前言:
通过SQLServerManagement Studio 配置资源调控器:
准备工作:
步骤:
分析:
扩充信息:
Home Database Mysql Tutorial 第十九章使用资源调控器管理资源(1)使用SQLServer Man

第十九章使用资源调控器管理资源(1)使用SQLServer Man

Jun 07, 2016 pm 03:18 PM
ma sqlserver use manage resource

本系列包含: 1、使用SQLServer Management Studio 配置资源调控器 2、使用T-SQL配置资源调控器 3、监控资源调控器 前言: 在前面的章节,提到过可以通过多种配置数据库服务器的方式来提高性能。如索引、统计信息、hints、物理设计和服务器配置等。 当你完成

本系列包含:

1、 使用SQLServer Management Studio 配置资源调控器

2、 使用T-SQL配置资源调控器

3、 监控资源调控器

 

前言:

      在前面的章节,提到过可以通过多种配置数据库服务器的方式来提高性能。如索引、统计信息、hints、物理设计和服务器配置等。

      当你完成上面那些配置后,还依旧有少量存储过程、查询运行得很慢时,由于硬件资源限制,可能已经没什么好调整。如一个数据库服务器支撑着多个应用系统,其中一个是报表系统,而报表系统往往都是非常耗资源的。

      在2008之前,对于这种问题,很难作出有效的解决方法。从2008开始,引入了一个资源调控器(ResourceGovernor)来协助解决这类问题。资源调控器(下面简称RG),可以管理服务器上CPU和内存资源。不同类型的请求可以被分配到不同的资源。

RG的功能可以分为3个组件:

1、 分类(Classification)

2、 资源池(Resource pool)

3、 工作负荷组(Workload group)

RG的基本功能/体系

 第十九章使用资源调控器管理资源(1)使用SQLServer Man

分类(Classification):定义一个用户自定义标量函数作为RG的分类函数,每当请求到达时,分类函数就会执行,区分请求的类型,然后放到特定的工作负荷组(Workload Group)中。

 

工作负载组(WorkloadGroup):一个逻辑单元,包含了一组资源。属于特定的资源池(Resource Pool)SQLServer创建了两个默认的工作负载组,internal和default。

 

资源池(ResourcePool):包含对请求分配特定工作负载组的资源规则定义,SQLServer同样创建了两个资源池internal和default。

 

通过SQLServerManagement Studio 配置资源调控器:

      在开始之前,先来创建一个现实环境,假设AdventureWorks数据库是生产数据库,且有数十亿的数据。这个库提供多个应用程序使用。一个应用程序是用于web程序,一个是OLTP。另外一个应用程序是报表系统。当查询报表的时候,会影响到web程序,为了解决这个问题,可以借助RG来保存web程序的CPU和内存资源。这里保留web程序获得最少50%的CPU和内存,报表使用25%。

本文将演示使用SQLServer Management Studio(下称SSMS)来实现。

 

准备工作:

本文将创建两个资源池和工作负载组。用于给web和报表程序之用。独立的用户名分类函数区分请求很有帮助,基于用户名,分类函数将发送请求到特定的工作负载组。

 

步骤:

1、 打开ssms,确保这个登录有管理员权限,如果不能,那需要有ALTER LOGIN和CONTROL SERVER的权限。

2、 在新建窗口输入,注意本文使用AdventureWorks2012数据库:


USE master
GO
 
CREATE LOGIN [AW_WebAppUser] WITH PASSWORD=N'AW_WebAppUser123' ,DEFAULT_DATABASE=AdventureWorks2012
GO
 
USE AdventureWorks2012
GO
 
CREATE USER [AW_WebAppUser] FOR LOGIN [AW_WebAppUser]
GO
ALTER ROLE [db_owner] ADD MEMBER [AW_WebAppUser]
GO
 
CREATE LOGIN [AW_ReportAppUser] WITH PASSWORD=N'AW_ReportAppUser123',DEFAULT_DATABASE=AdventureWorks2012
GO
 
USE AdventureWorks2012
GO
CREATE USER [AW_ReportAppUser] FOR LOGIN  [AW_ReportAppUser]
GO
ALTER ROLE [db_owner] ADD MEMBER  [AW_ReportAppUser]
GO
Copy after login


3、 创建分类函数: 

USE MASTER
GO
 
CREATE FUNCTION dbo.RGClassifier( )
RETURNS SYSNAME
    WITH SCHEMABINDING
AS
    BEGIN
        DECLARE @Workload_GroupName SYSNAME
   
        IF SUSER_NAME() = 'AW_WebAppUser'
            SET @Workload_GroupName = 'rg_WebApp'
   
        ELSE
            IF SUSER_NAME() = 'AW_ReportAppUser'
                SET @Workload_GroupName = 'rg_ReportApp'
   
            ELSE
                SET @Workload_GroupName = 'default'
        RETURN @Workload_GroupName
    END
Copy after login



4、 打开ssms,右键资源调控器节点,选择【属性】,就见到如下: 

第十九章使用资源调控器管理资源(1)使用SQLServer Man

5、 点击启用【启用资源调控器】:

第十九章使用资源调控器管理资源(1)使用SQLServer Man

6、 在分类函数名下拉框中,选择dbo.RGClassifier():

第十九章使用资源调控器管理资源(1)使用SQLServer Man

7、 在资源池网格中,可以找到两个默认资源池defalut和internal,现在添加一个新的资源池叫做rp_WebApp,并配置为如图,记住总和不能超过100:

第十九章使用资源调控器管理资源(1)使用SQLServer Man

8、 在资源池的工作负荷组:rp_WebApp中,创建一个新的工作负荷组rg_WebApp,并配置CPU时间为300:

第十九章使用资源调控器管理资源(1)使用SQLServer Man

9、 在资源池网格中,按上述步骤添加rp_ReportApp,并把最小CPU和内存设为25,CPU时间为300:

第十九章使用资源调控器管理资源(1)使用SQLServer Man

10、点击确定后,打开资源调控器节点:

 第十九章使用资源调控器管理资源(1)使用SQLServer Man

分析:

      在连接了SQLServer之后,先执行脚本创建用户,用于标识不同应用程序访问数据库。通过账号,分类函数会把登录名的请求发送到对应的资源池和工作负荷组。

      在创建类分区函数dbo.RGClassifier(),并在图形界面中调用这个函数。默认情况下资源调控器是禁用的,为了使其工作,需要手动启用。除了图形界面,也可以使用T-SQL语句:ALTER RESOURCEGOVERNOR RECONFIGURE命令来启动。

      如果请求不属于新建的两个资源池,会分配到default工作负荷组和default资源池。Internal工作负荷组是SQLServer内部使用的,并且DAC(专用管理员连接)是不受RG分类影响。

最后通过图形界面查看是否建立成功。

 

扩充信息:

       在现实世界中,在实施资源调控器之前,需要对各个应用程序的资源请求做一个趋势分析,可以帮助你更好地分配资源。

       在资源池中定义的MIN参数是不共享的,也就是别的请求不能占用这部分,是专用的资源。资源调控器可以有多个资源池。这就是为什么MIN中的百分比总和不能超过100.

        另一方面,MAX参数的值是共享的,实际的MAX值会根据MIN的值来调整。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem that the object named already exists in the sqlserver database How to solve the problem that the object named already exists in the sqlserver database Apr 05, 2024 pm 09:42 PM

For objects with the same name that already exist in the SQL Server database, the following steps need to be taken: Confirm the object type (table, view, stored procedure). IF NOT EXISTS can be used to skip creation if the object is empty. If the object has data, use a different name or modify the structure. Use DROP to delete existing objects (use caution, backup recommended). Check for schema changes to make sure there are no references to deleted or renamed objects.

How to import mdf file into sqlserver How to import mdf file into sqlserver Apr 08, 2024 am 11:41 AM

The import steps are as follows: Copy the MDF file to SQL Server's data directory (usually C:\Program Files\Microsoft SQL Server\MSSQL\DATA). In SQL Server Management Studio (SSMS), open the database and select Attach. Click the Add button and select the MDF file. Confirm the database name and click the OK button.

What to do if the sqlserver service cannot be started What to do if the sqlserver service cannot be started Apr 05, 2024 pm 10:00 PM

When the SQL Server service fails to start, here are some steps to resolve: Check the error log to determine the root cause. Make sure the service account has permission to start the service. Check whether dependency services are running. Disable antivirus software. Repair SQL Server installation. If the repair does not work, reinstall SQL Server.

How to check sqlserver port number How to check sqlserver port number Apr 05, 2024 pm 09:57 PM

To view the SQL Server port number: Open SSMS and connect to the server. Find the server name in Object Explorer, right-click it and select Properties. In the Connection tab, view the TCP Port field.

How to recover accidentally deleted database in sqlserver How to recover accidentally deleted database in sqlserver Apr 05, 2024 pm 10:39 PM

If you accidentally delete a SQL Server database, you can take the following steps to recover: stop database activity; back up log files; check database logs; recovery options: restore from backup; restore from transaction log; use DBCC CHECKDB; use third-party tools. Please back up your database regularly and enable transaction logging to prevent data loss.

Where is the sqlserver database? Where is the sqlserver database? Apr 05, 2024 pm 08:21 PM

SQL Server database files are usually stored in the following default location: Windows: C:\Program Files\Microsoft SQL Server\MSSQL\DATALinux: /var/opt/mssql/data The database file location can be customized by modifying the database file path setting.

How to delete sqlserver if the installation fails? How to delete sqlserver if the installation fails? Apr 05, 2024 pm 11:27 PM

If the SQL Server installation fails, you can clean it up by following these steps: Uninstall SQL Server Delete registry keys Delete files and folders Restart the computer

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

See all articles