We have hit a wall and are trying to understand what may have happened.
We have written a restful API using phalcon for speed. The root return from phalcon is blinding quick at 300ms as there is no MySQL. The additional latency (above our target of 100ms) is that the network has not been optimised. That said, the application responds very quickly considering it is running on a t1.small backed by a t1.micro database on RDS.
As soon as we run a MySQL command, the whole system slows down. Queries take on average 1.2 seconds to execute which is beyond acceptable.
we have set up the MySQL connection as:
<?php
$di->setShared('db', function() use ($di) {
$type = strtolower($di->get('config')->database->adapter);
$creds = array(
'host' => $di->get('config')->database->host,
'username' => $di->get('config')->database->username,
'password' => $di->get('config')->database->password,
'dbname' => $di->get('config')->database->name
);
The simplest query that runs first is an authorization query and this looks like:
<?php
$org = Organisation::findFirst("searchID = '".$that."' AND thisOther = '".$this."'");
We tried this other query which is closer to raw SQL but had the same result.
<?php
$query = $this->modelsManager->createQuery("SELECT searchID FROM \Models\Organisation WHERE searchID = :org: AND thisOther = '".$this."'");
$org = $query->execute(array('org' => $that))->getFirst();
$sID = $org['orgUID'];
This takes on avergae 1.2 seconds to excecute.
We then thought ah! Database. So we upgraded the instance to a m3.2xlarge with 30gigs of memory and the result was almost exactly the same at 1.12 secs.
There are pages with 5-6 queries on them that execute in order and drive the API response time to 8 seconds in some instances which is painful for such a fast framework. The models have also all be correctly defined with the column names declared to conserve resources.
Thus we think that maybe there is something we are doing wrong in the framework that we are unaware of.
any ideas where the issue could be? what settings do we need to modify?