7

I'm trying to implement a Push Notification system in PHP which needs to send massive notifications with the shortest delay possible, as described here:

push notification architecture

The drawback I see in this architecture is how to auto scale the Notification Workers. As far as I know, there is no way to count the pending tasks in a pull queue, nor to count the active workers. How would you do it?

Javier Marín
  • 2,166
  • 3
  • 21
  • 40

2 Answers2

0

There's queue statistics where you can get the number of tasks in the queue https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.api.taskqueue. We use it for monitoring the number of tasks, seems it can be used for your purpose.

marcadian
  • 2,608
  • 13
  • 20
0

I solved this counting the pending tasks in the Notification Queue with this method, and then adding workers depending on the number of pending tasks:

public static function task_count($queue)
    {
        $request = new google\appengine\TaskQueueFetchQueueStatsRequest();
        $response = new  google\appengine\TaskQueueFetchQueueStatsResponse();

        $request->addQueueName($queue);            

        google\appengine\runtime\ApiProxy::makeSyncCall('taskqueue', 'FetchQueueStats', $request, $response);

        return $response->getQueueStats(0)->getNumTasks();
    }
Javier Marín
  • 2,166
  • 3
  • 21
  • 40