26 Oct 2010

Timing The Execution Time Of Your MVC Actions

8 Comments Uncategorized

I recently had the need to find out how much time elapsed during the execution of just my action, so I created a handy little action filter based on System.Diagnostics.Stopwatch.  This action filter adds the elapsed time to an HTTP header, appropriately named, X-Stopwatch

I choose to use a header instead of a response in the content body, so that it could be used both with non-HTML responses (binary, JSON, XML, etc) and HTML response.  I was amazed at the usefulness of this simple piece of code, because it instantly gave me insight in to the actual execution time of my action to see if my optimizations were having any effect.  It allowed me to monitor the execution time of code that I can specifically and easily control the performance of.

Here is the filter if you want to add it to your own projects.

public class StopwatchAttribute : ActionFilterAttribute
{
    private Stopwatch _stopwatch;

    public StopwatchAttribute()
    {
        _stopwatch = new Stopwatch();
    }

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        _stopwatch.Start();
    }

    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        _stopwatch.Stop();

        var httpContext = filterContext.HttpContext;
        var response = httpContext.Response;

        response.AddHeader("X-Stopwatch", _stopwatch.Elapsed.ToString());
    }
}

You can view the full C# File here on my GitHub repository.  This could obviously be modified to suit your own needs.

01 Oct 2007

Anything For Sale By Owner

1 Comment Uncategorized

Anything For Sale By Owner LogoAs I alluded in a post a couple of weeks ago, I have been a bad blogger. And I have neglected my community of readers. However I would like to tell you what I have been doing in the last couple of months while I have been neglecting my blog.

I recently got involved in creating a startup as the lead developer for an online classifieds site called Anything For Sale By Owner. From the ground up this was conceived as a middle-ground between craigslist and ebay where every listing would be charged at a static rate of $1.00/month. The $1.00 is a way to week out the crap from craigslist and the death-by-fees from ebay.

The description is pretty straight forward but the more interesting tid-bits that I know my readers are interested in are as follows:

.NET/C#

We choose .NET mostly because it is what I knew and .NET for me has always been stable, predictable, and performed really well on server-side applications. The alternative was PHP and even through we wrote many of the processing layers by our self (i.e. REST Web Service Handler) the time to deployment was greatly accelerated because of all the work the Microsoft ASP.NET Team has put in to the product. The user of Master Pages and Web Services made for an easy separation between content and display.

MySQL

We choose MySQL for a whole host of reasons mostly based around the costs associated with a single Microsoft SQL Server Standard Edition license. Other reasons we choose MySQL was for scalability, because not only could we install 5 database servers (hardware included) for the same price we could purchase 1 MSSQL database server for but also because the master/slave replication of the databases seemed to be an easier process when we needed to scale horizontally.

REST Web Services/AJAX

We followed the Digg Model for exposing web services and each web service could be changed around to provide output through JSON, RSS, ATOM, KML (where applicable), and XML. I even did a write up about a month ago on the JSON Serializer that I developed for this website. This was very important for the AJAX we needed to control many aspects of the user experience.

Open Search

Open search was one of the value add features that wasn’t in the original spec but was an easy add-on because we already had the Web Services in place to leverage. You can view our open search XML definition file here. If you are unfamiliar with Open Search this is how A9.com defines it:

OpenSearch is a set of simple formats for the sharing of search results. Any website that has a search feature can make their results available in OpenSearch format. Other tools can then read those search results.

So that little search box in the upper right hand corner of your browser is an example of an Open Search client.

SEO

Search Engine Optimization is a very important part of any website today. Because for most new sites and even some of the older ones, Google is going to be the largest most ignored user of the site. Not only will Google look at every single page on your site every week, which I dare any human to try and accomplish, they will also be the largest organic promoter of your site.

One of the corner stones of SEO is easily readable URL’s that contain descriptive keywords. This means you have to have a good URL Rewriter in place. We choose Ionic’s ISAPI Rewriter that integrated nicely with IIS 6.0. However that left a big gap between using Visual Studio’s Intigrated Web Server (which doesn’t support ISAPI) and a full blown IIS Server. The benifits are pretty obvious for running the Intigrated Web Server that comes with Visual Studio, for one you don’t always have to have IIS that comes with Windows XP always running and the host of security problems that comes with it, two I was running Windows Vista and IIS 7.0 has some huge differences from IIS 6.0.

So I sat down one night and wrote my own Apache mod_rewrite compatible HttpModule for running the same rule-set that I defined for Ionic’s ISAPI Rewriter, to fill in the gap and make developing on my local machine as close as running the live web site on IIS 6.0.

If anybody is interested I offer the Url Rrewriter as a free download:

Front End Design

I am a software developer and usually don’t get invovled in the artsy end of the web site design. So I will let my co-worker Tom Lauck describe how he developed the front-end for Anything For Sale By Owner.

So all in all I believe that this website has a very good chance of making in the Wild Wild West that the Internet is, however that is probably just the ramblings of a proud father. Be on the look out for some major marketing campaigns in the NYC Times Square region.

30 Jul 2007

Vista Performance and Reliability Pack Unofficial Release

No Comments Uncategorized

Please note: These fixes break all current methods of bypassing driver singing requirements except the good old F8 during boot (that you have to do every single time you start vista)

If you are using Rivatuner, atitool and or Peerguardian on 64bit vista, you will have to use F8 every single time to disable driver signing requirements to use those two programs. x86 version is unaffected.

These updates should go official on the next patch Tuesday (in one weeks time). Please read more for the download links and information on these updates.

938979 Vista Performance and Reliability Pack

This update resolves a number of individual issues which may be affecting some computers running Windows Vista. These issues have been reported by customers using the Error Reporting service, product support, or other means. Installing this update will improve the performance and responsiveness for some scenarios and improves reliability of Windows Vista in a variety of scenarios. Some examples of the improvements contained in this update are:

  • Improves performance in resuming back to the desktop from the Photo and Windows Energy screensaver.
  • Resolves an issue where some secured web pages using advanced security technologies may not get displayed in Internet Explorer on Windows Vista.
  • Resolves an issue where a shared printer may not get installed if the printer is connected to a Windows XP or Windows Server 2003 system and User Access Control is disabled on the Vista client.
  • Resolves an issue where creating AVI files on Vista may get corrupted.
  • Improves the performance in calculating the ‘estimated time remaining’ when copying/moving large files.
  • Improves performance in bringing up Login Screen after resuming from Hibernate.
  • Resolves an issue where synchronization of offline files to a server can get corrupted.
  • Resolves a compatibility issue with RAW images created by Canon EOS 1D/1DS Digital SLR Camera which can lead to data loss. This only affects RAW images created by these two specific camera models.
  • Resolves an issue where a computer can lose its default Gateway address when resuming from sleep mode.
  • Improves the performance when copying or moving entire directories containing large amounts of data or files.
  • Improves the performance of Vista’s Memory Manager in specific customer scenarios and prevents some issues which may lead to memory corruption.

938194 Vista Compatibility and Reliability Pack

This update resolves a number of individual issues which may be affecting some computers running Windows Vista. These issues have been reported by customers using the Error Reporting service, product support, or other means. Installing this update will improve the reliability and hardware compatibility of Windows Vista in a variety of scenarios. Some examples of the improvements contained in this update are:

  • Improved reliability and compatibility of Vista when used with newer graphics cards in several specific scenarios and configurations.
  • Improved reliability when working with external displays on a laptop.
  • Increased compatibility with many video drivers.
  • Improved visual appearance of games with high intensity graphics.
  • Improved quality of playback for HD-DVD and Blue-Ray disks on large monitors.
  • Improved reliability for Internet Explorer when some third party toolbars are installed on Vista.
  • Improved Vista reliability in networking configuration scenarios.
  • Improved the reliability of Windows Calendar in Vista.
  • Improved reliability of systems that were upgraded from XP to Vista.
  • Increased compatibility with many printer drivers.
  • Increased reliability and performance of Vista when entering sleep and resuming from sleep.

Download: Vista Compatibility and Reliability Pack for x64 or x86 version
Source: Neowin.net