SlideShare a Scribd company logo
Hacking google cloud run
Hacking Cloud Run
Opinionated take on how to use Google Cloud Run for
functions that take longer than 10–15 minutes
Aviv Laufer - Principal Reliability Engineer at DoiT
International
Google Developers Expert - Cloud
@avivl
Across GeographiesEngineering Consulting
Data and Analytics
Machine Learning & AI
Kubernetes
App Modernization
Cost Optimization
On Any Platform
Unique Business Model
$0of added costs...
Proven
50+ Certifications
OSS Projects - https://github.com/doitintl/
Open source tools for everyone using Google
Cloud
BigQuery plugin for Grafana
Zorya - Instance Scheduler
Iris - Automatic resource tagging
Shamash - Autoscaling for Dataproc
Serverless Containers
● Source-driven
● No-ops
● Pay for usage
Cloud Run
Serverless Containers
Cloud Run
Serverless agility for containerized apps
Container to production in
seconds
Just "deploy"
Any stateless container Any
language, any library URL in
seconds
Natively Serverless
No servers to manage Focus on
writing code Scale up fast
Scale down to zero
Pay for exact usage
One experience,
where you want it
One developer experience
Fully managed or your GKE cluster
Consistent APIs & tooling
Portable with Knative without
vendor lock-in
Cloud Run
gcloud beta run deploy hello-run 
--image gcr.io/cloudrun/hello 
--allow-unauthenticated --concurrency=80
…
Service [hello-run] revision [hello-run-00001]
has been deployed and is serving traffic at https://hello-run-
upbps3cgka-uc.a.run.app
It’s All Very
Impressive But….
Your tasks can run up to 15 minutes
on the fully managed service or 10
minutes if you use Google Cloud
Run on your own GKE cluster.
Assumptions
● As long as there are incoming
requests, the Cloud Run will not
shut down the container.
● The load balancer will distribute
incoming requests equally
between service instances.
Hacking google cloud run
Hacking google cloud run
func main() {
ServerId = uuid.New().String()
log.Println("Starting Long John Silver demo " + ServerId)
httpListenPort := Config.Port
if httpListenPort == "" {
httpListenPort = "8080"
}
ctx := context.Background()
var err error
fsClient, err = firestore.NewClient(ctx, Config.ProjectId)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
hostPort := net.JoinHostPort("0.0.0.0", httpListenPort)
rtr := mux.NewRouter()
rtr.HandleFunc("/job", longTask).Methods(http.MethodPost)
rtr.HandleFunc("/job/{id:[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}}/{output}",
getResults).Methods(http.MethodGet)
rtr.HandleFunc("/job/{id:[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}}/{output}",
deleteDoneTask).Methods(http.MethodDelete)
rtr.HandleFunc("/job/{id:[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}}",
taskStatus).Methods(http.MethodGet)
rtr.HandleFunc("/job/{id:[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}}",
deleteTask).Methods(http.MethodDelete)
http.Handle("/", rtr)
err = http.ListenAndServe(hostPort, nil)
if err != nil {
log.Fatal(err)
}
}
func longTask(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
var p types.Payload
err := decoder.Decode(&p)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if p.Data == "" {
http.Error(w, "Missing data in payload", http.StatusBadRequest)
return
}
id := uuid.New().String()
accepted := types.AcceptedResponse{ServerId, types.Task{"/job/" + id, id}}
t := types.TaskData{"Nothing yet wait for it....", types.StatusPending, "0", ServerId}
_, err = fsClient.Doc("tasks/"+id).Create(context.Background(), &t)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
js, err := json.Marshal(accepted)
go worker(id, p.Data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusAccepted)
w.Write(js)
}
{
"ServerId": "88b8d21b-dcbb-4cd5-804e-750d4e1d33d4",
"task": {
"href": "/job/2e03e000-045c-4bd4-a82a-386166d8254a",
"id": "2e03e000-045c-4bd4-a82a-386166d8254a"
}
}
func worker(id string, data string) {
now := time.Now().UTC()
counter := 0
loops := (Config.WorkTime * 60) / Config.WorkerSleepTime
for {
select {
case <-Quit:
msg := <-Quit
if msg == id {
return
}
break
default:
time.Sleep(time.Duration(Config.WorkerSleepTime) * time.Second)
dur := time.Since(now)
// We are done working :)
if counter >= int(loops) {
t := types.TaskData{"We are golden", types.StatusDone, dur.String(), "None of your business"}
fsClient.Doc("tasks/"+id).Set(context.Background(), &t)
return
}
ctx := context.Background()
docsnap, err := fsClient.Doc("tasks/" + id).Get(ctx)
if err != nil {
log.Println(err)
return
}
var t types.TaskData
docsnap.DataTo(&t)
t.Duration = dur.String()
fsClient.Doc("tasks/"+id).Set(context.Background(), &t)
counter++
}
}
}
func taskStatus(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
task, _ := params["id"]
time.Sleep(time.Duration(time.Duration(Config.RequestSleepTime) * time.Second))
ok, t, err := getTask(task)
if !ok {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
return
}
jobStatus := types.StatusResponse{t, task, ServerId}
if t.Status == types.StatusDone {
http.Redirect(w, r, "/job/"+task+"/output", http.StatusSeeOther)
}
w.Header().Set("Content-Type", "application/json")
js, err := json.Marshal(jobStatus)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if t.Status == types.StatusPending {
w.WriteHeader(http.StatusOK)
}
w.Write(js)
}
func getResults(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
task, _ := params["id"]
ok, t, err := getTask(task)
if !ok {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
return
}
jobStatus := types.StatusResponse{t, task, ServerId}
js, err := json.Marshal(jobStatus)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(js)
}
Conclusions and Observations
Cloud Run is cool!
Google is working to extend the timeouts of requests
Always try to understand how the services you use work
https://github.com/doitintl/long_john_silver/
Hacking google cloud run

More Related Content

What's hot (20)

A Hands-On Introduction To Docker Containers.pdf
A Hands-On Introduction To Docker Containers.pdfA Hands-On Introduction To Docker Containers.pdf
A Hands-On Introduction To Docker Containers.pdf
Edith Puclla
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
Peng Xiao
 
DevOps Powerpoint Presentation Slides
DevOps Powerpoint Presentation SlidesDevOps Powerpoint Presentation Slides
DevOps Powerpoint Presentation Slides
SlideTeam
 
Learning Docker from Square One
Learning Docker from Square OneLearning Docker from Square One
Learning Docker from Square One
Docker, Inc.
 
Docker: From Zero to Hero
Docker: From Zero to HeroDocker: From Zero to Hero
Docker: From Zero to Hero
fazalraja
 
Microsoft Azure cloud services
Microsoft Azure cloud servicesMicrosoft Azure cloud services
Microsoft Azure cloud services
Najeeb Khan
 
KubeCon EU 2022: From Kubernetes to PaaS to Err What's Next
KubeCon EU 2022: From Kubernetes to PaaS to Err What's NextKubeCon EU 2022: From Kubernetes to PaaS to Err What's Next
KubeCon EU 2022: From Kubernetes to PaaS to Err What's Next
Daniel Bryant
 
Kubernetes Basics
Kubernetes BasicsKubernetes Basics
Kubernetes Basics
Eueung Mulyana
 
Serverless and Design Patterns In GCP
Serverless and Design Patterns In GCPServerless and Design Patterns In GCP
Serverless and Design Patterns In GCP
Oliver Fierro
 
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
Edureka!
 
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC WongDocker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker, Inc.
 
DevOps with Kubernetes
DevOps with KubernetesDevOps with Kubernetes
DevOps with Kubernetes
EastBanc Tachnologies
 
Introduction to Google Cloud Platform
Introduction to Google Cloud PlatformIntroduction to Google Cloud Platform
Introduction to Google Cloud Platform
Sujai Prakasam
 
CD using ArgoCD(KnolX).pdf
CD using ArgoCD(KnolX).pdfCD using ArgoCD(KnolX).pdf
CD using ArgoCD(KnolX).pdf
Knoldus Inc.
 
Kubernetes
KubernetesKubernetes
Kubernetes
erialc_w
 
Monitoring kubernetes with prometheus
Monitoring kubernetes with prometheusMonitoring kubernetes with prometheus
Monitoring kubernetes with prometheus
Brice Fernandes
 
Tom Grey - Google Cloud Platform
Tom Grey - Google Cloud PlatformTom Grey - Google Cloud Platform
Tom Grey - Google Cloud Platform
Fondazione CUOA
 
Building an analytics workflow using Apache Airflow
Building an analytics workflow using Apache AirflowBuilding an analytics workflow using Apache Airflow
Building an analytics workflow using Apache Airflow
Yohei Onishi
 
GitOps and ArgoCD
GitOps and ArgoCDGitOps and ArgoCD
GitOps and ArgoCD
Omar Fathy
 
Docker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and ContainersDocker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and Containers
Yajushi Srivastava
 
A Hands-On Introduction To Docker Containers.pdf
A Hands-On Introduction To Docker Containers.pdfA Hands-On Introduction To Docker Containers.pdf
A Hands-On Introduction To Docker Containers.pdf
Edith Puclla
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
Peng Xiao
 
DevOps Powerpoint Presentation Slides
DevOps Powerpoint Presentation SlidesDevOps Powerpoint Presentation Slides
DevOps Powerpoint Presentation Slides
SlideTeam
 
Learning Docker from Square One
Learning Docker from Square OneLearning Docker from Square One
Learning Docker from Square One
Docker, Inc.
 
Docker: From Zero to Hero
Docker: From Zero to HeroDocker: From Zero to Hero
Docker: From Zero to Hero
fazalraja
 
Microsoft Azure cloud services
Microsoft Azure cloud servicesMicrosoft Azure cloud services
Microsoft Azure cloud services
Najeeb Khan
 
KubeCon EU 2022: From Kubernetes to PaaS to Err What's Next
KubeCon EU 2022: From Kubernetes to PaaS to Err What's NextKubeCon EU 2022: From Kubernetes to PaaS to Err What's Next
KubeCon EU 2022: From Kubernetes to PaaS to Err What's Next
Daniel Bryant
 
Serverless and Design Patterns In GCP
Serverless and Design Patterns In GCPServerless and Design Patterns In GCP
Serverless and Design Patterns In GCP
Oliver Fierro
 
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
Edureka!
 
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC WongDocker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker, Inc.
 
Introduction to Google Cloud Platform
Introduction to Google Cloud PlatformIntroduction to Google Cloud Platform
Introduction to Google Cloud Platform
Sujai Prakasam
 
CD using ArgoCD(KnolX).pdf
CD using ArgoCD(KnolX).pdfCD using ArgoCD(KnolX).pdf
CD using ArgoCD(KnolX).pdf
Knoldus Inc.
 
Kubernetes
KubernetesKubernetes
Kubernetes
erialc_w
 
Monitoring kubernetes with prometheus
Monitoring kubernetes with prometheusMonitoring kubernetes with prometheus
Monitoring kubernetes with prometheus
Brice Fernandes
 
Tom Grey - Google Cloud Platform
Tom Grey - Google Cloud PlatformTom Grey - Google Cloud Platform
Tom Grey - Google Cloud Platform
Fondazione CUOA
 
Building an analytics workflow using Apache Airflow
Building an analytics workflow using Apache AirflowBuilding an analytics workflow using Apache Airflow
Building an analytics workflow using Apache Airflow
Yohei Onishi
 
GitOps and ArgoCD
GitOps and ArgoCDGitOps and ArgoCD
GitOps and ArgoCD
Omar Fathy
 
Docker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and ContainersDocker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and Containers
Yajushi Srivastava
 

Similar to Hacking google cloud run (20)

Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless framework
Luciano Mammino
 
DevSum'15 : Microsoft Azure and Things
DevSum'15 : Microsoft Azure and ThingsDevSum'15 : Microsoft Azure and Things
DevSum'15 : Microsoft Azure and Things
Thomas Conté
 
Android architecture components with cloud firestore
Android architecture components with cloud firestoreAndroid architecture components with cloud firestore
Android architecture components with cloud firestore
Pankaj Rai
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP Developers
Jeremy Lindblom
 
Working with data using Azure Functions.pdf
Working with data using Azure Functions.pdfWorking with data using Azure Functions.pdf
Working with data using Azure Functions.pdf
Stephanie Locke
 
Go react codelab
Go react codelabGo react codelab
Go react codelab
Alberto Jesús Gutiérrez Juanes
 
NodeJS
NodeJSNodeJS
NodeJS
Alok Guha
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Somkiat Puisungnoen
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Yaetos_Meetup_SparkBCN_v1.pdf
Yaetos_Meetup_SparkBCN_v1.pdfYaetos_Meetup_SparkBCN_v1.pdf
Yaetos_Meetup_SparkBCN_v1.pdf
prevota
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
Alex Su
 
Going Serverless
Going ServerlessGoing Serverless
Going Serverless
Mattias Severson
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
Aaron Stannard
 
Yaetos Tech Overview
Yaetos Tech OverviewYaetos Tech Overview
Yaetos Tech Overview
prevota
 
Deploying Web Apps with PaaS and Docker Tools
Deploying Web Apps with PaaS and Docker ToolsDeploying Web Apps with PaaS and Docker Tools
Deploying Web Apps with PaaS and Docker Tools
Eddie Lau
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
Manish Pandit
 
DCEU 18: Docker Containers in a Serverless World
DCEU 18: Docker Containers in a Serverless WorldDCEU 18: Docker Containers in a Serverless World
DCEU 18: Docker Containers in a Serverless World
Docker, Inc.
 
HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...
HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...
HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...
Andrey Devyatkin
 
nuclio Overview October 2017
nuclio Overview October 2017nuclio Overview October 2017
nuclio Overview October 2017
iguazio
 
iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)
Eran Duchan
 
Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless framework
Luciano Mammino
 
DevSum'15 : Microsoft Azure and Things
DevSum'15 : Microsoft Azure and ThingsDevSum'15 : Microsoft Azure and Things
DevSum'15 : Microsoft Azure and Things
Thomas Conté
 
Android architecture components with cloud firestore
Android architecture components with cloud firestoreAndroid architecture components with cloud firestore
Android architecture components with cloud firestore
Pankaj Rai
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP Developers
Jeremy Lindblom
 
Working with data using Azure Functions.pdf
Working with data using Azure Functions.pdfWorking with data using Azure Functions.pdf
Working with data using Azure Functions.pdf
Stephanie Locke
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Yaetos_Meetup_SparkBCN_v1.pdf
Yaetos_Meetup_SparkBCN_v1.pdfYaetos_Meetup_SparkBCN_v1.pdf
Yaetos_Meetup_SparkBCN_v1.pdf
prevota
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
Alex Su
 
Yaetos Tech Overview
Yaetos Tech OverviewYaetos Tech Overview
Yaetos Tech Overview
prevota
 
Deploying Web Apps with PaaS and Docker Tools
Deploying Web Apps with PaaS and Docker ToolsDeploying Web Apps with PaaS and Docker Tools
Deploying Web Apps with PaaS and Docker Tools
Eddie Lau
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
Manish Pandit
 
DCEU 18: Docker Containers in a Serverless World
DCEU 18: Docker Containers in a Serverless WorldDCEU 18: Docker Containers in a Serverless World
DCEU 18: Docker Containers in a Serverless World
Docker, Inc.
 
HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...
HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...
HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...
Andrey Devyatkin
 
nuclio Overview October 2017
nuclio Overview October 2017nuclio Overview October 2017
nuclio Overview October 2017
iguazio
 
iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)
Eran Duchan
 

Recently uploaded (20)

Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 

Hacking google cloud run

  • 2. Hacking Cloud Run Opinionated take on how to use Google Cloud Run for functions that take longer than 10–15 minutes Aviv Laufer - Principal Reliability Engineer at DoiT International Google Developers Expert - Cloud @avivl
  • 3. Across GeographiesEngineering Consulting Data and Analytics Machine Learning & AI Kubernetes App Modernization Cost Optimization On Any Platform Unique Business Model $0of added costs... Proven 50+ Certifications
  • 4. OSS Projects - https://github.com/doitintl/ Open source tools for everyone using Google Cloud BigQuery plugin for Grafana Zorya - Instance Scheduler Iris - Automatic resource tagging Shamash - Autoscaling for Dataproc
  • 7. Cloud Run Serverless agility for containerized apps Container to production in seconds Just "deploy" Any stateless container Any language, any library URL in seconds Natively Serverless No servers to manage Focus on writing code Scale up fast Scale down to zero Pay for exact usage One experience, where you want it One developer experience Fully managed or your GKE cluster Consistent APIs & tooling Portable with Knative without vendor lock-in
  • 8. Cloud Run gcloud beta run deploy hello-run --image gcr.io/cloudrun/hello --allow-unauthenticated --concurrency=80 … Service [hello-run] revision [hello-run-00001] has been deployed and is serving traffic at https://hello-run- upbps3cgka-uc.a.run.app
  • 9. It’s All Very Impressive But…. Your tasks can run up to 15 minutes on the fully managed service or 10 minutes if you use Google Cloud Run on your own GKE cluster.
  • 10. Assumptions ● As long as there are incoming requests, the Cloud Run will not shut down the container. ● The load balancer will distribute incoming requests equally between service instances.
  • 13. func main() { ServerId = uuid.New().String() log.Println("Starting Long John Silver demo " + ServerId) httpListenPort := Config.Port if httpListenPort == "" { httpListenPort = "8080" } ctx := context.Background() var err error fsClient, err = firestore.NewClient(ctx, Config.ProjectId) if err != nil { log.Fatalf("Failed to create client: %v", err) } hostPort := net.JoinHostPort("0.0.0.0", httpListenPort) rtr := mux.NewRouter() rtr.HandleFunc("/job", longTask).Methods(http.MethodPost) rtr.HandleFunc("/job/{id:[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}}/{output}", getResults).Methods(http.MethodGet) rtr.HandleFunc("/job/{id:[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}}/{output}", deleteDoneTask).Methods(http.MethodDelete) rtr.HandleFunc("/job/{id:[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}}", taskStatus).Methods(http.MethodGet) rtr.HandleFunc("/job/{id:[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}}", deleteTask).Methods(http.MethodDelete) http.Handle("/", rtr) err = http.ListenAndServe(hostPort, nil) if err != nil { log.Fatal(err) } }
  • 14. func longTask(w http.ResponseWriter, r *http.Request) { decoder := json.NewDecoder(r.Body) var p types.Payload err := decoder.Decode(&p) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } if p.Data == "" { http.Error(w, "Missing data in payload", http.StatusBadRequest) return } id := uuid.New().String() accepted := types.AcceptedResponse{ServerId, types.Task{"/job/" + id, id}} t := types.TaskData{"Nothing yet wait for it....", types.StatusPending, "0", ServerId} _, err = fsClient.Doc("tasks/"+id).Create(context.Background(), &t) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } js, err := json.Marshal(accepted) go worker(id, p.Data) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusAccepted) w.Write(js) }
  • 15. { "ServerId": "88b8d21b-dcbb-4cd5-804e-750d4e1d33d4", "task": { "href": "/job/2e03e000-045c-4bd4-a82a-386166d8254a", "id": "2e03e000-045c-4bd4-a82a-386166d8254a" } }
  • 16. func worker(id string, data string) { now := time.Now().UTC() counter := 0 loops := (Config.WorkTime * 60) / Config.WorkerSleepTime for { select { case <-Quit: msg := <-Quit if msg == id { return } break default: time.Sleep(time.Duration(Config.WorkerSleepTime) * time.Second) dur := time.Since(now) // We are done working :) if counter >= int(loops) { t := types.TaskData{"We are golden", types.StatusDone, dur.String(), "None of your business"} fsClient.Doc("tasks/"+id).Set(context.Background(), &t) return } ctx := context.Background() docsnap, err := fsClient.Doc("tasks/" + id).Get(ctx) if err != nil { log.Println(err) return } var t types.TaskData docsnap.DataTo(&t) t.Duration = dur.String() fsClient.Doc("tasks/"+id).Set(context.Background(), &t) counter++ } } }
  • 17. func taskStatus(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) task, _ := params["id"] time.Sleep(time.Duration(time.Duration(Config.RequestSleepTime) * time.Second)) ok, t, err := getTask(task) if !ok { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) return } jobStatus := types.StatusResponse{t, task, ServerId} if t.Status == types.StatusDone { http.Redirect(w, r, "/job/"+task+"/output", http.StatusSeeOther) } w.Header().Set("Content-Type", "application/json") js, err := json.Marshal(jobStatus) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } if t.Status == types.StatusPending { w.WriteHeader(http.StatusOK) } w.Write(js) }
  • 18. func getResults(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) task, _ := params["id"] ok, t, err := getTask(task) if !ok { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) return } jobStatus := types.StatusResponse{t, task, ServerId} js, err := json.Marshal(jobStatus) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write(js) }
  • 19. Conclusions and Observations Cloud Run is cool! Google is working to extend the timeouts of requests Always try to understand how the services you use work

Editor's Notes

  • #6: Many of you probably already know these products but here we go. So traditionally serverless has a couple of these characteristics It's typically source driven You write your code, function, or app, whatever it might be Obviously, it's serverless, so I don't want any operational overhead. So it's no ops. And it has a characteristic that you typically pay only when you're using it. It scales to zero. But some things can be constraining. So adding custom libraries or native binaries can sometimes be cumbersome. Arbitrary run times-- we talked about the runtime support expanding on App Engine and Cloud Functions. But what if I want to run Erlang or Rust? Well, you're sort of requiring the platform providers to do that, and to do a lot of work before you can get that. Well, there's another solution that people have been using for this and it's containers. And so the container is sort of the lingua franca of portability of code. So it's obviously container driven. Unfortunately, most container platforms do have at least some amount of ops. You're creating a cluster. You're managing a cluster of containers. And the billing model is typically you pay for the instances of the machines that are running your containers. But it has these advantages where you can specify arbitrary libraries, you can specify arbitrary run times. It operates in a very similar way to a virtual machine. So what we're announcing this week is a new product in GCP called Cloud Run which brings those two worlds together. So you get all the benefits of a container being able to run an arbitrary runtime, arbitrary custom libraries. You specify whatever you want in that container. But we give you all the operational model of a serverless product. So you have no ops. You only pay when it's being used.
  • #7: Cloud Run brings those two worlds together. So you get all the benefits of a container being able to run an arbitrary runtime, arbitrary custom libraries. You specify whatever you want in that container. But we give you all the operational model of a serverless product. So you have no ops. You only pay when it's being used.
  • #8: So we're going to talk a little bit about this. There's three aspects that we identify with Cloud Run. One is container to production in seconds. This was a really hard requirement for us. It's one thing to say, well, you can run a container. But if you have to jump through 20 hoops to get there, then it's not really serverless. There's no rule book that says serverless has to be easy, but we all know that that's how we want it to be. So I should be able to give Google a Docker image and curly URL in a few seconds. It's natively serverless. What does that mean? Well, if you go onto the Cloud Console and you create a Cloud Run serverless, it will be serverless by default. It will be no ops. You pay only for what you use. It scales up fast. It scales to zero, et cetera. And the last point is it's one developer experience wherever you want to go. I'll talk more about this a little bit later. But we also have a version of Cloud Run that runs on your GKE cluster. So if you're already a GKE customer or you already have made investment in Kubernetes and that's where you want to run the bulk of your workload, you may have developers internally that want some of the agility and benefits of the serverless developer experience where I just have to deploy and I get something back in seconds. Well, you can run that same capability on your GKE cluster. And some of you may have encountered this term Knative. I'll talk a little bit more about that as well. So Cloud Run is Google Cloud's implementation of the Knative serving specification. I'll pause that and leave it there. I'll come back to it later. It's very simple.
  • #10: Only one port, not all google services are accessible, some apps need to be changed (cobra naming for env variables)
  • #12: Problem: How can a client retrieve the result of such an operation without keeping the HTTP connection open for a too long time? Especially, as there normally will be a timeout for HTTP connections because every open connection allocates a certain amount of memory at the server and the client. How can we avoid wasting resources for open connections and for computations whose result will not be received by the client in case of a timeout? Forces: As the network is not reliable, the client may loose the connection before the server has completed processing the result. The longer the server takes to respond to the client, the higher the chances that the client may no longer be available to receive the result or interested to retrieve it. The server may need to perform expensive computations to process client requests and these would be repeated every time the client resends the request in case the connection on the previous one is dropped. Performing computations and delivering their results are two concerns that make completely different demands on the server infrastructure. Solution: The long running operation itself is turned into a resource, created using the original request with a response telling the client where to find the results. ese will be available once the operation running in the background completes. The client may poll the resource to GET its current progress, and will eventually redirected to another resource representing the result, once the long running operation has completed. Since the output has its own URI, it becomes possible GET it multiple times, as long as it has not been deleted. Additionally, the long running operation can be cancelled with a DELETE request, thus implicitly opping the operation on the server, or deleting its output if it had already completed in the meanwhile.
  • #16: The ‘href’ field is what the client should poll in order to get the operation status. The client will need to call this endpoint every few seconds in order to get the status of the job. That’s also making sure the instance is up.
  • #17: In order to support more than one Google Cloud Run instance, I had to have some sort of persistent layer in order to share the task statuses. Initially, my intent was to use the Google Cloud Memorystore [2], however, it is not yet accessible from the Google Cloud Run. Therefore, I am using Google Cloud Firestore [3] as a persistent layer.
  • #22: Shameless plug gphercon