SlideShare a Scribd company logo
1 of 23
bobward@microsoft.com
@bobwardms
http://aka.ms/bobsql
Want decks and demos now? http://aka.ms/bobwardms
Credits to Joe Sack,
Arvind Shyamsundar,
and the SQL R Team
Why SQL Server R Services?
What gets installed?
The SQL Server Extensibility Architecture
R and SQL Server Together
R with SQL Server is Scalable and Secure
Resource Pools, Best Practices, Monitoring, and Troubleshooting
SQL Server and R at Scale
Familiar
Scalable
Secure
SQL Server and Microsoft R
T-SQL
SQLOS
DMVs
Resource Governor
XEvent
Query Store
LOG files
Seconds and ms
R Open
R Client (R Studio)
ScaleR
R Server
R Data Sources
Hours and Days
R Services (In-Database)
SQL Server
R Services
Microsoft
R Server
Some differences
by edition
Not installed by
default in Azure VM
A few things to
do for Azure VM
Open Source
R Package
Microsoft R
Package
The offline experience
You must download both
• CUs and SPs will have new download packages
• Don’t forget /IACCEPTROPENLICENSETERMS for unattended installs
• Rsetup.exe and rsetup.log
launchpad.exe
sp_execute_external_script
sqlservr.exe
Named pipe
Each SQL
instance has a
launchpad
SQLOS
XEvent
MSSQLSERVER Service MSSQLLAUNCHPAD Service
“What” and “How”
to “launch”
“launcher”
Windows
“satellite” process
sqlsatellite.dll
Windows
“satellite” process
Windows
“satellite” process
Windows
“satellite” process
Windows
“satellite” process
execute sp_execute_external_script
@language = N'R'
, @script = N'
x <- as.matrix(InputDataSet);
y <- array(dim1:dim2);
OutputDataSet <- as.data.frame(x %*% y);'
, @input_data_1 = N' SELECT [Col1] from MyData;'
, @params = N'@dim1 int, @dim2 int'
, @dim1 = 12, @dim2 = 15
WITH RESULT SETS (([Col1] int, [Col2] int, [Col3] int, [Col4] int));
Getting started with R
docs installed in
R_SERVICESdoc
R is only currently
supported script language
today
R script. Use a @var
or read from a file
Input data for script. Can be
any T-SQL SELECT.
Parameters for script. OUTPUT supported
Result set bindingMessages can also be
returned including STDOUT
and STDERR
Lessons learned with customers from SQLCAT
SQL query tuning
Some R scripts work better as T-SQL (Ex. Result set aggregation)
Develop, Train, and Operationalize
R Client to develop, explore and experiment
Train a model with sp_execute_external_script and save the result to a table
Operationalize by using sp_execute_external_script to “run” the model
sp_execute_external_script
from T-SQL client
SQL Server Compute
Context from R client
RODBC data source in R
scripts
“Input data” queries traced
like any other query
Encapsulate in stored
procedure for SQL clients
sp_execute_external_script
sqlservr.exe
MSSQLSERVER Service
launchpad.exe
MSSQLLAUNCHPAD Service
rlauncher.dll
BxlServer.exe
sqlsatellite.dll
rterm.exe conhost.exe
process pool
compile input data
query
Send message to pipe
Execute input query
Push results
Pull results SNI/TCP – Comm technology as SQL
Retrieve input rows and params
Send back results and output params
stdout and stderr
R script
pipe CreateProcess
pipe
Windows Job Object
CreateProcess
SQLOS
XEvent
ScaleR“satellite”
process
interleaved
Open R
docs
rxlink.dll
Local User Account
Local User Account
Service SIDService SID
This is all local!
SATELLITE_* wait type
rlauncher.dll
rlauncher.dll
More efficient than standalone R clients
Data does not have to all fit in memory
Reduced data transmission over the network
Most R Open functions are single threaded
Use the ScaleR APIs for scalable R scripts that are multi-threaded on the SQL Server computer
We can stream data in parallel and batches from SQL Server
Use the power of SQL Server and R Server to develop, train, and execution
SQL Server Compute Context
T-SQL queries
Columnstore indexes
Data compression
Parallel query execution
Stored procedures
Enterprise Edition
gives you the
optimum
scalability
Reduced surface area
and isolation
‘external scripts enabled’
required
R script execution outside of
SQL Server process space
Script execution
requires explicit
permission
sp_execute_external_script
requires EXECUTE ANY
EXTERNAL SCRIPT for non-
admins
SQL Server login/user
required and db/table access
Satellite processes has
limited privileges
Satellite processes run under
local user accounts in the
SQLRUserGroup
Each execution is isolated.
Different users with different
accounts
Windows firewall rules to
block outbound traffic
MSSQLSERVR0n
Computer with enough cores, memory, and disk speed
High Performance Power Option
Balance memory needed by SQL Server and external pool
Launchpad needs specific privileges
Be sure SQLRUserGroup has log on local rights
Restart the SQL Server Service not stop/start (Launchpad is dependent)
8dot3 notation needs to be enabled. Read more here
Remote ODBC execution requires SQLRUserGroup login
20 unique users allowed to execute R scripts concurrently by default
SQL Server Query and Index design still apply
R scripts can often benefit from tuning
docs recommend
min 32Gb
Default max
memory is
20% of RAM
Need to add
more?
internal, default, “user”, and now external
Controls resources for external processes through Launchpad.
Default external pool and user external pools. User classifier function supported
The controls
• MAX_CPU_PERCENT – Max CPU percentage for external processes
• MAX_PROCESSES – Max number of external processes
• MAX_MEMORY – Max committed memory % for external processes
• AFFINITY – Control NODEs or CPUs for external processes
Windows Job
Objects
Each pool
requires a
separate job
object
dynamic
Min is 12 due to process
pool. conhost.exe doesn’t
count. 0 = unlimited
Install R
Services (In
Database)
Enable and
verify
Develop
model
Train and save
model
Operationalize
the model
Tune and
configure for
production
sp_configure
“hello world
test”
R Client
Migrate to ScaleR
SQL Compute Context
Some R scripts to T-SQL
Encapsulate in
a stored
procedure
SQL query tuning
R script tuning
Batch size
Resource Governor
sp_execute_external_script
Fraud detection at 1
million predictions per
second
SQL Server R 100 times
faster at price
optimizations for airline
tickets and hotel rooms
price predictions
Start here with the docs
SQL team blog post
Experiences from the SQLCAT team
bobsql blog series
Tiger team blog series
Revolution Analytics blog series
R libraries
• library
R
documentation
• doc
R tools
• bin
Microsoft ScaleR
libraries
• libraryRevoScaleR
<sql install dir>Microsoft SQL
ServerMSSQL13.<instance>R_SERVICES
How to install other R
packages
SQL specific binaries are installed
in MSSQLBINN
sqlservr.exe
BxlServer.exe
sqlsatellite.dll
R Client
rterm.exe
Open R
rxlink.dll
BxlServer.exe
CreateProces
s
pipe
launchpad.exe
rterm.exe
sqlCompute <- RxInSqlServer(connectionString = sqlConnString, wait = TRUE, consoleOutput = TRUE)
rxSetComputeContext("sqlCompute")
sp_execute_external-
script
RODBC
SQL Server R Services: What Every SQL Professional Should Know

More Related Content

What's hot

What's hot (20)

Experience sql server on l inux and docker
Experience sql server on l inux and dockerExperience sql server on l inux and docker
Experience sql server on l inux and docker
 
Sql server hybrid what every sql professional should know
Sql server hybrid what every sql professional should knowSql server hybrid what every sql professional should know
Sql server hybrid what every sql professional should know
 
Inside sql server in memory oltp sql sat nyc 2017
Inside sql server in memory oltp sql sat nyc 2017Inside sql server in memory oltp sql sat nyc 2017
Inside sql server in memory oltp sql sat nyc 2017
 
Experience SQL Server 2017: The Modern Data Platform
Experience SQL Server 2017: The Modern Data PlatformExperience SQL Server 2017: The Modern Data Platform
Experience SQL Server 2017: The Modern Data Platform
 
How SQL Server 2016 SP1 Changes the Game
How SQL Server 2016 SP1 Changes the GameHow SQL Server 2016 SP1 Changes the Game
How SQL Server 2016 SP1 Changes the Game
 
SQL Server 2016 New Features and Enhancements
SQL Server 2016 New Features and EnhancementsSQL Server 2016 New Features and Enhancements
SQL Server 2016 New Features and Enhancements
 
Azure DocumentDB 101
Azure DocumentDB 101Azure DocumentDB 101
Azure DocumentDB 101
 
SQL Server 2016 novelties
SQL Server 2016 noveltiesSQL Server 2016 novelties
SQL Server 2016 novelties
 
Connecting Hadoop and Oracle
Connecting Hadoop and OracleConnecting Hadoop and Oracle
Connecting Hadoop and Oracle
 
Brk2045 upgrade sql server 2017 (on prem, iaa-s and paas)
Brk2045 upgrade sql server 2017 (on prem, iaa-s and paas)Brk2045 upgrade sql server 2017 (on prem, iaa-s and paas)
Brk2045 upgrade sql server 2017 (on prem, iaa-s and paas)
 
Testing batch and streaming Spark applications
Testing batch and streaming Spark applicationsTesting batch and streaming Spark applications
Testing batch and streaming Spark applications
 
Real Time Operational Analytics with Microsoft Sql Server 2016 [Liviu Ieran]
Real Time Operational Analytics with Microsoft Sql Server 2016 [Liviu Ieran]Real Time Operational Analytics with Microsoft Sql Server 2016 [Liviu Ieran]
Real Time Operational Analytics with Microsoft Sql Server 2016 [Liviu Ieran]
 
SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?
 
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERAGeek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
 
Products.intro.forum version
Products.intro.forum versionProducts.intro.forum version
Products.intro.forum version
 
SQL Server 2016: Just a Few of Our DBA's Favorite Things
SQL Server 2016: Just a Few of Our DBA's Favorite ThingsSQL Server 2016: Just a Few of Our DBA's Favorite Things
SQL Server 2016: Just a Few of Our DBA's Favorite Things
 
What's New in Amazon Aurora
What's New in Amazon AuroraWhat's New in Amazon Aurora
What's New in Amazon Aurora
 
Hadoop for the Absolute Beginner
Hadoop for the Absolute BeginnerHadoop for the Absolute Beginner
Hadoop for the Absolute Beginner
 
Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014
 
Snowflake SnowPro Certification Exam Cheat Sheet
Snowflake SnowPro Certification Exam Cheat SheetSnowflake SnowPro Certification Exam Cheat Sheet
Snowflake SnowPro Certification Exam Cheat Sheet
 

Viewers also liked

портфолио голубович
портфолио голубовичпортфолио голубович
портфолио голубович
golubovicholga
 
Psicopedagoga rj.com.br Cadastro
Psicopedagoga rj.com.br   CadastroPsicopedagoga rj.com.br   Cadastro
Psicopedagoga rj.com.br Cadastro
PsicopedagogaRJ
 
Creep Coursework Presentation
Creep Coursework PresentationCreep Coursework Presentation
Creep Coursework Presentation
kess1a
 

Viewers also liked (20)

Twenty is Plenty
Twenty is PlentyTwenty is Plenty
Twenty is Plenty
 
ckitterman resume
ckitterman resumeckitterman resume
ckitterman resume
 
Accounting concepts
Accounting conceptsAccounting concepts
Accounting concepts
 
Actividad 2
Actividad 2Actividad 2
Actividad 2
 
Actividad 5 (1)
Actividad 5 (1)Actividad 5 (1)
Actividad 5 (1)
 
indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...
indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...
indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...
 
3. linux installation
3.  linux installation3.  linux installation
3. linux installation
 
Privacidad, seguridad y protección online
Privacidad, seguridad y protección onlinePrivacidad, seguridad y protección online
Privacidad, seguridad y protección online
 
Cast/Actors
Cast/ActorsCast/Actors
Cast/Actors
 
Ppt on self study
Ppt on self studyPpt on self study
Ppt on self study
 
Agile vs. waterfall
Agile vs. waterfallAgile vs. waterfall
Agile vs. waterfall
 
Copper conductor
Copper conductorCopper conductor
Copper conductor
 
Who's Reading Over Your Shoulder?
Who's Reading Over Your Shoulder? Who's Reading Over Your Shoulder?
Who's Reading Over Your Shoulder?
 
Lokale Präpositionen 2 wo wohin - woher
Lokale Präpositionen 2  wo   wohin - woherLokale Präpositionen 2  wo   wohin - woher
Lokale Präpositionen 2 wo wohin - woher
 
портфолио голубович
портфолио голубовичпортфолио голубович
портфолио голубович
 
Portfolio Draft
Portfolio DraftPortfolio Draft
Portfolio Draft
 
Psicopedagoga rj.com.br Cadastro
Psicopedagoga rj.com.br   CadastroPsicopedagoga rj.com.br   Cadastro
Psicopedagoga rj.com.br Cadastro
 
Pre Production (Planning)
Pre Production (Planning)Pre Production (Planning)
Pre Production (Planning)
 
Creep Coursework Presentation
Creep Coursework PresentationCreep Coursework Presentation
Creep Coursework Presentation
 
Context Based Learning for GIS: an Interdisciplinary Approach
Context Based Learning for GIS: an Interdisciplinary ApproachContext Based Learning for GIS: an Interdisciplinary Approach
Context Based Learning for GIS: an Interdisciplinary Approach
 

Similar to SQL Server R Services: What Every SQL Professional Should Know

Intro to big data analytics using microsoft machine learning server with spark
Intro to big data analytics using microsoft machine learning server with sparkIntro to big data analytics using microsoft machine learning server with spark
Intro to big data analytics using microsoft machine learning server with spark
Alex Zeltov
 
Enter the Dragon - SQL 2014 on Server Core PASS Summit 2014 Edition
Enter the Dragon -  SQL 2014 on Server Core PASS Summit 2014 EditionEnter the Dragon -  SQL 2014 on Server Core PASS Summit 2014 Edition
Enter the Dragon - SQL 2014 on Server Core PASS Summit 2014 Edition
Mark Broadbent
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Net
webhostingguy
 

Similar to SQL Server R Services: What Every SQL Professional Should Know (20)

Intro to big data analytics using microsoft machine learning server with spark
Intro to big data analytics using microsoft machine learning server with sparkIntro to big data analytics using microsoft machine learning server with spark
Intro to big data analytics using microsoft machine learning server with spark
 
Ml2
Ml2Ml2
Ml2
 
RUCK 2017 R에 날개 달기 - Microsoft R과 클라우드 머신러닝 소개
RUCK 2017 R에 날개 달기 - Microsoft R과 클라우드 머신러닝 소개RUCK 2017 R에 날개 달기 - Microsoft R과 클라우드 머신러닝 소개
RUCK 2017 R에 날개 달기 - Microsoft R과 클라우드 머신러닝 소개
 
Machine learning services with SQL Server 2017
Machine learning services with SQL Server 2017Machine learning services with SQL Server 2017
Machine learning services with SQL Server 2017
 
SQL Server 2008 Integration Services
SQL Server 2008 Integration ServicesSQL Server 2008 Integration Services
SQL Server 2008 Integration Services
 
Enter the Dragon - SQL 2014 on Server Core PASS Summit 2014 Edition
Enter the Dragon -  SQL 2014 on Server Core PASS Summit 2014 EditionEnter the Dragon -  SQL 2014 on Server Core PASS Summit 2014 Edition
Enter the Dragon - SQL 2014 on Server Core PASS Summit 2014 Edition
 
PPT
PPTPPT
PPT
 
SQLSaturday#290_Kiev_AdHocMaintenancePlansForBeginners
SQLSaturday#290_Kiev_AdHocMaintenancePlansForBeginnersSQLSaturday#290_Kiev_AdHocMaintenancePlansForBeginners
SQLSaturday#290_Kiev_AdHocMaintenancePlansForBeginners
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
Roles y Responsabilidades en SQL Azure
Roles y Responsabilidades en SQL AzureRoles y Responsabilidades en SQL Azure
Roles y Responsabilidades en SQL Azure
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
 
Plantilla oracle
Plantilla oraclePlantilla oracle
Plantilla oracle
 
Rajnish singh(presentation on oracle )
Rajnish singh(presentation on  oracle )Rajnish singh(presentation on  oracle )
Rajnish singh(presentation on oracle )
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
SQL Server - High availability
SQL Server - High availabilitySQL Server - High availability
SQL Server - High availability
 
Watch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML UtilitiesWatch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML Utilities
 
2019 Blackhat Booth Presentation - PowerUpSQL
2019 Blackhat Booth Presentation - PowerUpSQL2019 Blackhat Booth Presentation - PowerUpSQL
2019 Blackhat Booth Presentation - PowerUpSQL
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Net
 
Enter The Dragon - SQL 2014 on Server Core - SQLSaturday #341 Porto Edition
Enter The Dragon - SQL 2014 on Server Core - SQLSaturday #341 Porto EditionEnter The Dragon - SQL 2014 on Server Core - SQLSaturday #341 Porto Edition
Enter The Dragon - SQL 2014 on Server Core - SQLSaturday #341 Porto Edition
 
SQL Injection
SQL InjectionSQL Injection
SQL Injection
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

SQL Server R Services: What Every SQL Professional Should Know

  • 1. bobward@microsoft.com @bobwardms http://aka.ms/bobsql Want decks and demos now? http://aka.ms/bobwardms Credits to Joe Sack, Arvind Shyamsundar, and the SQL R Team
  • 2. Why SQL Server R Services? What gets installed? The SQL Server Extensibility Architecture R and SQL Server Together R with SQL Server is Scalable and Secure Resource Pools, Best Practices, Monitoring, and Troubleshooting SQL Server and R at Scale
  • 3.
  • 4. Familiar Scalable Secure SQL Server and Microsoft R T-SQL SQLOS DMVs Resource Governor XEvent Query Store LOG files Seconds and ms R Open R Client (R Studio) ScaleR R Server R Data Sources Hours and Days R Services (In-Database)
  • 5. SQL Server R Services Microsoft R Server Some differences by edition Not installed by default in Azure VM
  • 6. A few things to do for Azure VM Open Source R Package Microsoft R Package The offline experience You must download both • CUs and SPs will have new download packages • Don’t forget /IACCEPTROPENLICENSETERMS for unattended installs • Rsetup.exe and rsetup.log
  • 7. launchpad.exe sp_execute_external_script sqlservr.exe Named pipe Each SQL instance has a launchpad SQLOS XEvent MSSQLSERVER Service MSSQLLAUNCHPAD Service “What” and “How” to “launch” “launcher” Windows “satellite” process sqlsatellite.dll Windows “satellite” process Windows “satellite” process Windows “satellite” process Windows “satellite” process
  • 8. execute sp_execute_external_script @language = N'R' , @script = N' x <- as.matrix(InputDataSet); y <- array(dim1:dim2); OutputDataSet <- as.data.frame(x %*% y);' , @input_data_1 = N' SELECT [Col1] from MyData;' , @params = N'@dim1 int, @dim2 int' , @dim1 = 12, @dim2 = 15 WITH RESULT SETS (([Col1] int, [Col2] int, [Col3] int, [Col4] int)); Getting started with R docs installed in R_SERVICESdoc R is only currently supported script language today R script. Use a @var or read from a file Input data for script. Can be any T-SQL SELECT. Parameters for script. OUTPUT supported Result set bindingMessages can also be returned including STDOUT and STDERR
  • 9. Lessons learned with customers from SQLCAT SQL query tuning Some R scripts work better as T-SQL (Ex. Result set aggregation) Develop, Train, and Operationalize R Client to develop, explore and experiment Train a model with sp_execute_external_script and save the result to a table Operationalize by using sp_execute_external_script to “run” the model sp_execute_external_script from T-SQL client SQL Server Compute Context from R client RODBC data source in R scripts “Input data” queries traced like any other query Encapsulate in stored procedure for SQL clients
  • 10. sp_execute_external_script sqlservr.exe MSSQLSERVER Service launchpad.exe MSSQLLAUNCHPAD Service rlauncher.dll BxlServer.exe sqlsatellite.dll rterm.exe conhost.exe process pool compile input data query Send message to pipe Execute input query Push results Pull results SNI/TCP – Comm technology as SQL Retrieve input rows and params Send back results and output params stdout and stderr R script pipe CreateProcess pipe Windows Job Object CreateProcess SQLOS XEvent ScaleR“satellite” process interleaved Open R docs rxlink.dll Local User Account Local User Account Service SIDService SID This is all local! SATELLITE_* wait type rlauncher.dll rlauncher.dll
  • 11.
  • 12. More efficient than standalone R clients Data does not have to all fit in memory Reduced data transmission over the network Most R Open functions are single threaded Use the ScaleR APIs for scalable R scripts that are multi-threaded on the SQL Server computer We can stream data in parallel and batches from SQL Server Use the power of SQL Server and R Server to develop, train, and execution SQL Server Compute Context T-SQL queries Columnstore indexes Data compression Parallel query execution Stored procedures Enterprise Edition gives you the optimum scalability
  • 13. Reduced surface area and isolation ‘external scripts enabled’ required R script execution outside of SQL Server process space Script execution requires explicit permission sp_execute_external_script requires EXECUTE ANY EXTERNAL SCRIPT for non- admins SQL Server login/user required and db/table access Satellite processes has limited privileges Satellite processes run under local user accounts in the SQLRUserGroup Each execution is isolated. Different users with different accounts Windows firewall rules to block outbound traffic MSSQLSERVR0n
  • 14. Computer with enough cores, memory, and disk speed High Performance Power Option Balance memory needed by SQL Server and external pool Launchpad needs specific privileges Be sure SQLRUserGroup has log on local rights Restart the SQL Server Service not stop/start (Launchpad is dependent) 8dot3 notation needs to be enabled. Read more here Remote ODBC execution requires SQLRUserGroup login 20 unique users allowed to execute R scripts concurrently by default SQL Server Query and Index design still apply R scripts can often benefit from tuning docs recommend min 32Gb Default max memory is 20% of RAM Need to add more?
  • 15. internal, default, “user”, and now external Controls resources for external processes through Launchpad. Default external pool and user external pools. User classifier function supported The controls • MAX_CPU_PERCENT – Max CPU percentage for external processes • MAX_PROCESSES – Max number of external processes • MAX_MEMORY – Max committed memory % for external processes • AFFINITY – Control NODEs or CPUs for external processes Windows Job Objects Each pool requires a separate job object dynamic Min is 12 due to process pool. conhost.exe doesn’t count. 0 = unlimited
  • 16.
  • 17. Install R Services (In Database) Enable and verify Develop model Train and save model Operationalize the model Tune and configure for production sp_configure “hello world test” R Client Migrate to ScaleR SQL Compute Context Some R scripts to T-SQL Encapsulate in a stored procedure SQL query tuning R script tuning Batch size Resource Governor sp_execute_external_script
  • 18. Fraud detection at 1 million predictions per second SQL Server R 100 times faster at price optimizations for airline tickets and hotel rooms price predictions
  • 19. Start here with the docs SQL team blog post Experiences from the SQLCAT team bobsql blog series Tiger team blog series Revolution Analytics blog series
  • 20.
  • 21. R libraries • library R documentation • doc R tools • bin Microsoft ScaleR libraries • libraryRevoScaleR <sql install dir>Microsoft SQL ServerMSSQL13.<instance>R_SERVICES How to install other R packages SQL specific binaries are installed in MSSQLBINN
  • 22. sqlservr.exe BxlServer.exe sqlsatellite.dll R Client rterm.exe Open R rxlink.dll BxlServer.exe CreateProces s pipe launchpad.exe rterm.exe sqlCompute <- RxInSqlServer(connectionString = sqlConnString, wait = TRUE, consoleOutput = TRUE) rxSetComputeContext("sqlCompute") sp_execute_external- script RODBC

Editor's Notes

  1. Follow the instructions in justshowus\readme.txt
  2. What does R mean in “R services”. R is a statistical computing programming language based on an Open Source Standard, R Open.
  3. MPI is Messaging Passing Interface and is used by R and ScaleR to support parallel computing: https://msdn.microsoft.com/en-us/library/bb524831(v=vs.85).aspx
  4. This is one of the very few scenarios where setup has to connect to the internet
  5. Talk about other “extensible” environments we have used in the past xproc sp_OA Linked servers Full-text
  6. sp_execute_external_script is an example of a special proc or specproc. The source code of the procedure can’t be found in the resource db. It is implemented in our source code
  7. We deploy a “process pool” when launching scripts so when you run a script execution you will see more than one rterm/bxlserver pair. Since rterm is a windows console app you will also see a conhost.exe for each rterm.exe Rterm = R runtime command interpreter Bxlserver = Microsoft R Server process which also hosts sqlsatellite.dll
  8. Follow the instructions in insidesqlr\readme.txt
  9. Perhaps the #1 reason why SQL R Services is a value proposition is because we are pushing the computing power of SQL Server queries and R scripts to the server leaving the R client to analyze the results (such as plots)
  10. TODO: max memory is % of computer physical memory.