Friday, February 10, 2012

The Cost of Complexity

I find it stupendous that a single application can bring a decently modern i7 quadcore with 4gb of RAM to its knees. The app in question is our custom product that I'm helping work on. It stores data  locally on the client in SQL Server with Entity Framework, syncs with a server database via Sync Framework, and renders itself with WPF. It's simply a beast. Solution explorer in Visual Studio shows about 25-30 projects in the solution and each project has anywhere from 20 to 200 classses, with quite a few classes weighing in at over 1,000 lines of code. The whole suite easily gobbles up 2gb of memory on its own, while the remaining 2gb are consumed entirely by Windows 7, Visual Studio 2010, and this browser.

Now I mostly blame Entity Framework and only slightly WPF. Entity Framework is a discordant combination of being easy to use and while at the same time extremely difficult to master. On the one hand it's pleasantly easy to create the schema and start using the entities in code the very same day (and by the same token also easy to fall prey to lazy practice that apparently will do a number on your performance), while on the other hand, it's very difficult to reign in the effects of this ease-of-use and the results can get out of hand. We have had several teams analyze performance from different levels - from the overall architectural choices made early on and down to the details of how views are written, entities materialized, and so forth. We've certainly made quite a few improvements, but the biggest of these came not from improving the efficiency of the data layer, but simply by wrapping the data operations in asynchronous calls. WPF shares a portion of the blame here as well. The queries, while slow, typically don't account for more than half or three quarters of the time a user spends wishing he was at the dentist instead. No, the rest of the time is spent rendering huge data grids. Why am I letting WPF off the hook easily you ask? Well, the problem here is largely attributable to design choices, such as caving in when the customer asked for data grids that show hundreds of rows of data with an equal number of columns. Another portion of the blame can also be leveled at Telerik, which while providing beautiful and functional controls is at the same time another dirty pig in this mud bath the user has to slog through.  Nevertheless, I still can't help but blame WPF for some of the performance problems when I can see scroll bars chug along and occasionally see the entire UI lock up for entire seconds. But I shouldn't be so hard on this application since it really has sped up a lot over the last year. It was entirely normal to have to wait upwards of 30 seconds for a single tab to open and display nothing more complex than a simple message inbox. I am aware that care is required in tweaking the display of grids, but that's exactly the problem in my opinion. The whole technology stack we're using is extremely simple to use and yet infuriatingly, devilishly difficult to tune and tweak.

When I say this app dwarfs iTunes and makes Visual Studio feel like Notepad, I'm not kidding folks. I also admit that the app deals with huge amounts of data due to its "enterprise" nature. There is verbose logging being done in triplicate to the hard drive, the database and a logging service, which in a manner of speaking could be considered necessary since each log records different variations of the same events for different audiences. No data is being deleted and even our sparse test data set has bloated the client database to over 9gb, though most of this is transactional logging (exporting the same data sans transactional data yields a file that only weighs 300mb). Myriad small things have crept into the design and architecture of the application to meet very specific and sometimes narrow minded business requirements that were assembled by different business units within the same client organization. These requirements are often impossible, costly or just painful to implement in light of oftentimes conflicting or even duplicate requirements that originated from different business units. Lastly, the rigid and literal interpretation of design documents by the testing teams combined with unrealistically short turnaround times required for bug fixes has resulted in many suboptimal solutions to problems that never existed. I'm going to skip over the half dozen or so integrations to third party systems that are at the best of times brittle and non-functional, but I hope I've drawn a clear picture of the problem.

Thursday, February 9, 2012

DIY Tablet Part 2 - Battery power

This is part 2 of the series where I'll probably electrocute myself trying to build my own tablet. See part 1 to see what prompted this insanity.

I found a great guide on building a battery pack, and it explains the basics pretty well. What I'll probably end up doing for my Pandaboard is to wire 4 NiMH cells in series to get 4.8v, at roughly 2Ah. Considering that the PB draws between 0.4 and 0.8 amps (not counting peaks of up to 1.4 amps during boot), this should get me several hours of juice. Depending on how much space I have I'd like to squeeze in 8 cells, but it's not a huge issue if I can't.

Wednesday, February 8, 2012

DIY Tablet Part 1 - Pandaboard

[Update: This is now Part 1 of my series "DIY Tablet" where I'll write about building a tablet device from scratch]

Ok, I know this isn't at all related to web coding, but I don't care. I went out and ordered myself a Pandaboard for a couple of different reasons. First, let me gush about the technical side of this thing because it looks like a dynamite device. It has a dual core ARM Cortex A9 CPU clocking in at 1.2ghz, 1gb of RAM, and more expansion ports (including USB host!) than many laptops. It costs less than $200. It has no moving parts and draws 1 amp of power. It can play 1080p video.

With such admirable qualities there are already a couple of things I want to try...

The first and most obvious use is probably to turn this thing into a low-power always-on server. Such a role would be perfect. I could see it doing a fine job hosting files, streaming video to my TV, and finishing downloads overnight. It would be a quieter, lower-power PC for doing simple things like writing this blog. My PC is fairly hefty and has a nearly 1000 watt power supply, 3 hard drives and almost a half dozen fans. If I were to power it with a generator under my desk it would honestly not add much to the din this thing makes.

The other possibility is more interesting to me. Call me crazy, but I kinda want to build a tablet. This board is very self-contained (it's a complete system on a chip, after all) and all it needs to become a tablet is a touch screen and batteries. Um, an enclosure would be customary, but I might just go for the visible guts T-800 look. The PB community has tackled both of these issues for me. Battery power seems to range from anywhere as simple as plugging the PB into a spare battery pack like those sold at airport kiosks for charging phones on the go, or building a small circuit to power the board from 3 rechargeable AA-sized cells or a even nice flat LiPo pack. As long as it provides between 4.5 and 5 volts with a peak capacity of 1.5 amps, it'll work. The touchscreen is a bit scarier to me though I found a nice kit at Chalkboard Electronics that I'm thinking of buying. My inspiration for a device like this is a kit I found over at Liquidware, though I wanted a larger screen. In fact, I almost sprang for the LW kit, despite the price, because I could be fairly certain that it would work as-is. I opted not to, as I didn't like the small screen and form factor. Let's be honest, it's fairly thick and brick-like. No, what I wanted was a larger screen so that I could position the board and battery side by side. That's what I hope the 10" screen from CE would let me do, but that's for later on once I get more comfortable with the PB.

I'm going to close with a rant, because I need to say that mainstream consumer mobile devices in general leave me very disappointed. I dumped my Archos tablet a year ago, and while I love my Droid X, I wish it did more. I've even gone so far as to root my DX and install Liberty ROM, but it's just not as complete as I want. These devices we carry around with us are immensely powerful despite the trade off for power savings and sleek form factor, yet they're crippled and limited to simple tasks by the software they run. Who said that I shouldn't be able to plug a USB thumb drive or keyboard into my tablet? It's clearly not a technical limitation, but our devices are "dumb" by design. Very few devices have USB host capabilities. Most devices are locked by the manufacturer so that the end user can't install the software of his choosing. The final nail in my Archos' coffin was that it was stuck on Android 1.6 at the time phones were shipping with Android 2.2. Thanks to it's locked bootloader, I was stuck with what it shipped with since Archos never sent an update. Shame on you, Archos. Shame on you not just for limiting my choice, but shame on you for selling me a device that was locked into running outdated, buggy software.

That said, my Pandaboard should arrive this Friday, and it should be able to run anything from Android, to Ubuntu, Meego, hell even the oft-maligned Windows CE!