0

We are currently developing an app with the google appengine for PHP an would like to optimize our costs.

At several times a day (morning, evening, midnight) we have a high amount of calculations that are started by a background-task. The sub-tasks take about 3-5 minutes each and are serialized (i.e. a finished sub-task puts the next sub-task to the query) in order to keep the number of used instances at the same time as low as possible. That leads to pretty long calculation times though.

Are there any times a day (like midnight) where instances have higher costs? Are there any ways to save some more costs? Are there any ways to improve the calculation times, for example by rearranging the independent calculations in a different order?

Thanks in advance!

Edit: Code-Example - all background-files look similar to this

require_once 'google/appengine/api/taskqueue/PushTask.php';
use google\appengine\api\taskqueue\PushTask;

$cron_data = get_cron_data();
if(empty($cron_data)) {
  end_cronjob($cron_data["cron_id"]);
  exit();
}

$data_array = db_select ( "SELECT * FROM db_table WHERE id > ". 
               $cron_data["data_id"] ." ORDER BY id ASC LIMIT 5");
if(empty($data_array)) {
  end_cronjob($cron_data["cron_id"]);
  exit();
}

foreach($data_array as $d) {
  calculate($d);
  update_cronjob($cron_data["cron_id"], $d["data_id"]);
}

$task = new PushTask('/this_task', ["cron_id" =>  $cron_data["cron_id"]]);
$task_name = $task->add();
exit();
kof
  • 45
  • 1
  • 7
  • 3
    Do instance costs vary by time of day? No. Can you save money by optimizing your code? Yes. When you want to know how to improve the performance of your code you will have to post the code in question for analysis. You could also write your calculations in python or Java and put them in a different service (module) which could give you a boost. – konqi May 18 '16 at 10:22
  • Thanks so far! I updated my post with a short example how all tasks work. – kof May 19 '16 at 06:52
  • You probably already have an index on db_table for column id, so what is happening inside calculate($d) that is so expensive? Have you tried to profile the code and see what is taking the most time? – mba12 May 20 '16 at 16:04
  • Raw computation tasks would be cheaper on Compute Engine VMs. Pre-emptible ones especially! – Tom May 21 '16 at 21:39

0 Answers0