Thursday, July 10, 2008

A few months ago, Brian Dawson gave us a look at a bunch of perf tests for querying with ADO.NET and Entity Framework.

I adapted and enhanced those tests for my session at TechEd and then added even more logic to them as I dug into performance for my book.

I thought I would share some of what I found. All of the timings here are only meant to demonstrate the performance relatively between the technologies. They are hardly scientific benchmarks. In my book I've called them "backyard benchmarks".

The first set of tests is similar to Brian's in that I merely query for all of the customers in the customer table of AdventureWorksLT. That's about 450.

However, thanks to some tips from Brad Sarsfield and Bruno Guardia Robles who do performance testing on the DP team, we added an extra loop of queries to "prime the pump" so to speak and get anything like metadata loading, query caching and well as SQL Server query caching out of the way.

Here are the average times comparing different ways of querying data.

Again, read these as relative to one another and nothing else.

perfa

The EntityClient query looks funny, as you'd expect it to be faster. When the query is more complex and the data is shaped, the EntityClient performs better than ObjectQuery which makes sense to me.

This is not using any query caching  or pre-compiled queries or other advantages. I actually do a ton of those tests in that particular book chapter though.

Note that Entity Client and Object Services cache compiled queries by default (you can turn this off) which is a little different than using Compiled Queries in LINQ but has similar effect. So by default, the two Entity SQL tests are benefiting from that but the LINQ to Entities is not. So I really should either create a compiled query for LINQ to Entities and LINQ to SQL or turn query caching off for the two Entity SQL tests, because that's not completely fair.On the other hand, these *are* the defaults.

But what I found really interesting were updates.

There are a lot of ways to update data with ADO.NET. I chose to use DataAdapters since calling DataAdapter.Update is relative to calling context.SaveChanges. Here I queried those same 450 or so customers, edited each one, added 10 new ones then updated the database. I also was sure to clear out the 10 new records from the database after each iteration of the tests was complete. I didn't happen to do any deletes in this test.

I also did one DataAdapter.Update using UpdateBatch, just to compare.

In all cases I am starting the stopwatch, performing the update, then stopping the stopwatch. These times are the average of my 100 iterations of each test.

perfb

That is not a typo next to LINQ to SQL. I have not dug into why this is so different, but I had been told that EF was much faster than LINQ to SQL for updates. I had to see for myself. Bruno says this looks about right, but he's going to double check my code to make sure I didn't do anything completely wacky. And if I did it wasn't intentional.

But I was also interested to see that Object Services was also faster than DataAdapter.

I'm not trying to make a point here...just an observation because I have never seen these comparisons made before.

For all of these methods there are a lot of things you can do to improve this performance, not only in code but on the servers. And some server tweaks might benefit one method but not another. These tests are just using all defaults and gives me a stake in the ground. Now if I didn't need to actually finish my book, I could just keep at it which would be fun and interesting. But it wouldn't be so fun when Tim O'Reilly comes knocking on my door wondering where the heck my book is!

Thursday, July 10, 2008 4:07:06 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [4]  | 
 Wednesday, July 09, 2008

At Remix 07, I got an intro to the fact that Robotics Studio has APIs in there that are being used for some amazing projects that have nothign to do with robots. Last month I had a chance to talk with the man who heads up the Robotics Division at Microsoft and then coincidentally discovered an article on the same in the June 2008 MSDN Mag. Read more...

[A New DevLife Post]

Wednesday, July 09, 2008 10:28:19 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Friday, July 04, 2008

I definitely want to hear Roger Jennings' story! Roger, your turn!! :-)

Friday, July 04, 2008 7:53:04 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [1]  | 
 Thursday, July 03, 2008

I've been called out by Shawn Wildermuth to answer a bunch of questions about how I got started in programming, etc. I've done that over here and called out 5 more folks as well.

[A New DevLife Post]

Thursday, July 03, 2008 2:50:24 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Sunday, June 29, 2008

Sorry, this has nothing to do with Entity Framework. :-)

This is about garden slugs! I've been having some problems with the slugs decimating the Romaine in my garden. Since my husband wouldn't let me use any of his fancy beer to lure them away, I used the next trick I learned about - "over ripe" yogurt.

I put it in a small yogurt container, dug a whole in the corner of my garden and placed the container in there so that the top was level with the ground.

Yesterday I went out there and it looked like every slug in Vermont had heard about the awesome yogurt being served up on Moody road. They were coming out of the tall grass surrounding the garden and I think there must have been 50 there.

Whoa - big mistake. Now all of those slugs know about my romaine! I probably should have put that yogurt a bit farther from the garden.  It's similar to when people very cleverly buy those "bag a bugs" to lure Japanese Beetles away from their flowers. But the scent in those sacks is so powerful that it draws Japanese Beetles from far away. We've trained our neighbors not to use them. So far so good this year - the roses are blooming and actually sticking around!

I went out this morning to take a picture of the slugs because it was so bizarre and was surprised to find they were all gone. It was like a big frat party had just dissipated and to add to the image, there were two slugs that were slowly slugging there way away from the yogurt container back into the weeds that surround the garden.

The real goal was that they were supposed to fall in there and drown (I know - murderer! All for a head of lettuce!) but instead they drained the yogurt and headed off. At least the mass of slugs wasn't attacking the lettuce. But I'm sure they'll be back!  EEEEEW.

Sunday, June 29, 2008 11:06:48 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [1]  | 

After appying SP1 on one of my development machines, I got a COM Interop error when opening up SQL Server Management Studio. It took a few minutes to find the correct search terms on the web, but I found the simple fix to the problem pretty quickly. Read more here...

[A new DevLife post]

Sunday, June 29, 2008 10:57:38 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Friday, June 27, 2008

Apparently not everyone in the world has been conscious that today is Bill Gates last day working full time at Microsoft. My sister thought that the "moving on" story she heard on NPR was an obit... read more

[A New DevLife Post]

Friday, June 27, 2008 7:19:27 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Thursday, June 26, 2008

I've seen this quote in many of the recent discussions of the evils of Entity Framework.

In the comments to Sebastien Lambla's, blog post, Danny Simmons explains:

The goal is not one model to rule them all. The goal is unifying the way you specify models in many tools to be the same. That way you can leverage your learning across many things. That way if you WANT to reuse some of your model in multiple places you can, but the real thing is that it's absolutely ridiculous that I have to do essentially the same task in completely different ways when I want to build a model for my objects that talk to the database and another model (maybe with different contents but the same idea of a model) for my reporting and another one for whatever else. We're trying to eliminate the differences in experience and learning required for the parts of these tasks that are very much the same.

I thought it was worth surfacing.

Thursday, June 26, 2008 8:42:16 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
Thursday, June 26, 2008 3:29:44 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

If you live in northern Vermont and you have any interest in SQL Server, you'll want to attend tonight's VTSQL meeting. It's their official SQL Server 2008 Launch event, with gobs of swag provided by Microsoft and pizza sponsored by MyWebGrocer.com. Laura Blood and Roman Rehak "will be giving an overview of some of the most interesting new features arriving with SQL Server 2008.  We can’t cover everything, but hope to provide you with some insights on what new functionality you can look forward to."

6pm to 8pm at Competitive Computing.
354 Mountain View Drive
Colchester, VT 05446

More info and directions at www.VTSQL.org.

Thursday, June 26, 2008 10:22:23 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [3]  | 

The Entity Framework - don't get fooled in what is wrong about it

I guess it's better than calling myself a "self-congratulatory, self-proclaimed, egotistical doofus". ;-)

(In case the reference doesn't make sense, Sebastien has since modified his post so that the word "fooled" no longer links to my blog...)

Thursday, June 26, 2008 7:55:44 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [1]  | 
 Wednesday, June 25, 2008

Dinesh uses humor (laced with a little well deserved sarcasm) in response to "the sky is falling because Technology X doesn't fit my way of programming" ....

Design of LINQ to SQL - What was I thinking or was I?

Wednesday, June 25, 2008 6:40:49 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [4]  | 
 Tuesday, June 24, 2008

A few months ago I came across this great interview with Jimmy Nilsson where he is talking abot LINQ and Entity Framework. I love what he says about LINQ - that it's a beatiful thing and it's small & compact. And I'd been very curious to know what Jimmy thought of EF since I missed my chance to meet him and ask directly when I went to Stockholm. The most memorable thing he said is that it is "very big". Indeed it is. And of the things he didn't like about SQL, the most critical was the lack of value objects (aka, thanks to Roger, what we know as complex types in EF). With EF it was that it comes so deeply from the data world and the lack of PI. Here he calls IPOCO the "anti-PI". While I don't have time to set EF aside and sit down and really learn about Domain Driven development as  well as the slew of ORMs out there, I do try to grab what I can when I can and I this particular video, with Jimmy's soft-spoken contemplative way of addressing these topics, has definitely stuck in my mind.

In addition, Jimmy talked about Eric Evan's book "Domain Driven Design" and that it "is like poetry". I loved that and immediately went to find some text from it to understand what he meant and I totally agree. It's not like a typical technical book to begin with because it is all concept and written from the heart. It really made me look back at how I was "speaking" when writing my book which is very different than how I write, for example, here in my blog. In the book I am trying to explain technical concepts, how to, how to code, what does this mean, what does that mean, how does this thing work, etc...and it feels much more formal. As I go back and review what I've written, I hope to loosen it up a bit. And eventually, I'll get to read Eric's book for content, not just writing style, but for the time being I need to stay focused...

And in the meantime, I'm really excited that Jimmy & Eric are both part of the advisory group for v2 of Entity Framework.

Tuesday, June 24, 2008 4:54:34 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [2]  | 

Anyone who knows me knows that I just LOVE being in the middle of a controversy. Well, that's a lie. I sure know how to pick'em, though, eh?

I have to deal with java and open source people (many who I am friends with, respect and admire) harassing me because I use Microsoft products.

I have to deal with C# developers (many who I am friends with, respect and admire) harassing me because I code with VB mostly.

Now I have to deal with Domain Driven Developers (many who I am friends with, respect and admire) harassing me because I have been busting my ass learning about Entity Framework and trying to share what I know because there are going to be a lot of people who will have to learn how to use it.

So now there's this no-confidence vote to ... I think just counter all of the information about what EF is and can do to vocalize where it's failings are if you have a particular programming style which is not supported in v1 (though are targetted for v2 and important to the EF team) and to take the EF team (which is part of the Data Programmability team, which is part of the SQL Server team) to task for creating a data-centric framework. However, the way the petition is laid out is to list it's failings to be sure that nobody gets "tricked" into using Entity Framework. Not to say the only problems are from the perspective of Domain developers, or nHibernate users or those who need Persistence Ignorance. I struggle with it too, but I just don't have the same needs as those that are listed in the petition.

I was happy to see that the Entity Framework team has responded very quickly. This responsiveness is new for them, and a new part of their recently announced transparent design for v2 which they adopted from the Astoria team.

Tuesday, June 24, 2008 2:53:45 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [2]  | 
 Monday, June 23, 2008

With the exception of this past Saturday (which I took advantage of by riding my bike 50 miles to our friends' house on the lake), this has been what the forecast has looked like for the past 2 weeks. Unfortunately, this particular view is for the upcoming week.

I tried to sneak in a little ride this afternoon, but got caught in the rain.

Of course, it's not like we're flooded out, so I can't complain. We live up on a hill so we're more susceptible to the lightning than the rain.

Monday, June 23, 2008 7:13:10 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Wednesday, June 18, 2008

I have no idea when this went on to Amazon, but it's there now. I STILL don't have a cover which is frustrating. And Amazon seems to have given me some extra time to finish my book! The "about the author" seems funny to me. I guess since, unlike some people, I don't have 80 books under my belt (LINQ to Dummies is #80 for John), or even one, there's not much to lean on here.

 

I think it's going to be a bit longer than 456 pages, but hell, with that big discount, I better find another day job! I think that will translate to about $1/book that goes towards my royalties! And I doubt that the book will hit Amazon's top 10 list (of all categories) like Bill, Scott & Devin's ASP.NET book which has already been reprinted numerous times!

Wednesday, June 18, 2008 3:39:42 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [4]  | 
 Monday, June 16, 2008

Working with the online MSDN Library today, I lost the tree view for navigating. I finally found it, can you? Find out for yourself here!

[A New DevLife Post]

Monday, June 16, 2008 9:52:02 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Friday, June 13, 2008

In my cycling hey day, there was no mountain road that I wouldn't try to climb. I rode over passes in Colorado, gaps in Vermont, and many routes in the Catskill mountains. While Colorado's climbs are long (15+ miles in many cases with no break) the grades are slight - perhaps 6%. In the northeast the climbs are shorter but incredibly steep - 10-15+ % grades are not uncommon.

But still that was a while ago and I have gotten older, fatter and lazier since then. (And of course spend a lot more time in front of my computer than in those days).

I live right near one of the most challenging climbs in Vermont, the App Gap (aka Appalachian Gap). The summit is 7 miles from my house. Eleven years ago I rode up the other side and still had to take a break near the top.

Whenever I ride in that direction, when I get to Route 17, I always take a right - away from the Gap climb. Last night, I did that once again, but on the way home I figured what the heck, I'll just see how far I can go.

No, I did not make it to the top. The grades get up to 18% and are relentless. I went about 1/2 way and was surprised that I even got that far but  after a 1/2 mile of struggling, when I looked around the curve and saw where I was, I knew that there was another 1/4 mile before it leveled off a bit, so I bailed.

Getting even that far was great for me, but it wasn't from some unknown source of strength because I have only ridden a total of 50 miles this season. It's more from sheer will and also thanks to my past experience of how to climb and how to pace myself. So maybe I'll start working on it. While I'd rather go for a ride where I get a steady workout rather than killing myself and then doing a long scary windy descent, there's nothing like the challenge that says "you cannot do this". The most important thing for me was to realize that it was stupid for me to wait to even try it because I will NEVER feel ready.

Friday, June 13, 2008 8:23:08 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 
 Thursday, June 12, 2008

I just added my latest completed chapter (Advanced Modelling and Stored Procedures) into my spreadsheet where I keep track of my progress. When I added the page count (56! - Heck, stored procs deserve their own book anyway) the total added up to exactly 300 pages.

I'm getting there but I still have a ways to go!

Thursday, June 12, 2008 12:54:19 PM (Eastern Standard Time, UTC-05:00)  #     |  Comments [0]  | 

In moving a Silverlight 2.0 app to use Beta2, I hit a wall when trying to access my WCF Service which was working perfectly fine in Beta1.

I was getting a 404 telling me that the service could not be found. While the exception itself told me nothing more than that a 404 had been returned (with no inner exception), thankfully the exception popup window had the critical info in the header: TargetInvocationException crossed a native/managed boundary. So I knew that the cross domain problem had returned with the new bits. It wasn't until I searched for "TargetInvocationException" and found this thread did I see exactly what was causing the problem and how to fix it.

It turns out that if you are using the ClientAccessPolicy.xml file in the service to overcome cross domain issues, the file needs to be modified from what was needed in Beta1. Here's the new version. What has changed is that I am now using the "http-request-headers" attribute in the allow-from element. I'm not sure why it worked without this in Beta1, but this works now, so I'm a happy camper.

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
    <cross-domain-access>
        <policy>
            <allow-from http-request-headers="*">
                <domain uri="*"/>

            </allow-from>
            <grant-to>
                <resource path="/" include-subpaths="true"/>
            </grant-to>
        </policy>
    </cross-domain-access>
</access-policy>

Thursday, June 12, 2008 8:09:30 AM (Eastern Standard Time, UTC-05:00)  #     |  Comments [2]  |