Write Ops incurred during Model.put()

259 views
Skip to first unread message

Alex Epshteyn

unread,
Sep 16, 2011, 4:00:06 PM9/16/11
to google-a...@googlegroups.com
Does a Model.put() call incur Write Ops for every indexed property in
an entity regardless of whether the actual property values have
changed?

In other words, if I update a stored entity having only changed one
property, does the datastore update just that one index with 2 write
ops (asc & desc) or does it perform write ops to update all the
properties in the entity regardless of whether their values have
changed?

Jose Montes de Oca

unread,
Sep 20, 2011, 12:20:35 PM9/20/11
to google-a...@googlegroups.com
Hi,

AFAIK, when you do a put() it will update the hole entity. that been said it will also update all the indexes related to it.

Hope this helps!

Jose Montes de Oca

Simon Knott

unread,
Sep 20, 2011, 12:27:43 PM9/20/11
to google-a...@googlegroups.com
Hi,

According to Alfred, who's a Googler who appears to know lots about the datastore, only the updated values cause index write operations - see https://groups.google.com/d/msg/google-appengine/mjnSqQWOfqU/cgPVeHbrR8oJ for more info.

Jose Montes de Oca

unread,
Sep 20, 2011, 12:44:22 PM9/20/11
to google-a...@googlegroups.com
Thanks for bringing up that.

Indexes updated are property changed related.

I think that clears alex question. ;)

FYI, if you have properties you will never filter or sort on in a query, consider indexed=False to avoid this write ops

Best,
Jose

Alex Epshteyn

unread,
Sep 20, 2011, 2:09:48 PM9/20/11
to google-a...@googlegroups.com
So the Write Ops value in the new dev_appserver's Datastore Viewer
applies only to creating new entities of a kind, updating the entity i
is presumably much cheaper if only a few properties are changed?

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine/-/OcSq1WpF5noJ.
> To post to this group, send email to google-a...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengi...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>

Alfred Fuller

unread,
Sep 24, 2011, 4:00:44 PM9/24/11
to google-a...@googlegroups.com
Yes, the write ops for changing an entity depends on how many indexed properties you change. It is:
1 op for the entity
2 ops for each changed index value (1 to remove the old value and 1 to add the new)

Since it is not a fixed value and depends on what you actually modify, we do not (can not) show it in the dev_appserver's Datastore Viewer.

Alex Epshteyn

unread,
Sep 24, 2011, 4:19:38 PM9/24/11
to google-a...@googlegroups.com
Thanks for the definitive clarification, Alfred.

It would be awesome if you guys could show the actual Read/Write Ops
incurred by each URI under the Current Load section of the live
dashboard.

mac

unread,
Jun 6, 2012, 4:16:00 PM6/6/12
to google-a...@googlegroups.com
Hi Alfred,

Sorry for bringing this old topic back, I am also confused by the number showed in the dev_appserver.

I think you meant
1 op for the entity
2x2 = 4 ops for each changed index value (1 remove, 1 add and two directions)

My question is, do we need to do checks before calling put() to make sure it won't update all fields and their indices?

For example, do we need to do something like below?

s = Sample.all().get()[0]
changed = False

if s.field1 != field1_new_value:
  s.field1 = field1_new_value
  changed = True

if s.field2 != field2_new_value:
  s.field2 = field2_new_value
  changed = True

if s.field3 != field3_new_value:
  s.field3 = field3_new_value
  changed = True

if changed:
  s.put()

Or we can just do below.
s = Sample.all().get()[0]
s.field1 = field1_new_value 
s.field2 = field2_new_value 
s.field3 = field3_new_value 
s.put()

And datastore will check which fields were changed, only update those fields and their indices?

Alfred Fuller

unread,
Jun 8, 2012, 1:56:28 PM6/8/12
to google-a...@googlegroups.com
The datastore will only update indexes that changed, so if s didn't change you would only be charged 1 write op for the entity write (vs 0 write ops if you didn't call put at all). I believe the dev_appserver only shows the cost for inserting a new entity (which is substantially different from the cost of an update).

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/aqIb5sFqOfsJ.
Reply all
Reply to author
Forward
0 new messages