Mobile Internet Bandwidth Usage

As U.S. broadband providers move towards metering everyone’s internet usage it pays to have a basic understanding of how your surfing habits add up. Using a borrowed Verizon VZAccess card for my laptop last week, I noticed every time I logged onto the service it gave an update on how much data I had consumed in the previous session.  I was quite surprised at the amount I used per session. And going over your plan can be painful. Verizon, for example, has one plan that charges $20 for each additional Gigabyte (GB) once you go over your 1st GB.

So, I decided to put firebug to work and take a few measurements of my own.  Full, non-mobile, web pages can add up in size really quick. Check out the sizes of these pages:

  1. Computerworld – 541K
  2. MSNBC – 1MB
  3. MSDN Home page – 423K
  4. Youtube video – 20.9 MBs (~6 mins)

So how about some tools to help out? Verizon provides a nice online planning tool to help you gauge how much data you might use: https://www.verizonwireless.com/splash_includes/datacalculator.html . Give it a shot, I think you’ll be surprised at just how fast the data (and charges) could add up.

As far as running a usage monitor on your droid (or iPhone), I don’t really have any recommendations yet, since I just started digging into this. I’ve tried Network Monitor, but it didn’t work on my Motorola Atria. I’m currently trying the free version of PhoneUsage. So, if you have some suggestions post a comment. If I can compile enough useful and interesting information I’ll write an updated blog post.

A better way to measure CPU % using Windows, PerformanceCounter and C#

I’ve seen dozens of reproductions of the same code on the internet showing how to measure CPU utilization on a Windows machine using the PerformanceCounter.nextValue() method. The vast majority of these implementations consistently alternated values of either “0” or “100” on some machines and worked just fine on others, which is essentially worthless. And, since my apps tend to be deployed on many different types of machines, I needed something that worked all the time. 

So, for a recent project I decided I was going to dig deep into Microsoft’s online documentation and solve this riddle once and for all. Sure enough I found what I was looking for in an article that mentioned using the System.Diagnostics. CounterSample Structure as a way to compare two PerformanceCounter values. That seemed like a perfect way to gaurantee better measurements.

So, here’s how I implemented it:

           
     PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
     CounterSample cs1 = cpuCounter.NextSample();
     System.Threading.Thread.Sleep(100);
     CounterSample cs2 = cpuCounter.NextSample();
     float finalCpuCounter = CounterSample.Calculate(cs1, cs2);

So why and how does this work? System.Diagnostics.CounterSample lets you compare two PerformanceCounter samples to come up with a float value. Rather than taking a snapshot value, which is what the nextValue() method does, you can compare values over a period of time.  Here’s the official description from MSDN of the Calculate() method: “Calculates the performance data of the counter, using two sample points. This method is generally used for calculated performance counter types, such as averages.” 

Feel free to experiment with adjusting the Thread.Sleep timeframe. It may need to be set slightly more or slightly less depending on the speed of the machine in which it runs, and the CPU activity on the machine. For example, if your machine activity is very sporadic and frantic, then you might want a shorter interval. Or, if you have long running processes that eat a fairly consistent amount of CPU you could probably lengthen the sleep time. I tested this pattern on a total of three different machines including two Windows 7 boxes and an 8-core, Windows Server 2008 box, and it worked very well. 

Now, for those of you purists who hate seeing Thread.Sleep in any code there’s no need to yell at me. This is a sample for you to use as you see fit. 

References: 

PerformanceCounter Class (MSDN online doc)

Performance Counter Value Retrieval (article)

CounterSample Structure (MSDN online doc)

Running .ashx files on IIS 7, Windows 7 and .NET 4

If you simply copy your Visual Studio 2010 generic handler (.ashx) project’s directory into a virtual directory on IIS it will fail with an error similar to the following:

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not create type ‘HealthCheck.health’.

There are lots of suggestions on the internet, but the most fundamental fix is hard to find. I know because I’ve run into this problem before and it took me quite a while to figure it out. This time I only wasted a half-an-hour before a little voice in my head reminded me that generic handlers created in Visual Studio 2010 require that they be run as an application in IIS.

So here’s how you do set up IIS to run the .ashx file as an application:

  1. Open  Internet Information Services (IIS) Manager
  2. Double-click on “Application Pools”. If your Default App Pool is not set to v4.0 then double click on it and change the version. If you don’t have v4.0 installed, then you’ll you need to do so. NOTE: if you change this be sure to test your other/older applications to make sure they don’t break. If they do break other apps, then right click below the Application Pool table and create a new, custom app pool using .NET v4.0.
  3. Right click “Default Web Site”
  4. Select “Add Application”
  5. Fill in all the Alias and Physical Path fields. BE SURE to select the correct application pool referenced in step 2!!

Extras

  1. Here’ s a great blog post on how find your .NET version that’s being used: https://www.walkernews.net/2008/05/16/how-to-check-net-framework-version-installed/ .
  2. You can also look at the bottom of the Parser Error Message and you’ll see the .NET version there, as well.