→ Scalable apps and asynchronous processing made easy

Google Cloud Platform


  • App Engine - PaaS
  • Compute Engine - IaaS
  • Cloud Storage - Object Store
  • Cloud SQL - Stuctured Data
  • Cloud Datastore - NoSQL datastore
  • BigQuery - fast big data analysis
  • Many other APIs available

https://developers.google.com/cloud/

Google Cloud Platform


  • App Engine - PaaS
  • Compute Engine - IaaS
  • Cloud Storage - Object Store
  • Cloud SQL - Stuctured Data
  • Cloud Datastore - NoSQL datastore
  • BigQuery - fast big data analysis
  • Many other APIs available

https://developers.google.com/cloud/

App Engine

PHP on App Engine

App Engine APIs and Services

App Engine APIs and Services

introducing our app...

App Engine Task Queues

  • Define tasks and process them asynchronously, in the background
  • App Engine automatically scales processing capacity
    • matches your queue configuration and processing volume.

Task Queues

Description

Adding A Task to a Queue

Tasks are HTTP request handlers.

require_once 'google/appengine/api/taskqueue/PushTask.php';
use \google\appengine\api\taskqueue\PushTask;
...
$task_params = ['feed_url' => $feed_url, 'user_id' => $user_id];
$task = new PushTask('/do_add_feed_task', $task_params);
$task->add();
      

A Task Handler

require_once 'google/appengine/api/taskqueue/PushTask.php';
use \google\appengine\api\taskqueue\PushTask;
...
$task_params = ['feed_url' => $feed_url, 'user_id' => $user_id];
$task = new PushTask('/do_add_feed_task', $task_params);
$task->add();
      

The /do_add_feed_task handler script:

<?php
$user_id = $_POST['user_id'];
$feed_url = $_POST['feed_url'];
// in the handler, add the feed based on the task params
if (!addNewFeed($feed_url, $user_id)) {
  // ....
}
  

Scheduling Tasks

  $task_options = [
    'delay_seconds' => $task_delay_seconds,
  ];

  $task = new PushTask('/rss_poll_handler',
    ['feed_url' => $feed_url],
    $task_options);
    

Where are we putting all this feed data?

Google Cloud Datastore


NoSQL datastore: Highly scalable, distributed, robust, schemaless datastore

(and Memcache)

Using Multiple Queues

queue:
- name: rss-poll
  rate: 50/s
- name: add-feed
  rate: 10/s
    
require_once 'google/appengine/api/taskqueue/PushTask.php';
use \google\appengine\api\taskqueue\PushTask;
...
$task = new PushTask('/rss_poll_handler',
  ['feed_url' => $feed_url], $task_options)->add('rss-poll');
          

Demo: a deeper dive

But, feeds get updated at very different rates...

Demo: multiple polling queues

Summary: Scalable PHP apps on App Engine

  • Task Queue background processing is decoupled from request/response cycle
    • scheduling, execution and retries handled automatically
    • no management of queuing infrastructure
  • App autoscales with increased demand: both frontend and background requests
  • Lets you focus on building the app.

Resources

<Thank You!>