I'm accessing the Google Cloud Datastore from my PHP App Engine instance using the official google-cloud-php library.
I'm consistently seeing upwards of 0.35 seconds of latency per query. Even for simple queries with less than 100 entities in the datastore.
My web app needs to make 4 or so consecutive datastore queries per request which makes datastore entirely unusable (consistently 1.5 to 3 seconds of latency per page load)
Am I missing something?
Here's how I connect to the datastore:
// Same issue even without 'authCache' (a memcached wrapper).
$authCache = new DatastoreAuthCache();
$datastore = new DatastoreClient([
'projectId' => AppIdentityService::getApplicationId(),
'authCache' => $authCache
]);
Datastore::$ds = $datastore;
Here are two examples of my queries:
// Lookup by keys.
$ds = Datastore::get();
$queryResults = $ds->lookupBatch($keys);
$rows = keyValue($queryResults, "found");
// Query by fields.
$query = $ds->query()
->kind(self::EntityName)
->filter('owner', '=', $a)
->filter('target', '=', $b)
->limit(1)
->keysOnly();
$results = $ds->runQuery($query);
foreach ($results as $entity) {
return $entity;
}
Is this level of latency to be expected? I can cache some results, but not all, so I'm hoping this is an issue on my end.
Here's what I've already tried to improve the latency:
-
Added 'authCache' handler to cache datastore API tokens (no impact)
-
Confirmed datastore and app engine instance are in the same region
-
Confirmed that index.yaml is set up correctly
-
Confirmed that latency is due to datastore calls and not business logic
-
Other database backends are working fine (Cloud SQL server returns in < 0.1 seconds). The local datastore emulator also returns in <0.01 seconds.
What can I do to improve this latency?
from Google Datastore very slow from PHP AppEngine
No comments:
Post a Comment