SlideShare a Scribd company logo
1 of 26
Deploying R for production
2019-01-23 Stockholm R User Group
Holger Hellebro
IT Architect & Data Scientist
Cognitive & Analytics
IBM Global Business Services
https://www.linkedin.com/in/holgerhellebro
Twitter: @holken
Can we deploy
R code?
Why would we?
How?
Will it scale?
Security?
Why deploy R stuff?
Models for scoring
Visualizations
Data preparation
Feature extraction
Verify with more data
Incoming data
IT system
Build model
Predictions/
Decisions
Training &
testing data
Model
Deploy or rewrite?
Why rewrite?
• Minimize number of
languages
• IT team skills
• Extreme performance /
latency
Why deploy?
• Reuse code
• Consistency
• Easier to maintain
Modern cloud technologies
Helps us package code and data. Helps us run it on a cluster.
“Dockerfile” tells
docker how to
build into an
image
Images contain
all dependencies,
but not a full
Operating System
Container images are uploaded to a
registry to simplify deployment
Docker images & containers
Means of packaging and running
software
Independent of host system
Include all dependencies
Light weight
Kubernetes
Cluster Internet access
My
Image
?
Kubernetes
Cluster Internet access
My
Image
Container
Registry
Deployment
instructions
Containers
Pods
Deployments
Services
Load balancing
Scaling
Deploying a Shiny app
Develop
the app
Make it
run as a
Docker
container
Push the
container
to a
registry
Deploy to
Kubernetes
Expose to
the
Internet
Developing and building
Dockerfile
app.R
FROM rocker/shiny:latest
WORKDIR /srv/shiny-server/
COPY . .
EXPOSE 3838
CMD ["/usr/bin/shiny-server.sh"]
$ docker build . –t holken/myshiny
$ docker run –p 3838:3838 holken/myshiny
$ docker push holken/myshiny
Deploy
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: myshiny-deployment
spec:
replicas: 2
template:
metadata:
labels:
app: myshiny
spec:
containers:
- name: myshiny
image:
docker.io/holken/myshiny:latest
Deployment descriptor
• What container(s)
• Number of instances (replicas)
• Secrets
• Persistent storage
• Resource requirements & limits
…
deployment.yaml
Networking
apiVersion: v1
kind: Service
metadata:
name: myshiny-service
spec:
ports:
- port: 80
targetPort: 3838
protocol: TCP
type: LoadBalancer
selector:
app: myshiny
Isolated by default
“Service” defines networking
service.yaml
Instance
1
Load
Balancer
Instance
2
Traffic
Service:
myshiny-service
App:
myshiny
Making it secure with Ingress and App ID
Shiny
Proxy Web App
A
Web App
BUser
registry
Forward
Lookup
Ingress
App ID
https://console.bluemix.net/docs/containers/cs_ingress.html#ingress
https://console.bluemix.net/docs/containers/cs_annotations.html#appid-auth
HTTPS
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-test-ingress
annotations:
ingress.bluemix.net/rewrite-path: "serviceName=myshiny-service rewrite=/"
ingress.bluemix.net/appid-auth: "bindSecret=binding-appid-test namespace=default
requestType=web serviceName=myshiny-service,web-service"
spec:
tls:
- hosts:
- growsmarter-test.eu-de.containers.appdomain.cloud
secretName: growsmarter-test
rules:
- host: growsmarter-test.eu-de.containers.appdomain.cloud
http:
paths:
- path: /shiny/
backend:
serviceName: myshiny-service
servicePort: 3838
- path: /
backend:
serviceName: web-service
servicePort: 80
Deploying a Shiny app
Develop
the app
Make it
run as a
Docker
container
Push the
container
to a
registry
Deploy to
Kubernetes
Expose to
the
Internet
docker build
docker run
docker push kubectl applykubectl apply
Deploying an API
Develop
the API
Make it
run as a
Docker
container
Push the
container
to a
registry
Deploy to
Kubernetes
Expose to
the
Internet
docker build
docker run
docker push kubectl applykubectl apply
Building APIs with plumber
https://www.rplumber.io/
Step 1. Building the model
create-model.R
Building APIs with plumber
Step 2. Do scoring
score-lm.R
https://www.rplumber.io/
Deploying
Deployment
Base image
Default port 8000
Can customize
Build model in Dockerfile or
separately?
FROM trestletech/plumber
WORKDIR /R/
COPY . .
EXPOSE 8000
RUN ["install2.r", "ggplot2", "readr"]
RUN ["R", "-f", "/R/create-model.R"]
CMD ["/R/score-lm.R"]
$ docker build . –t score-lm
$ docker run –p 8000:8000 score-lm
$ curl http://localhost:8000/score-lm?carat=0.5
{"price":[1621.8522]}
https://hub.docker.com/r/trestletech/plumber/
Securing APIs
1. Protect by network
2. Simple API key
3. API Gateway
Considerations:
• Public-facing APIs
• Brute force attacks
• Denial of service attacks
APIAPI
Gateway
ForwardApp Call
Registry
Lookup
Is R slow?
Compared to what?
What is too slow?
Several things we can do
https://www.thoughtworks.com/insights/blog/retail-analytics-hours-seconds-using-r
http://www.win-vector.com/blog/2019/01/timing-of-the-same-algorithm-in-r-python-and-c/
Joe Cheng, CTO RStudio:
“R can be slow, and is single-threaded –
But it’s probably less slow than you think”
Write efficient code Leverage multi-core Scale with multiple
instances
Integrate other
technologies
Vectorize!
RCpp
data.table
Profile to find
bottlenecks
ranger
parallel
foreach
doParallel
caret
Kubernetes –
load-balanced
pods
Node scaling
Map - Reduce
future / promises
ipc
Resources
RStudio: Load testing Shiny Applications
https://rstudio.github.io/shinyloadtest/
Joe Cheng: Shiny in Production (17 Jan)
https://speakerdeck.com/jcheng5/shiny-in-
production
Colin Fay: An Introduction to Docker for R Users
https://colinfay.me/docker-r-reproducibility/
My tutorial: Deploying Shiny Apps on IBM Cloud
https://github.com/holken1/deploying-r-on-
cloud/tree/master/shiny-on-ibm-cloud
• Free IBM Cloud cluster
• IBM Container Registry
My sample code:
https://github.com/holken1/deploying-r-on-cloud
IBM Cloud: https://cloud.ibm.com
Yes, we can
deploy R code.
It’s easy!
Secure! Scalable!
Deploying R for Production - SRUG

More Related Content

What's hot

.NET Day Switzerland 2019 - DOCKER + AZURE DEVOPS + KUBERNETES = ♥
.NET Day Switzerland 2019 - DOCKER + AZURE DEVOPS + KUBERNETES = ♥.NET Day Switzerland 2019 - DOCKER + AZURE DEVOPS + KUBERNETES = ♥
.NET Day Switzerland 2019 - DOCKER + AZURE DEVOPS + KUBERNETES = ♥Marc Müller
 
Infrastructure as Code
Infrastructure as CodeInfrastructure as Code
Infrastructure as CodePrasant Kumar
 
Harnessing the power of aws using dot net
Harnessing the power of aws using dot netHarnessing the power of aws using dot net
Harnessing the power of aws using dot netDror Helper
 
.NET Online TechTalk “Azure Cloud for DEV”
.NET Online TechTalk “Azure Cloud for DEV”.NET Online TechTalk “Azure Cloud for DEV”
.NET Online TechTalk “Azure Cloud for DEV”GlobalLogic Ukraine
 
Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...
Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...
Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...Ajeet Singh Raina
 
Using Go in DevOps
Using Go in DevOpsUsing Go in DevOps
Using Go in DevOpsEficode
 
Nils Rhode - Does it always have to be k8s - TeC Day 2019
Nils Rhode - Does it always have to be k8s - TeC Day 2019Nils Rhode - Does it always have to be k8s - TeC Day 2019
Nils Rhode - Does it always have to be k8s - TeC Day 2019Haufe-Lexware GmbH & Co KG
 
Azure Pipeline Tutorial | Azure DevOps Tutorial | Edureka
Azure Pipeline Tutorial | Azure DevOps Tutorial | EdurekaAzure Pipeline Tutorial | Azure DevOps Tutorial | Edureka
Azure Pipeline Tutorial | Azure DevOps Tutorial | EdurekaEdureka!
 
Azure DevOps Extensions
Azure DevOps ExtensionsAzure DevOps Extensions
Azure DevOps ExtensionsChristian Waha
 
Welcome - Kubernetes for the Enterprise - London
Welcome - Kubernetes for the Enterprise - LondonWelcome - Kubernetes for the Enterprise - London
Welcome - Kubernetes for the Enterprise - LondonVMware Tanzu
 
Azure DevOps: the future of integration and traceability
Azure DevOps: the future of integration and traceabilityAzure DevOps: the future of integration and traceability
Azure DevOps: the future of integration and traceabilityLorenzo Barbieri
 
Leveraging Azure DevOps across the Enterprise
Leveraging Azure DevOps across the EnterpriseLeveraging Azure DevOps across the Enterprise
Leveraging Azure DevOps across the EnterpriseAndrew Kelleher
 
Delivery Pipelines as a First Class Citizen @deliverAgile2019
Delivery Pipelines as a First Class Citizen @deliverAgile2019Delivery Pipelines as a First Class Citizen @deliverAgile2019
Delivery Pipelines as a First Class Citizen @deliverAgile2019ciberkleid
 
X-celerate 2019: Iterating fast with the MERN Stack
X-celerate 2019: Iterating fast with the MERN StackX-celerate 2019: Iterating fast with the MERN Stack
X-celerate 2019: Iterating fast with the MERN StackHaufe-Lexware GmbH & Co KG
 
Azure, DevOps and the Commodore 64
Azure, DevOps and the Commodore 64Azure, DevOps and the Commodore 64
Azure, DevOps and the Commodore 64Todd Whitehead
 

What's hot (20)

Kabanero
KabaneroKabanero
Kabanero
 
Appsody
AppsodyAppsody
Appsody
 
.NET Day Switzerland 2019 - DOCKER + AZURE DEVOPS + KUBERNETES = ♥
.NET Day Switzerland 2019 - DOCKER + AZURE DEVOPS + KUBERNETES = ♥.NET Day Switzerland 2019 - DOCKER + AZURE DEVOPS + KUBERNETES = ♥
.NET Day Switzerland 2019 - DOCKER + AZURE DEVOPS + KUBERNETES = ♥
 
Infrastructure as Code
Infrastructure as CodeInfrastructure as Code
Infrastructure as Code
 
Harnessing the power of aws using dot net
Harnessing the power of aws using dot netHarnessing the power of aws using dot net
Harnessing the power of aws using dot net
 
.NET Online TechTalk “Azure Cloud for DEV”
.NET Online TechTalk “Azure Cloud for DEV”.NET Online TechTalk “Azure Cloud for DEV”
.NET Online TechTalk “Azure Cloud for DEV”
 
Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...
Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...
Accelerate Your Automation Testing Effort using TestProject & Docker | Docker...
 
Using Go in DevOps
Using Go in DevOpsUsing Go in DevOps
Using Go in DevOps
 
Nils Rhode - Does it always have to be k8s - TeC Day 2019
Nils Rhode - Does it always have to be k8s - TeC Day 2019Nils Rhode - Does it always have to be k8s - TeC Day 2019
Nils Rhode - Does it always have to be k8s - TeC Day 2019
 
Tour of Azure DevOps
Tour of Azure DevOpsTour of Azure DevOps
Tour of Azure DevOps
 
Azure Pipeline Tutorial | Azure DevOps Tutorial | Edureka
Azure Pipeline Tutorial | Azure DevOps Tutorial | EdurekaAzure Pipeline Tutorial | Azure DevOps Tutorial | Edureka
Azure Pipeline Tutorial | Azure DevOps Tutorial | Edureka
 
Azure DevOps Extensions
Azure DevOps ExtensionsAzure DevOps Extensions
Azure DevOps Extensions
 
CI/CD@Scale
CI/CD@ScaleCI/CD@Scale
CI/CD@Scale
 
Welcome - Kubernetes for the Enterprise - London
Welcome - Kubernetes for the Enterprise - LondonWelcome - Kubernetes for the Enterprise - London
Welcome - Kubernetes for the Enterprise - London
 
Demystifying DevOps
Demystifying DevOpsDemystifying DevOps
Demystifying DevOps
 
Azure DevOps: the future of integration and traceability
Azure DevOps: the future of integration and traceabilityAzure DevOps: the future of integration and traceability
Azure DevOps: the future of integration and traceability
 
Leveraging Azure DevOps across the Enterprise
Leveraging Azure DevOps across the EnterpriseLeveraging Azure DevOps across the Enterprise
Leveraging Azure DevOps across the Enterprise
 
Delivery Pipelines as a First Class Citizen @deliverAgile2019
Delivery Pipelines as a First Class Citizen @deliverAgile2019Delivery Pipelines as a First Class Citizen @deliverAgile2019
Delivery Pipelines as a First Class Citizen @deliverAgile2019
 
X-celerate 2019: Iterating fast with the MERN Stack
X-celerate 2019: Iterating fast with the MERN StackX-celerate 2019: Iterating fast with the MERN Stack
X-celerate 2019: Iterating fast with the MERN Stack
 
Azure, DevOps and the Commodore 64
Azure, DevOps and the Commodore 64Azure, DevOps and the Commodore 64
Azure, DevOps and the Commodore 64
 

Similar to Deploying R for Production - SRUG

HPC Cloud Burst Using Docker
HPC Cloud Burst Using DockerHPC Cloud Burst Using Docker
HPC Cloud Burst Using DockerIRJET Journal
 
Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Microsoft
 
[20200720]cloud native develoment - Nelson Lin
[20200720]cloud native develoment - Nelson Lin[20200720]cloud native develoment - Nelson Lin
[20200720]cloud native develoment - Nelson LinHanLing Shen
 
Docker Birthday #5 Meetup Cluj - Presentation
Docker Birthday #5 Meetup Cluj - PresentationDocker Birthday #5 Meetup Cluj - Presentation
Docker Birthday #5 Meetup Cluj - PresentationAlex Vranceanu
 
Tampere Docker meetup - Happy 5th Birthday Docker
Tampere Docker meetup - Happy 5th Birthday DockerTampere Docker meetup - Happy 5th Birthday Docker
Tampere Docker meetup - Happy 5th Birthday DockerSakari Hoisko
 
Docker Bday #5, SF Edition: Introduction to Docker
Docker Bday #5, SF Edition: Introduction to DockerDocker Bday #5, SF Edition: Introduction to Docker
Docker Bday #5, SF Edition: Introduction to DockerDocker, Inc.
 
TechDays 2017 - Asp.NET Core Anwendungen automatisiert als Container ausliefern
TechDays 2017 - Asp.NET Core Anwendungen automatisiert als Container ausliefernTechDays 2017 - Asp.NET Core Anwendungen automatisiert als Container ausliefern
TechDays 2017 - Asp.NET Core Anwendungen automatisiert als Container ausliefernMarc Müller
 
Docker Orchestration: Welcome to the Jungle! JavaOne 2015
Docker Orchestration: Welcome to the Jungle! JavaOne 2015Docker Orchestration: Welcome to the Jungle! JavaOne 2015
Docker Orchestration: Welcome to the Jungle! JavaOne 2015Patrick Chanezon
 
Red Hat and kubernetes: awesome stuff coming your way
Red Hat and kubernetes:  awesome stuff coming your wayRed Hat and kubernetes:  awesome stuff coming your way
Red Hat and kubernetes: awesome stuff coming your wayJohannes Brännström
 
Docker Enterprise Edition Overview by Steven Thwaites, Technical Solutions En...
Docker Enterprise Edition Overview by Steven Thwaites, Technical Solutions En...Docker Enterprise Edition Overview by Steven Thwaites, Technical Solutions En...
Docker Enterprise Edition Overview by Steven Thwaites, Technical Solutions En...Ashnikbiz
 
Containers as a Service with Docker
Containers as a Service with DockerContainers as a Service with Docker
Containers as a Service with DockerDocker, Inc.
 
Docker Container As A Service - March 2016
Docker Container As A Service - March 2016Docker Container As A Service - March 2016
Docker Container As A Service - March 2016Patrick Chanezon
 
Designing Your Best Architectural Diagrams
Designing Your Best Architectural DiagramsDesigning Your Best Architectural Diagrams
Designing Your Best Architectural DiagramsEric D. Schabell
 
'DOCKER' & CLOUD: ENABLERS For DEVOPS
'DOCKER' & CLOUD:  ENABLERS For DEVOPS'DOCKER' & CLOUD:  ENABLERS For DEVOPS
'DOCKER' & CLOUD: ENABLERS For DEVOPSACA IT-Solutions
 
Docker and Cloud - Enables for DevOps - by ACA-IT
Docker and Cloud - Enables for DevOps - by ACA-ITDocker and Cloud - Enables for DevOps - by ACA-IT
Docker and Cloud - Enables for DevOps - by ACA-ITStijn Wijndaele
 
The DevOps paradigm - the evolution of IT professionals and opensource toolkit
The DevOps paradigm - the evolution of IT professionals and opensource toolkitThe DevOps paradigm - the evolution of IT professionals and opensource toolkit
The DevOps paradigm - the evolution of IT professionals and opensource toolkitMarco Ferrigno
 
The DevOps Paradigm
The DevOps ParadigmThe DevOps Paradigm
The DevOps ParadigmNaLUG
 
What's New in Docker - February 2017
What's New in Docker - February 2017What's New in Docker - February 2017
What's New in Docker - February 2017Patrick Chanezon
 
Development workflow guide for building docker apps
Development workflow guide for building docker appsDevelopment workflow guide for building docker apps
Development workflow guide for building docker appsAbdul Khan
 

Similar to Deploying R for Production - SRUG (20)

HPC Cloud Burst Using Docker
HPC Cloud Burst Using DockerHPC Cloud Burst Using Docker
HPC Cloud Burst Using Docker
 
Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015
 
[20200720]cloud native develoment - Nelson Lin
[20200720]cloud native develoment - Nelson Lin[20200720]cloud native develoment - Nelson Lin
[20200720]cloud native develoment - Nelson Lin
 
Docker Birthday #5 Meetup Cluj - Presentation
Docker Birthday #5 Meetup Cluj - PresentationDocker Birthday #5 Meetup Cluj - Presentation
Docker Birthday #5 Meetup Cluj - Presentation
 
Tampere Docker meetup - Happy 5th Birthday Docker
Tampere Docker meetup - Happy 5th Birthday DockerTampere Docker meetup - Happy 5th Birthday Docker
Tampere Docker meetup - Happy 5th Birthday Docker
 
Docker Bday #5, SF Edition: Introduction to Docker
Docker Bday #5, SF Edition: Introduction to DockerDocker Bday #5, SF Edition: Introduction to Docker
Docker Bday #5, SF Edition: Introduction to Docker
 
TechDays 2017 - Asp.NET Core Anwendungen automatisiert als Container ausliefern
TechDays 2017 - Asp.NET Core Anwendungen automatisiert als Container ausliefernTechDays 2017 - Asp.NET Core Anwendungen automatisiert als Container ausliefern
TechDays 2017 - Asp.NET Core Anwendungen automatisiert als Container ausliefern
 
Docker Orchestration: Welcome to the Jungle! JavaOne 2015
Docker Orchestration: Welcome to the Jungle! JavaOne 2015Docker Orchestration: Welcome to the Jungle! JavaOne 2015
Docker Orchestration: Welcome to the Jungle! JavaOne 2015
 
Red Hat and kubernetes: awesome stuff coming your way
Red Hat and kubernetes:  awesome stuff coming your wayRed Hat and kubernetes:  awesome stuff coming your way
Red Hat and kubernetes: awesome stuff coming your way
 
Docker Enterprise Edition Overview by Steven Thwaites, Technical Solutions En...
Docker Enterprise Edition Overview by Steven Thwaites, Technical Solutions En...Docker Enterprise Edition Overview by Steven Thwaites, Technical Solutions En...
Docker Enterprise Edition Overview by Steven Thwaites, Technical Solutions En...
 
Containers as a Service with Docker
Containers as a Service with DockerContainers as a Service with Docker
Containers as a Service with Docker
 
Docker Container As A Service - March 2016
Docker Container As A Service - March 2016Docker Container As A Service - March 2016
Docker Container As A Service - March 2016
 
Designing Your Best Architectural Diagrams
Designing Your Best Architectural DiagramsDesigning Your Best Architectural Diagrams
Designing Your Best Architectural Diagrams
 
Red hat cloud platforms
Red hat cloud platformsRed hat cloud platforms
Red hat cloud platforms
 
'DOCKER' & CLOUD: ENABLERS For DEVOPS
'DOCKER' & CLOUD:  ENABLERS For DEVOPS'DOCKER' & CLOUD:  ENABLERS For DEVOPS
'DOCKER' & CLOUD: ENABLERS For DEVOPS
 
Docker and Cloud - Enables for DevOps - by ACA-IT
Docker and Cloud - Enables for DevOps - by ACA-ITDocker and Cloud - Enables for DevOps - by ACA-IT
Docker and Cloud - Enables for DevOps - by ACA-IT
 
The DevOps paradigm - the evolution of IT professionals and opensource toolkit
The DevOps paradigm - the evolution of IT professionals and opensource toolkitThe DevOps paradigm - the evolution of IT professionals and opensource toolkit
The DevOps paradigm - the evolution of IT professionals and opensource toolkit
 
The DevOps Paradigm
The DevOps ParadigmThe DevOps Paradigm
The DevOps Paradigm
 
What's New in Docker - February 2017
What's New in Docker - February 2017What's New in Docker - February 2017
What's New in Docker - February 2017
 
Development workflow guide for building docker apps
Development workflow guide for building docker appsDevelopment workflow guide for building docker apps
Development workflow guide for building docker apps
 

Recently uploaded

Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一ffjhghh
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxfirstjob4
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 

Recently uploaded (20)

Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptx
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 

Deploying R for Production - SRUG

  • 1. Deploying R for production 2019-01-23 Stockholm R User Group
  • 2. Holger Hellebro IT Architect & Data Scientist Cognitive & Analytics IBM Global Business Services https://www.linkedin.com/in/holgerhellebro Twitter: @holken
  • 3. Can we deploy R code? Why would we? How? Will it scale? Security?
  • 4. Why deploy R stuff? Models for scoring Visualizations Data preparation Feature extraction Verify with more data Incoming data IT system Build model Predictions/ Decisions Training & testing data Model
  • 5. Deploy or rewrite? Why rewrite? • Minimize number of languages • IT team skills • Extreme performance / latency Why deploy? • Reuse code • Consistency • Easier to maintain
  • 6. Modern cloud technologies Helps us package code and data. Helps us run it on a cluster.
  • 7. “Dockerfile” tells docker how to build into an image Images contain all dependencies, but not a full Operating System Container images are uploaded to a registry to simplify deployment Docker images & containers Means of packaging and running software Independent of host system Include all dependencies Light weight
  • 10. Deploying a Shiny app Develop the app Make it run as a Docker container Push the container to a registry Deploy to Kubernetes Expose to the Internet
  • 11. Developing and building Dockerfile app.R FROM rocker/shiny:latest WORKDIR /srv/shiny-server/ COPY . . EXPOSE 3838 CMD ["/usr/bin/shiny-server.sh"] $ docker build . –t holken/myshiny $ docker run –p 3838:3838 holken/myshiny $ docker push holken/myshiny
  • 12. Deploy apiVersion: apps/v1beta1 kind: Deployment metadata: name: myshiny-deployment spec: replicas: 2 template: metadata: labels: app: myshiny spec: containers: - name: myshiny image: docker.io/holken/myshiny:latest Deployment descriptor • What container(s) • Number of instances (replicas) • Secrets • Persistent storage • Resource requirements & limits … deployment.yaml
  • 13. Networking apiVersion: v1 kind: Service metadata: name: myshiny-service spec: ports: - port: 80 targetPort: 3838 protocol: TCP type: LoadBalancer selector: app: myshiny Isolated by default “Service” defines networking service.yaml Instance 1 Load Balancer Instance 2 Traffic Service: myshiny-service App: myshiny
  • 14. Making it secure with Ingress and App ID Shiny Proxy Web App A Web App BUser registry Forward Lookup Ingress App ID https://console.bluemix.net/docs/containers/cs_ingress.html#ingress https://console.bluemix.net/docs/containers/cs_annotations.html#appid-auth HTTPS
  • 15. apiVersion: extensions/v1beta1 kind: Ingress metadata: name: my-test-ingress annotations: ingress.bluemix.net/rewrite-path: "serviceName=myshiny-service rewrite=/" ingress.bluemix.net/appid-auth: "bindSecret=binding-appid-test namespace=default requestType=web serviceName=myshiny-service,web-service" spec: tls: - hosts: - growsmarter-test.eu-de.containers.appdomain.cloud secretName: growsmarter-test rules: - host: growsmarter-test.eu-de.containers.appdomain.cloud http: paths: - path: /shiny/ backend: serviceName: myshiny-service servicePort: 3838 - path: / backend: serviceName: web-service servicePort: 80
  • 16. Deploying a Shiny app Develop the app Make it run as a Docker container Push the container to a registry Deploy to Kubernetes Expose to the Internet docker build docker run docker push kubectl applykubectl apply
  • 17. Deploying an API Develop the API Make it run as a Docker container Push the container to a registry Deploy to Kubernetes Expose to the Internet docker build docker run docker push kubectl applykubectl apply
  • 18. Building APIs with plumber https://www.rplumber.io/ Step 1. Building the model create-model.R
  • 19. Building APIs with plumber Step 2. Do scoring score-lm.R https://www.rplumber.io/
  • 20. Deploying Deployment Base image Default port 8000 Can customize Build model in Dockerfile or separately? FROM trestletech/plumber WORKDIR /R/ COPY . . EXPOSE 8000 RUN ["install2.r", "ggplot2", "readr"] RUN ["R", "-f", "/R/create-model.R"] CMD ["/R/score-lm.R"] $ docker build . –t score-lm $ docker run –p 8000:8000 score-lm $ curl http://localhost:8000/score-lm?carat=0.5 {"price":[1621.8522]} https://hub.docker.com/r/trestletech/plumber/
  • 21. Securing APIs 1. Protect by network 2. Simple API key 3. API Gateway Considerations: • Public-facing APIs • Brute force attacks • Denial of service attacks APIAPI Gateway ForwardApp Call Registry Lookup
  • 22. Is R slow? Compared to what? What is too slow? Several things we can do https://www.thoughtworks.com/insights/blog/retail-analytics-hours-seconds-using-r http://www.win-vector.com/blog/2019/01/timing-of-the-same-algorithm-in-r-python-and-c/ Joe Cheng, CTO RStudio: “R can be slow, and is single-threaded – But it’s probably less slow than you think”
  • 23. Write efficient code Leverage multi-core Scale with multiple instances Integrate other technologies Vectorize! RCpp data.table Profile to find bottlenecks ranger parallel foreach doParallel caret Kubernetes – load-balanced pods Node scaling Map - Reduce future / promises ipc
  • 24. Resources RStudio: Load testing Shiny Applications https://rstudio.github.io/shinyloadtest/ Joe Cheng: Shiny in Production (17 Jan) https://speakerdeck.com/jcheng5/shiny-in- production Colin Fay: An Introduction to Docker for R Users https://colinfay.me/docker-r-reproducibility/ My tutorial: Deploying Shiny Apps on IBM Cloud https://github.com/holken1/deploying-r-on- cloud/tree/master/shiny-on-ibm-cloud • Free IBM Cloud cluster • IBM Container Registry My sample code: https://github.com/holken1/deploying-r-on-cloud IBM Cloud: https://cloud.ibm.com
  • 25. Yes, we can deploy R code. It’s easy! Secure! Scalable!

Editor's Notes

  1. Security HTTPS / SSL Authentication (login) Multiple web apps Single-sign on