NOODB: Projections Complete?

Last night’s post included some samples showing that the property resolution was working. One of them actually wasn’t due to a recursion problem. That was a minor fix.

After that, plugging everything in went pretty easy. I thought that I might have to change some things around due to how the property resolution ended up working, but I didn’t. Everything fit together well.

I ran some tests to see how performance is under a variety of scenarios. Remember that I haven’t paid any particular attention to performance; I’m keeping it mind as I go, but I’m not testing and analyzing yet. These are the first-pass numbers.

Each test is run 10 times. Additionally, the server is warmed up before the first test executes.

All tests retrieve every movie review from the dvdfriend database.

Get Everything

This simply calls client.GetObjects<MovieReview>(). This is just a read of every object of the given type. It’s the full graph. You probably don’t want to use this in most situations. It’s like doing “select * from table”.

Iteration 0: 2006.4515ms, Count=2904
Iteration 1: 1841.9566ms, Count=2904
Iteration 2: 1830.4992ms, Count=2904
Iteration 3: 1806.5747ms, Count=2904
Iteration 4: 1894.1823ms, Count=2904
Iteration 5: 1806.3163ms, Count=2904
Iteration 6: 1732.0549ms, Count=2904
Iteration 7: 1692.3944ms, Count=2904
Iteration 8: 1788.4181ms, Count=2904
Iteration 9: 1769.857ms, Count=2904
Average: 1816.8705

Query Everything – No Select Clause

This runs a query without specifying a select clause. Because there isn’t a select clause, it will automatically retrieve the entire graph.

from r in MovieReview
Iteration 0: 1862.5085ms, Count=2904
Iteration 1: 1768.9057ms, Count=2904
Iteration 2: 1805.549ms, Count=2904
Iteration 3: 1810.9975ms, Count=2904
Iteration 4: 1809.6719ms, Count=2904
Iteration 5: 1747.9265ms, Count=2904
Iteration 6: 1814.4942ms, Count=2904
Iteration 7: 1801.1459ms, Count=2904
Iteration 8: 1789.6214ms, Count=2904
Iteration 9: 1722.5566ms, Count=2904
Average: 1793.33772

Query Everything – Deep Select Clause

The end result of this is the same as “Query Everyting – No Select Clause”. The difference here is that we specify r.**, which tells it to get all of the fields.

So what’s the difference? The difference is that when you don’t specify the select clause, it doesn’t resolve the properties, it just gets everything. With the select clause of r.**, it resolves all of the properties. Every query receives a list of all of the properties.

An optimization here would be to detect if all fields are explicitly selected. If so, then drop the projections. But, the hit isn’t that big, so I’m not in a big rush for it. (I will put it on the to-do list).

from r in MovieReview select r.**
Iteration 0: 1854.0705ms, Count=2904
Iteration 1: 1868.8928ms, Count=2904
Iteration 2: 1989.5221ms, Count=2904
Iteration 3: 1849.2452ms, Count=2904
Iteration 4: 1799.233ms, Count=2904
Iteration 5: 1823.9078ms, Count=2904
Iteration 6: 1817.7604ms, Count=2904
Iteration 7: 1846.124ms, Count=2904
Iteration 8: 1848.9052ms, Count=2904
Iteration 9: 1789.4011ms, Count=2904
Average: 1848.70621

Query Everything – Shallow Select Clause

Now we start to see some real benefits. Rather than get the entire review graph, it only gets the top level properties.

from r in MovieReview select r.*
Iteration 0: 814.5349ms, Count=2904
Iteration 1: 848.7935ms, Count=2904
Iteration 2: 855.4855ms, Count=2904
Iteration 3: 842.2453ms, Count=2904
Iteration 4: 823.8852ms, Count=2904
Iteration 5: 793.6476ms, Count=2904
Iteration 6: 743.9888ms, Count=2904
Iteration 7: 789.7292ms, Count=2904
Iteration 8: 897.9049ms, Count=2904
Iteration 9: 871.061ms, Count=2904
Average: 828.12759

User Reviews – Without Projections

This is the use case that prompted the implementation of the projections. Obviously they were always a required feature, but I didn’t need it until building the User Review page in DvdFriend. The user review pulls back all of the user’s reviews, including the review text which isn’t shown. It only needs 4 fields; it’s pulling back everything else for no reason.

from r in MovieReview where r.Author.ScreenName=='DvdFriend' orderby r.ReviewDate descending
Iteration 0: 1012.1361ms, Count=1293
Iteration 1: 948.4727ms, Count=1293
Iteration 2: 927.2112ms, Count=1293
Iteration 3: 923.0019ms, Count=1293
Iteration 4: 844.9469ms, Count=1293
Iteration 5: 924.5507ms, Count=1293
Iteration 6: 985.8055ms, Count=1293
Iteration 7: 927.8918ms, Count=1293
Iteration 8: 913.6041ms, Count=1293
Iteration 9: 903.036ms, Count=1293
Average: 931.06569

User Reviews – With Projections

Ta da! Now we only pull back the exact fields that the user review page needs.

from r in MovieReview where r.Author.ScreenName=='DvdFriend' select r.ReviewDate, r.Movie.ProductName, r.Rating orderby r.ReviewDate descending
Iteration 0: 614.1987ms, Count=1293
Iteration 1: 589.8489ms, Count=1293
Iteration 2: 552.8296ms, Count=1293
Iteration 3: 540.0005ms, Count=1293
Iteration 4: 552.5914ms, Count=1293
Iteration 5: 554.0354ms, Count=1293
Iteration 6: 543.7779ms, Count=1293
Iteration 7: 552.0717ms, Count=1293
Iteration 8: 585.1147ms, Count=1293
Iteration 9: 596.9977ms, Count=1293
Average: 568.14665

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: