- SQL Server 2017 Machine Learning Services with R
- Toma? Ka?trun Julie Koesmarno
- 411字
- 2021-06-24 19:03:47
Resource Governor
Resource Governor is a very welcome feature of R Services (in-database), as it enables the Govern workload against the server with a simple dataset that is available with the accompanying code-database RevoTestDB, it needs to be restored first:
USE [master] RESTORE DATABASE [RevoTestDB] FROM DISK = N'C:\SQLServer2017MLServicesR\CH03\RevoTestDB.bak'; GO
After the restore, we will see the loads against the database and how to govern resources:
USE RevoTestDB; GO -- TEST query EXECUTE sp_execute_external_script @language = N'R' ,@script = N' library(RevoScaleR) f <- formula(as.numeric(ArrDelay) ~ as.numeric(DayOfWeek) + CRSDepTime) s <- system.time(mod <- rxLinMod(formula = f, data = AirLine)) OutputDataSet <- data.frame(system_time = s[3]);' ,@input_data_1 = N'SELECT * FROM AirlineDemoSmall' ,@input_data_1_name = N'AirLine' WITH RESULT SETS ((Elapsed_time FLOAT));
With this test query on my computer, the whole running time was 21 seconds and with elapsed time returned from R Engine, of 1.43 seconds.
Setting up the Resource Governer to tackle picks and spikes. To have execution operations running faster when needed or when running a higher amount of data, we need to configure the external resource pool and the resource pool to grant the resources:
-- Default value ALTER EXTERNAL RESOURCE POOL [default] WITH (AFFINITY CPU = AUTO) GO CREATE EXTERNAL RESOURCE POOL RService_Resource_Pool WITH ( MAX_CPU_PERCENT = 10 ,MAX_MEMORY_PERCENT = 5 ); ALTER RESOURCE POOL [default] WITH (max_memory_percent = 60, max_cpu_percent=90); ALTER EXTERNAL RESOURCE POOL [default] WITH (max_memory_percent = 40, max_cpu_percent=10); ALTER RESOURCE GOVERNOR reconfigure; ALTER RESOURCE GOVERNOR RECONFIGURE; GO
In the last step, a classification function must be created and reconfigured:
CREATE FUNCTION RG_Class_function() RETURNS sysname WITH schemabinding AS BEGIN IF program_name() in ('Microsoft R Host', 'RStudio') RETURN 'R_workgroup'; RETURN 'default' END; GO ALTER RESOURCE GOVERNOR WITH (classifier_function = dbo.RG_Class_function); ALTER RESOURCE GOVERNOR reconfigure; GO
After that, I can run the same query again:
-- TEST 2 - performance normal; with governor enabled EXECUTE sp_execute_external_script @language = N'R' ,@script = N' library(RevoScaleR) f <- formula(as.numeric(ArrDelay) ~ as.numeric(DayOfWeek) + CRSDepTime) s <- system.time(mod <- rxLinMod(formula = f, data = AirLine)) OutputDataSet<- data.frame(system_time = s[3]);' ,@input_data_1 = N'SELECT * FROM AirlineDemoSmall' ,@input_data_1_name = N'AirLine' WITH RESULT SETS ((Elapsed_time FLOAT));
In the end, the comparison in performance is obvious. In the case of my test environment, because I dedicated more CPU and RAM resources to executing R code, I get a running time of three seconds with an R elapsed time of 0.63 seconds. Results on your client might be different, but the change from the default resource governor settings to new settings should be very obvious.
- 構建高質量的C#代碼
- 中文版Photoshop CS5數碼照片處理完全自學一本通
- Visual C# 2008開發技術詳解
- Zabbix Network Monitoring(Second Edition)
- PostgreSQL Administration Essentials
- 統計策略搜索強化學習方法及應用
- 21天學通Visual Basic
- Android游戲開發案例與關鍵技術
- Implementing AWS:Design,Build,and Manage your Infrastructure
- Azure PowerShell Quick Start Guide
- 零起點學西門子S7-200 PLC
- Hands-On Data Warehousing with Azure Data Factory
- Unreal Development Kit Game Design Cookbook
- EJB JPA數據庫持久層開發實踐詳解
- Oracle 11g Anti-hacker's Cookbook