Scott Hanselman

Performance Counters in ASP.NET

February 18, '04 Comments [2] Posted in ASP.NET
Sponsored By

Did some great performance testing this last Sunday on the bank we're taking live soon.  We needed to get a few thousand users on the box, all banking at the same time.  The Host Interface side has some great performance counters that made it very easy to measure.  Even though they have a rich serious of counters, I added some counters to the UI side. 

As I've mentioned before, we describe our Domain Objects and Messages with XSD, and generate loads of C# code with CodeSmith (and some with XSLT).  Using these 'nouns' we create services (verbs) that act on them as they move through the system.  We build 1st class interfaces on top of a 3rd class router that basically does an Invoke/Execute/DoIt/IDispatch...a lot the way Invoke() works with ASMX WebServices. 

There's a whole vocabulary of messages that can be sent to Voyager, like 'GetAccounts' or 'AddPayment.'  Some come with Voyager and some are added for the implementation. 

Typically with Performance Counters there are either static counters, like 'Avg Bytes/sec' through the system, or instance counters like 'Bytes/sec on this hard drive.'  Often these instance counters are per process, or per piece-of-hardware. 

But since the verbs that head through the system can be dynamic, why not make new per counters as we see new verbs? (there's usually no more than 100, really usually <50)  So, on both the UI and HI we can look at instance Performance Counters like 'Time in (ms) for GetAccounts' or 'Bytes Out for AddPayee.' 

By adding the same counters but for an 'instance' that is really a verb, we can find out when a certain operation (verb) is not performing well on the system. 

And, since we can look at what the UI's round-trip time is (for example, 500ms) and what the HI's times are (200ms to the host, 150ms in the code) we can start measuring interstitial times like marshalling time, logging overhead, etc. at a very granular level.

Fortunately we baked in hooks to allow Performance Counters early on in the project.  You should to!  It's nice to REALLY know what's happening in your app.  The less of a black box your own app feels like, the more confident you can be when you make Service Level Agreements and predictions as to performance.  Nothing is more scary than NOT knowing how to measure your own application.

Tips and Best Practices:

  • Remember the ASPNET process has access to WRITE to Performance Counters, but not READ, CREATE, or DELETE counters.
  • Add an Installer class to your ASP.NET application that does the creating of the PerformanceCategory, the creation of the PerformanceCounters and the deletion at uninstall.  You can run 'installutil [/u] yourclass.dll' from the command-line.  You can also add your installer dll to the Custom Actions section of your Web Setup and the Performance Counters will get created/deleted automatically when your MSI runs.
  • Use some High Performance Timer for your timing - don't use DateTime.anything.

It was a good weekend.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Choosing the best computer for you...in 1982.

February 18, '04 Comments [10] Posted in Musings
Sponsored By

Found this little gem in the archives and scanned it for y'all.  Couple of great ads inside. 

  • An IBM PC ad, the one with Charlie Chaplin - 16k bytes.  16 bit, 8088.  optional 5.25" 160k floppy.  4-color 320x200. Good times.  Only $3k.
    "The modem that plugs into your phone takes the codes your IBM Personal Computer understands and turns them into signals that can be transmitted over phone lines"
  • Some nice articles on acoustic vs. direct-connect models. The acoustic model from Novation was only $189.
  • This was back before computing was limited to a few companies. Some highlighted models:
    • $g(Apple II)
    • $g(Atari 800)
    • $g(Commodore 64)
    • $g(Franklin ACE 1000)
    • $g(IBM PC)
    • $g(TRS 80 Model III)
    • $g(Apple III)
    • $g(Casio FX9000P)
    • $g(Corvus Concept)
    • $g(Cromemco C10)
    • $g(DEC Rainbow 100)
    • $g(Fortune 32 16)
    • $g(Heathkit H90 Zenith Z89)
    • $g(MTU130)
    • $g(NEC APC)
    • $g(North Star Advantage)
    • $g(Olivetti M20)
    • $g(TFI if800)
    • $g(Victor 9000)
    • $g(Wang PC)
    • $g(Xerox 820II)
    • $g(Dynalogic Hyperion)
    • $g(Epson HX20)
    • $g(Grid Compass)
    • $g(Kaypro II)
    • $g(Lexicon LEX31)
    • $g(Osbourne I)
    • $g(Otrona Attache)
    • $g(Panasonic RLH1000)
    • $g(Sharp PC1500)
    • $g(Atari 400)
    • $g(Commodore VIC 20)
    • $g(TI99 4A)
    • $g(Timex Sinclar 1000)
    • $g(TRS80 Color Computer)

Do you have any fond memories of these beauties?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Test Coverage IS important...

February 18, '04 Comments [4] Posted in Programming | Tools
Sponsored By

This fellow said:

"I would much rather aim for 100% test-driven development than aim for 100% test coverage."

But I fear he's missing the point.  If I'm only testing 1% of my code paths, 100% of the time, what am I accomplishing? Squat. 

As my boss has said, adding a non-intrusive code coverage tool to an already successful unit-testing strategy can absolutely find gaps in coverage that staring at the screen just won't find. 

But juxtaposing 100% TDD with a 100% coverage goal doesn't make sense.  They are complimentary, parallel even, but not opposing goals.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Googling by Filetype!

February 14, '04 Comments [0] Posted in XML
Sponsored By

Well this will just change my life...I can Google by FileType...Here's a search for all PowerPoints with the word Zen in them:

http://www.google.com/search?hl=en&lr=&ie=ISO-8859-1&safe=off&q=%22Zen%22+filetype%3Appt&btnG=Google+Search

Just by putting "Zen" filetype:ppt in the Google search box. Yum.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Sheesh, ScottGu, just buy this company already...

February 14, '04 Comments [3] Posted in ASP.NET | Javascript | Internationalization | Bugs | Tools
Sponsored By

I briefly mentioned this 3rd party tool once before, but as I'm using it daily and for the last 4 months, I wanted to post more on it.  (Note: I'm just doing this 'cause I dig it.  I'm not meaning to sound like a shill, but you know me, if it's cool, I tell you.  If it sucks, I say it loud.)

Every once in a while you come upon some cool controls for ASP.NET that you just have to spread the word.  Andy Smith's stuff is like that, you know, and now he works with Robert McLaws at Interscape. Just clever, simple, elegant and few moving parts.  When I find a set of controls that give me elegant and powerful functionality I typically RIP them apart to find out how they did it and how I can learn from them. 

So the fellow I want to talk about is Peter Blum, and the ASP.NET Toolkit is the Validation and More package.

Validation Sucks

We write banking sites and one of the things that is the most time consuming and irritating is the client side validation code.  Banking sites typically have VERY complex business rules that need to be represented in the browser...things like "If this index in this drop down is selected, make sure this checkbox can be checked and require this text in this text box, else show an alert box."  It's the kind of code that you COULD write in custom JavaScript, but getting it to work on every browser is a hassle.  Also, you might write a bunch of code that shows the error messages in an alert box, but then the client says, "this is great, but put it in a table at the end of the page" or "put a dot by each text box that needs to be validated" or "turn each control red when there's an error" or worse, "all of the above."

Microsoft ships 5 validation controls with ASP.NET and they are OK, and produce some pretty basic JavaScript.  Rather than working from these meager beginnings, Peter starts from scratchNow, seriously, pause and drink that in.  The VAM (Validation and More) controls are NOT "more ASP.NET Validation Controls" - they are a complete and total framework in and of themselves.  It's a whole new way of thinking about validation in ASP.NET.  He's basically written a Validation/Action engine in cross-browser Javascript. 

Each of the VAM controls (there's 22) can be manipulated in the ASP.NET Design Mode surface with property pages.  So, for example, you can drop a MultiConditionValidator on the page, add a TextRequiredValidator and a RegularExpressionValidator and associate them with one or more controls like TextBoxes, or Combos.  Then here's the magic: On the client-side an array of actions is generated.  When the form is about to be submitted client-side, VAM uses the powerful eval()-uation features of JavaScript to dynamically validate the page. 

Then, the actions are abstracted from the formatters.  Basically the fact an error occured is SEPARATE from how that error's message will express itself.  So, you might have a string "Please enter a valid Social Security Number" but that can be presented as an Alert Box, a  DHTML layer, a tiny gif with an ALT tag tooltip, a colored textbox, or a flashing graphic (or whatever you want).  Separating activities from presentation from storage... it's "3 tiered" design within a replacement validation framework.  It's so crazy it just might work. :) 

It's generated JavaScript supports IE, IE/MAC, Netscape 6+, Mozilla and Opera.  It also supports isomorphic SERVER-SIDE validation, so if your use bypasses your client-side code, you'll catch them on the server side.  Pretty sweet.

Localization (So few people care...but everyone should)

There's a LOT (most?) of ASP.NET controls out there that just assume that everyone in the world speaks English (or cares to).  I've picked up a few Calendar controls from random places that literally crashed when told to display a different culture.

We have banks live in such out of the way places as Greece, Thailand, and Malaysia.  We need our systems and ASP.NET controls to be fully "culture smart." (PLUG: Come see my Internationalizing ASP.NET Sites at VSLive!)  The VAM validation controls support using ResourceID strings for complete localization of Error Messages.  This culture awareness is throughout the framework, and it's appreciated as I work on banks en español.

JavaScript you DON'T have to write (and ought not be writing)

One cool extra is a concept called a FieldStateController.  From the site:

"The FieldStateController controls can monitor edits and clicks on any type of field on the page. They can use the same Conditions used by validators to determine if a certain condition is met before taking their action. For example, the checkbox must be checked, the textbox must contain some text, or the listbox must have a selection."

You can use any attribute supported in the DOM or in DHTML so changes in the state of one or more fields can change the attributes in an other objects on the page.  This translates to less custom JavaScript that I have to write.

Extensibility

There's a great (and incredibly long) Developer's Guide that explains how you can extend the framework.  For example, I wanted to support entering dates like this "YYYYMMDD" as well as the standard culture-specific "MM/DD/YYYY".   So, I derived from the existing PeterBlum.DateTypeConverter my own CustomScottDateTypeConverter.  It's one class that handles both server and client side validation/conversion.  I added code to handle my new "DataType" and delegated the rest to the base class.  No need to reinvent the wheel.

Freebees

There's also a bunch of freebee features that aren't neccessarily validation related, but are useful to your application. 

  • There's a "TrueBrowser" object model that lets you sniff browser capabilities more easily than the standard BrowserCaps stuff. 
  • There's a FilteredTextBox to limit keystrokes to just decimals, currency or integers.
  • LocalizedLabels - smart string lookup labels for multi-lingual sites.I know

Documentation (When it's good, OH it's good.)

His documentation is obscene.  Like, it's embarassing.  No single developer should write this much documentation.  You'd think there's a separate documentation department.  Probably he's locked his mom in the garage and got her making PDFs.  I mean that in the best way.  Except, he's put me in a bad spot...if I ever start my own company, I need to have doc at least this good...and I'm not sure I want the bar set that high.

Support

We had to call support with a CRAZY threading bug in our 1.02 version of the VAM that happened if two people with the identical browser hit the site within a few milliseconds of each other if that browser has never hit the site before and the site is under exteme load.  (This happened twice in a week, so you get the idea that it's was obscure and not a big deal.)  Anyway, I explained it to Peter and he had already found and fixed it for the next minor version! 

Conclusion

He's got two pricing levels of VAM, and Level 2 (the one that includes all the good stuff) is only $100 and even the Redist or Source Code License is reasonable.  That's insane.  Anyway, check it out.  It's SO rich and SO powerful that it may freak you out as it's overwhelming. Seriously, take a day and spend time with it.  Read the instructions, and read them again. 

The real value for me is that we are using it's extensibility points to extend it WELL beyond it's standard features and firmly into the Financial Vertical I work in.  We've extended and added to the point where it's now the Corillian Validation Framework, and that's just great for us...our job isn't to write validation code, it's to make powerful banking sites.  And that suits me just fine.  Microsoft should buy this guy and integrated the whole thing into ASP.NET 2.x.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.