Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduce Cloud Run

Yuki Ito
October 18, 2020

Introduce Cloud Run

Yuki Ito

October 18, 2020
Tweet

More Decks by Yuki Ito

Other Decks in Technology

Transcript

  1. What is Cloud Run Cloud Run is a managed compute

    platform that enables you to run stateless containers that are invocable via web requests... Cloud Run is serverless: it abstracts away all infrastructure management... https://cloud.google.com/run/docs
  2. Architecture ✅ Using same API interceptors ✅ Managed by API

    Definitions ✅ Using same Monitoring environments
  3. Job resource "google_pubsub_topic" "foo" { name = "foo" } resource

    "google_pubsub_subscription" "job-foo" { name = "job-foo" topic = google_pubsub_topic.foo.name push_config { push_endpoint = "<cloud run endpoint uri>" } }
  4. Job resource "google_project_iam_member" "pubsub-is-sa-token-creator" { project = "<project name>" role

    = "roles/iam.serviceAccountTokenCreator" member = "serviceAccount:service-<project number>@gcp-sa-pubsub... } roles/iam.serviceAccountTokenCreator
  5. Job resource "google_service_account" "job-api-invoker" { // ... account_id = "job-api-invoker"

    } resource "google_pubsub_subscription" "job-foo" { name = "job-foo" topic = google_pubsub_topic.foo.name push_config { push_endpoint = "<cloud run endpoint uri>" oidc_token { service_account_email = "job-api-invoker@..." audience = "<audience>" } } }
  6. Deployment gcloud alpha builds submit \ --pack image=asia-northeast1-docker.pkg.dev/... jobs: deploy:

    # ... steps: # ... - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master with: version: '314.0.0' project_id: <project name> service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY }} export_default_credentials: true GitHub Actions
  7. Cold Start Run Firestore app, err := firebase.NewApp( ctx, config,

    ) // ... firestoreClient, err := app.Firestore(ctx) // ... server.ListenAndServe()
  8. Cold Start Run Firestore Time app.Firestore(ctx) // Creating Firestore client

    server.ListenAndServe() // Listening on PORT Connecting to Firestore // Asynchronous!!
  9. Cold Start Run Firestore Time app.Firestore(ctx) // Creating Firestore client

    server.ListenAndServe() // Listening on PORT Connecting to Firestore // Asynchronous Additional Latency!!
  10. Cold Start Run Firestore app, err := firebase.NewApp( ctx, config,

    option.WithGRPCDialOption(grpc.WithBlock()), ) // ... firestoreClient, err := app.Firestore(ctx) // ... server.ListenAndServe()
  11. Cold Start Run Firestore Time app.Firestore(ctx) // Creating Firestore client

    server.ListenAndServe() // Listening on PORT Connecting to Firestore // Synchronous
  12. Background Process ❌ Avoiding background activities https://cloud.google.com/run/docs/tips/general#avoiding_background_activities When an application

    running on Cloud Run finishes handling a request, the container instance's access to CPU will be disabled or severely limited. Therefore, you should not start background threads or routines that run outside the scope of the request handlers.
  13. Background Process e.g.) Push notification Time Start handling a request

    Finish handling a request Start a background routine for the notification Finish a background routine for the notification
  14. Background Process e.g.) Push notification Time Start handling a request

    Finish handling a request Start a background routine for the notification Finish a background routine for the notification CPU
  15. Background Process e.g.) Push notification Time Start handling a request

    Finish handling a request Start a background routine for the notification Finish a background routine for the notification CPU
  16. Background Process e.g.) Push notification Time Start handling a request

    Finish handling a request Start sending the notification Finish sending the notification CPU
  17. Background Process e.g.) Push notification Time Start handling a request

    Finish handling a request Start sending the notification Finish sending the notification CPU Additional Latency!!
  18. Background Process e.g.) Push notification Time Start handling a request

    Finish handling a request Push a queue to Cloud Tasks or Pub/Sub CPU