Since GAE went to the pricing model at the start of last week I have been wrestling with exceeding my quota of Datastore read and write operations. I'm not sure whether Google counts all updates for one writer as one write or whether every column update is counted as a separate write.
If the latter is true could I get around this by having one update function to update the 6 columns in the parameters or do will I also get charged for 6 updates?
Here is my existing code, used to update a player's score (rating) and the other details at the same time. At the moment I always populate name, email, rating, won, played and achievements with values from the client. One solution may be to only send these from the client side when they have changed value.
Long key = Long.valueOf(updateIdStr);
System.out.println("Key to update: " + key);
PlayerPersistentData ppd =null;
try {
ppd = pm.getObjectById(
PlayerPersistentData.class, key);
// for all of these, make sure we actually got a value via
// the query variables
if (name != null && name.length() > 0) {
ppd.setName(name);
}
if (ratingStr != null && ratingStr.length() > 0) {
ppd.setRating(rating);
}
if (playedStr != null && playedStr.length() > 0) {
ppd.setPlayed(played);
}
if (wonStr != null && wonStr.length() > 0) {
ppd.setWon(won);
}
if (encryptedAchievements != null
&& encryptedAchievements.length() > 0) {
ppd.setAchievements(achievements);
}
if (email != null & email.length() > 0) {
ppd.setEmail(email);
}
resp.getWriter().print(key);
} catch (JDOObjectNotFoundException e) {
resp.getWriter().print(-1);
}
}
The number of writes you are charged for depends on your entity. In general, you are charged for 1 write for the entity, and 1 write for each index update. Each indexed property is included in the ascending and descending single-property indexes, so there's a minimum of 2 writes per indexed entity, plus any writes for composite (user-defined) indexes.
When updating an existing entity, you're charged for the diff of the old indexes and the new ones. So if you modify one property, you'll be charged for the entity write, plus 4 writes per property (deleting the old value and inserting the new one) for the built-in indexes, and likewise for any composite indexes.
Note the changes in pricing structure going into effect July 1st, 2016 going from per operation
to per entity
. This changes how you think about writing efficiently (cost-wise) to Datastore.
New Cloud Datastore Pricing Starting July 1st, 2016
On July 1, 2016, Google Cloud Datastore pricing will change from charging per operation to charging per entity. This much simpler pricing means it will cost significantly less to use the full power of Google Cloud Datastore.
For example, in the current pricing, writing a new entity with 1 indexed property would cost 4 write operations. In the new pricing, it would cost only 1 entity write. Similarly, deleting this entity in the current pricing would cost 4 write operations, but in the new pricing it would cost only 1 entity delete.
来源:https://stackoverflow.com/questions/8113363/what-does-google-classify-as-a-datastore-write-operation-in-google-app-engine