0
4

3 回答 3

0

The answer is to use appstats and you can find out:

AppStats

To keep your application fast, you need to know:

Is your application making unnecessay RPC calls? Should it be caching data instead of making repeated RPC calls to get the same data? Will your application perform better if multiple requests are executed in parallel rather than serially?

Run some tests, try it both ways and see what appstats says.

But I'd say that your option 2) is better simply because you don't need to search millions of entities. But who knows for sure? The trouble is that "resources" are a dozen different things in app engine - CPU, datastore reads, datastore writes etc etc etc.

于 2012-11-07T16:57:10.660 回答
0

For your User class, set a unique ID for each user (such as a username or email address). For the Word class, set the parent of each Word class as a specific User.

So, if you wanted to look up words from a specific user, you would do an ancestor query for all words belonging to that specific user.

By setting an ID for each user, you can get that user by ID as opposed to doing an additional query.

More info on ancestor queries: https://developers.google.com/appengine/docs/java/datastore/queries#Ancestor_Queries

More info on IDs: https://developers.google.com/appengine/docs/java/datastore/entities#Kinds_and_Identifiers

于 2012-11-07T17:13:02.890 回答
0

It really depends on the queries you're using. I assume that you want to find all the words given a certain owner.

Most likely, 2 would be cheaper, since you'll need to fetch the user entity instead of running a query.

2 will be a bit more work on your part, since you'll need to manually keep the list synchronized with the instances of Word

Off the top of my head I can think of 2 problems with #2, which may or may not apply to you:

A. If you want to find all the owners given a certain word, you'll need to keep that list of words indexed. This affects your costs. If you mostly find words by owner, and rarely find owners by words, it'll still make sense to do it this way. However, if your search pattern flips around and you're searching for owners by words a lot, this may be the wrong design. As you see, you need to design the models based on the queries you will be using.

B. Entities are limited to 1MB, and there's a limit on the number of indexed properties (5000 I think?). Those two will limit the number of words you can store in your list. Make sure that you won't need more than that limit of words per user. Method 1 allows you unlimted words per user.

于 2012-11-07T17:57:09.617 回答