I am using Google Cloud Datastore through the Python library in a Python 3 flexible app engine environment. My flask application creates an object and then adds it to the datastore with:
ds = datastore.Client()
ds.put(entity)
In my testing, each call to put takes 0.5-1.5 seconds to complete. This does not change if I make two calls immediately one after the other like here.
I am wondering if the complexity of my object is the problem. It is multi-layered something like:
object = {
a: 1,
...,
b: [
{
d: 2,
...,
e: {
h: 3
}
}
],
c: [
{
f: 4,
...,
g: {
i: 5
}
}
]
}
which I am creating by nesting datastore.Entity's, each initialised with something like:
entity = datastore.Entity(key=ds.key(KIND))
entity.update(object_dictionary)
Both lists are 3-4 items long. The JSON equivalent of the object is ~2-3kb.
Is this not the recommended practice? What should I be doing instead?
More info:
I do not currently wrap this put of an Entity in a transaction. put is just a thin wrapper over put_multi. put_multi appears to create a batch, send the Entity, then commit the batch.
I do not specify the object's "Name/ID" (title from datastore online console). I allow the library to decide that for me:
datastore.key(KIND)
where KIND is just a string specifying my collection's name. The alternative to this would be:
datastore.key(KIND, <some ID>)
which I use for updating objects, rather that here where I am initially creating the object. The keys generated by the library are increasing with time, but not monotonically (e.g: id=4669294231158784, id=4686973524508672).
I am not 100% sure of the terminology of what I am doing ("are entities are in the same entity group, or if you use indexed properties"), but people seem to refer to the process as an "Embedded Entity" (i.e. here). In the datastore online console, under the entities section I only have a single "kind", not multiple kinds for each of my sub objects. Does that answer your question, or can I find this out somehow?
I only have one index on the collection, on a separate ID field which is a reference to another object in a different database for cross database lookup.
4669). For best latency and scaling those shouldn't be too close. For keys it's best to let Datastore generate IDs as you already have done. - Anigcloud datastorehelp. Where do I find the datastore's location? - Jon G