Wednesday, May 8, 2013

ASP.NET Sessions

Did you know that if you don't put anything into an ASP.NET session, it will generate a new one with EVERY page request!!???

Try it out for yourself...

  • Create a new MVC(3/4) Web App in Visual Studio. 
  • Choose the Razor rendering engine
  • Add the following code to index.cshtml
@if ( Session.IsNewSession )
{
    <p>We have a NEW session! ID [@Session.SessionID]</p>
}
else
{
    <p>We have an EXISTING session! ID [@Session.SessionID]</p>
    <p>Today is: @Session["DAY_NAME"]</p>
}

Run the website and you will see that the Session ID is different every time you click back to, or refresh the index page!


At first I though this was because I wasn't logged in. If I go to the Register.cshtml page and create a new account, and login with it, this behaviour still persists.

It's only when you add something to the session that you see the same Session ID being reused.

Go to the About.cshtml page and add the following code:
    if(Request.IsAuthenticated)
  {
      Session["DAY_NAME"] = "Wednesday!";
  }

Run the app again, and make a note of the Session ID on the index.cshtml page. Next click the About menu tab, and then go back to the Home tab. You will see that your Session has been persisted because you added today's name into the collection.


Why does it work this way? I'm not really sure. If you have any ideas, I'd be happy to hear them.

Wednesday, May 1, 2013

Mac OS X, Bootcamp, Virtual Machines and SSD Performance

I have a 17" Macbook Pro configured with a bootcamp partition. I usually do my daily development work on this when I have to go on site at a client. I work with Visual Studio 2010 building web apps and desktop tools.

As soon as I bought the laptop I replaced the stock 750GB 5400rpm drive with a 480GB OWC SATA3 SSD. I also added a data doubler kit from MacSales and replaced the DVD drive with a 250GB Corsair SATA2 SSD.

After some hair pulling and firmware upgrades to the Macbook Pro I was able to get some great benchmark speeds on the OWC SSD under Mac OS X, but under Windows the speeds were only averaging SATA 2 speeds.

These are the Mac OS X benchmarks:

17" MacBook Pro - Running Lion OS



OWC Mercury Electra 6G 480GB - Mac OS X

The performance was as expected - Max Read Avg. 520MB/s and Max Write Avg. 469MB/s. These results are what you'd expect from a SATA 3 SSD.

Next I booted into bootcamp, running Windows 7 - 64 bit (Bootcamp v3.3) , and expected to see some similar results. But this was not to be. This is what I found instead:






OWC Mercury Electra 6G 480GB - Windows 7 Pro (Bootcamp v3.3 64 bit)

As you can see, the throughput seems to be capped around the 240MB/s - 250MB/s - for both Reads and Writes. Quickbench and ATTO Disk Benchmark show this very consistently, however there is a bit more variance with Crystal Disk Mark and AS SSD Benchmark. I put these differences down to variations in the tools and possibly other disk activity. But you get the picture. Something isn't right. 

After a lot of hunting around the various Apple and OWC/Macsales forums and blogs etc... I couldn't find anyone who had noticed this difference in performance. Eventually after opening an email dialog with the OWC staff, they determined that the bottleneck is the Apple Bootcamp drivers. I was running 64bit windows with bootcamp v3.3, so I'm not sure if it was a 64bit issue and switching to 32 bit Windows would have produced a different result. I had 16GB RAM so didn't want to forego the memory benefits of running a 32bit OS. 

**Edit** I see now that Apple have release Bootcamp v5.0 which is 64bit only for Windows 7 & 8. These SATA driver issues might well be fixed now. I haven't tested these combinations though.

So what to do now? I've got an awesome laptop with a super fast hard drive and I want to get the most out of it... in both Mac OS X as well as Windows. 

The answer is Virtual Machines!! My hypothesis was that if the Mac OS X drivers were heaps faster than the bootcamp drivers, I could probably run Windows in a virtual machine, under either Parallels Desktop or VMware Fusion with a better result - despite a virtualised hard drive - than natively on the bootcamp partition. Would I be proven right!!?? Lets see!

For the purpose of these tests I used the Windows Experience Index (WEI) as the best way to compare all the different permutations of VM & bootcamp etc... 

I used Parallels Desktop version 7.0 and VMware Fusion version 5.03. In all cases each virtual machine was given 4 processors and 8GB of RAM.

First of all, lets start with Windows 7 (64 bit) running under Bootcamp v3.3


This is effectively our baseline benchmark. A 6.9 overall, with a 7.0 on the primary hard disk. Note that memory and CPU are pretty good too. 

Next step is to see what scores I can get by running a VM, that is attached to the bootcamp partition - effectively running a native disk. 

Parallels with Native Bootcamp Partition - Win 7 x64

This is Parallels running the native bootcamp partition. Disk speed has already jumped to a 7.6 despite a drop to 5.9 for an overall score. Not bad. Lets see what Fusion can do:

VMware Fusion with Native Bootcamp Partition - Win 7 x64
Fusion gives us a slightly better score overall, but the hard disk rating has dropped to 7.1. Bummer! Look at those CPU and memory scores though. They are doing better than our baseline, booting natively into the bootcamp partition!!

Next I created 2 new virtual machines, one each in Parallels and Fusion, but this time running Windows 8 (64bit). 

Parallels with Windows 8 x64 in VM - Virtual Disk
Wow! Look at that... an 8.4 disk score! CPU and memory are still about the same, but the overall score of 5.9 has dropped as a result of the poor graphics performance.

Fusion with Windows 8 x64 in VM - Virtual Disk
VMware Fusion was just pipped at the post on this one. Disk score of 8.3 is nearly the same, but the graphics lets it down again. However we got a bump on the memory score! 


So what does all this mean?? What did I choose to go with? 

Well, despite the slightly slower score, I chose VMware Fusion. Why did I do this? I have been a long time user of VMware Workstation and I absolutely love it and couldn't live without it for my day to day development activities. The two products are compatible with each other so if I need to migrate existing virtual machines I have across to Fusion, I can do that easily. I know that Parallels has some nice import features too, and I've used them successfully too. 

But in the end it was close enough that I don't think it would really matter. I know this is a long post, but hopefully it's been helpful for you if you've been wondering about whether it's worthwhile running Windows VM's under Max OS X instead of going the bootcamp route. In my opinion, it is absolutely not only a viable option, but a performant one too. I have now deleted my bootcamp partition, migrated it across to a Fusion VM for archive purposes, and I am in the process of building up Fusion VM with Windows 8 x64, Visual Studio 2012 and SQL Server 2012 to do all my .Net development. So far it's working great. 

Thursday, February 7, 2013

My Ultimate Developer Rig - Part 2

UPDATE: Apologies for taking so long to finish this post!

Click here to read Part 1 first.

So how does it run?? Smokin' is all I've got to say! This is an awesome beast of a machine. I'm sure with some more money, time and attention to overclocking detail I could get even more out of her, but I'm happy with what I've achieved.

Windows Experience Index (WEI)
This is what you're really wanting to see isn't it? Well here it is:



I'm not surprised by the 7.8 on the graphics card as it's nowhere near a top line card, but I was by the Processor score. Maybe you need something even more to pull a 7.9 there. But the Primary Hard Disk score of 7.9 was exactly what I was after.

So lets break it all down a little....

CPU Overclocking
Here is a look at the system under a full load with the CPU overclocked to a speedy 4.72Ghz.



Not a bad increase up from the stock 3.40Ghz. Remember that while I'm using the Corsair Water cooling unit, it is still using fan based cooling, not refrigeration based chilled water. I tried pushing to 4.80Ghz but the system wasn't stable. It would POST and boot into Windows, but usually after about 5mins it would crash and blue screen. I ran Core Damage overnight as shown with Normal Priority threads @ 4.72Ghz and the system was rock solid. Core temps were around the 70C mark.

So I know that I have a solid stable system that is nice and fast, and doesn't get too hot. It's interesting to see that even though I bought so called "Value" labelled RAM kits, they performed brilliantly, and didn't impact the WEI score at all.

SSD Performance
I ran some tests using a number of different tools in order to get the most accurate view of what is really going on with the RAID 0 setup. The following tools made up the list:

  • AS SSD Benchmark v1.6.4067
  • ATTO Disk Benchmark
  • CrystalDiskMark v3.0.1
  • HD Tune Pro v4.61
Breaking the 1,000MB/s barrier was my goal - I had thought this was possible in theory if I used RAID 0; but now I've proved my hypothesis. Niiiice! :o)









I've been running the system now for well over a year and a half and it's never let me down. I've subsequently moved to SSD's on all my other systems and it is just heaven. 

One last thing...
With that in mind though, just remember that all hard drives DO fail at some point. And SSD's are no different... except when they fail, they die stone cold dead! There is no tell tale clicking sign or funny data reads etc... You just go to use it one day and it's dead. So make sure you have a good, reliable daily backup (and [offsite] backups of your backups!). Even more importantly, make sure you have tested your backups and can recover them successfully.

How Cool are Google's Real-Time Analytics!!


Click to view full image.

Wednesday, December 19, 2012

Customer Service Fail

The company I work for hosts some of our domains with BlueCentral here in Australia. For some reason our accounts department missed the payment of our domain hosting, so they naturally cut us off - as you would expect. We picked up the error the day after the invoice due date and called them to pay the bill and get things working again.

This is where they fail big time... There is only 1 number you can call for support to talk to someone about an existing service. But when I tell them we've missed the invoice payment date and our website is offline and can I pay it right now over the phone, they say, "Oh, no, we'll pass your inquiry on to the accounts team, and someone will get back to when they get a chance!".

"But I want to give you money... right now.... over the phone", I say to the cheerful call centre lady. Is there no way you can transfer me through to the accounts guys or something? Nope, not possible. So how long will I have to wait does she think? Maybe an hour if they're not too busy, but possibly longer! Sigh!

How long did it end up taking? Nearly 24hrs until we were back online again. In fairness to BlueCentral, I did get a helpful call from their technical support staff, after I logged an urgent ticket, and the guy was very helpful. When I explained the situation, he said yeah, that's the way it is... if you need quick action, the best way is to log a ticket and they'll get onto it asap!

Seth Godin frequently talks about this on his blog... don't make it difficult for people to give you money! I think we might be looking for a new hosting provider in the not too distant future - someone who provides great service to their paying customers!

Friday, July 8, 2011

My Ultimate Developer Rig - Part 1

The time has come for me to replace my old desktop PC with a new whiz bang developer rig. The old system has the following specs:

Intel Core 2 Duo 2.13Ghz
4GB RAM
120GB SATA 2 OCZ SSD
300GB SATA 2 Western Digital Velociraptor 10,000RPM
750GB Seagate 7200RPM
Windows 7 Ultimate x86 (32bit)

It ran well for the most part. The SSD was a great interim measure to give me some extra speed until I could afford the big upgrade with a completely new machine. At the time I built this original machine I was more concerned with how quiet the machine was, so I had a low end fanless graphics card along with a tonne of sound absorbing audio foam in the case. It was nice and quiet but I couldn't play any decent sized videos.When I tried to use Visual Studio 2010 with Resharper 5 (great tool!!!) on my new project I was working on, I found myself waiting up to 10secs for intellisense to pop up. This became soooo frustrating, so it was time to upgrade.

I was spurred on by both Scott Hanselman and Jeff Atwoods articles on building the ultimate developer rig as well as going for a 7.9 WEI rating (Windows Experience Index):

http://www.hanselman.com/blog/TheCodingHorrorUltimateDeveloperRigThrowdownPart1.aspx

http://www.codinghorror.com/blog/2007/07/building-a-pc-part-iv-now-its-your-turn.html

http://www.hanselman.com/blog/UltimateDeveloperPC20Part1BuildingAWEI79AndRFCForBuildingAGOMGodsOwnMachine.aspx


I deliberately waited until the prices of various items I wanted had come down bit so that I could keep the budget under AUD$3,000. Ideally the core machine would be under AUD$2,000 and then I had plans to add a 4 disk RAID5 Array. I wanted speed, speed and more speed.

The first and highest priority component was the main hard drive. Sata 3 has recently come out so I definitely wanted a good quality motherboard that supported RAID 0 (striping) on the Sata 3 controller, and I wanted to have the fastest SSD's that I could get my hands on.

Enter the new OCZ Vertex 3 SSD.



OCZ VERTEX 3 120GB SSD SATA3 550/500 R/W/MB

These puppies are simply awesome. They are fast, silent, and have a new controller (you can google for tech details if you want). I bought 2 so I could set them up in RAID 0 for twice the throughput (does this really work? Checkout Part 2 for disk benchmarking results).

Next is a fast CPU. I went for the new Intel Core i7 2600K - note the 'K' means the clock multiplier is unlocked for easier, better and awesome overclocking.



INTEL CORE i7 2600K 3.4GHz 8MB

I also went for a new video card that would have a number of options for output connections, plus good clock speed and RAM for good framerates when watching HD video. I found this little baby:

XFX HD6870 900M PCIe/1GB/DVI/HDMI/DP

This is a great graphics card because it can support up to 5 monitors!!!! It has 2 x DVI, 2 x Display Port, and 1 x HDMI. Great Stuff!

Because I want to use this as my developer machine, I will be running virtual machines etc.. and doing all sorts of audio/video encoding, watching full HD video, all at the same time I went for 16GB RAM (4 x 4GB), so I have plenty to play with. With disk I/O being the biggest bottleneck on the system, I just went for budget priced RAM:

GEIL 16GB KIT DDR3 VALUE PLUS C9 1600M


I want to overclock the CPU to get maximum speed out of it, so I wanted a decent motherboard with a good price point. It had to have Sata 3, RAID0,1,5, good RAM speed and capacity, and for the future USB 3.0:

ASUS P8P67 LE B3 DESKTOP MOTHERBOARD
This motherboard ticks all these boxes, plus it has the new Sandy Bridge Chipset so I know I'm going to get the most out of the Core i7 CPU I'm going to put in it.

If I'm going to be overclocking it I want a rock solid PSU so I went with Corsair:


CORSAIR 750W HX-750W


Lastly, I want to keep everything nice and cool, especially with the extra heat that this CPU is going to be generating when overclocked. In the past I've gone for large heat sinks and CPU fan setup, and extra case fans and the like, but I wanted something nice and minimalist this time. So the only choice was a Corsair Watercooling Kit:


CORSAIR COOLING HYDRO H70 CPU COOLER

This is so easy to install, and works perfectly. One word of advice though, make sure you attached the mounting backing plate on the motherboard before you screw the motherboard into your case!! :o)

Now lastly we need to put all these bits in a case. I just wanted a decent full size ATX case at a good price. It had to have good airflow and easy to use quick release HDD bays. Enter this one:



LIAN-LI LANCOOL PC-K58 CASE BLACK


So, what was the damage for all these goodies? Here's a summary of all the parts and their prices and quantities:


Quantity
Price
LIAN-LI LANCOOL PC-K58 CASE BLACK
1
$95.00
CORSAIR COOLING HYDRO H70 CPU COOLER
1
$159.00
INTEL CORE i7 2600K 3.4GHz 8MB
1
$339.00
XFX HD6870 900M PCIe/1GB/DVI/HDMI/DP
1
$197.00
GEIL 16GB (4 x 4GB) KIT DDR3 VALUE PLUS C9 1600M
1
$209.00
ASUS P8P67 B3 DESKTOP MOTHERBOARD
1
$169.00
ASUS DVD RW 24x BK/ +/-/DL/SATA
1
$35.00
CORSAIR 750W HX-750W MODULAR POWER SUPPLY
1
$209.00
OCZ VERTEX 3 120GB SSD SATA3 550/500 R/W/MB (Unit price $329)
2
$658.00

$2070.00



So I've come in ever so slightly over budget - well what I was aiming for ideally - so I'm very happy. In the next installment, I'll post some benchmarking results for the RAID 0 SSD configuration as well as my overclocking results and WEI Score.

Saturday, July 2, 2011

Image Mosaic Generator

A friend of mine told me about this site http://click7.org/image-mosaic-generator/?create.

I uploaded this photo:


and this is what it generated. (Click to view large version):


So clever and great fun!!

Wednesday, June 29, 2011

How do I open my SQL CE 4.0 Database in SQL Server 2008 Management Studio?

Simple answer... you can't! :o)

You can open up to SQL CE 3.5 SP1 in 2008 Management Studio, but CE 4.0 is not supported. Have a quick read of this stackoverflow.com article for more info.

Can you open SQL CE 4.0 files in Visual Studio 2010? Yes you can.

But the problem I've come across is that when I want to work in code and write say a POCO class (Plain Old C# Class) I can't. While the SQL Table property sheet is open so I can see the column data types - it's Modal, so I can't easily jump back and forth updating my code while reading the types. Not a major problem really, just an annoyance.

The solution?

SQL Server Compact Toolbox Stand Alone. You can download it here on codeplex.com. It is a great little tool that you can run - no installation - and connect to your SQL CE 4.0 file. So now I can have the toolbox open on one monitor and happily code away in VS 2010 in the other.

Life is good again.

ps: For all the information you could need on SQL CE, check out ErikEJ's excellent blog, ironically named Everything SQL Server Compact.

Thursday, June 16, 2011

Entity Spaces 2011, SQL Server Compact Edition 4.0 and WebMatrix

Okay... I want to do some SQL queries that are wrapped in transactions and not just simple CRUD statements. So I pulled out my trusty DAL code generation library (EntitySpaces) and began integrating it into my WebMatrix project.

After installing EntitySpaces 2011 I referenced all the DLL's that I needed in my project (I'm using a separate "Core" project in Visual Studio 2010 that is linked to my WebMatrix project), including the EntitySpaces.SqlServerCe4Provider:



WebMatrix uses SQL Server Compact Edition v4.0, and due to the way the EntitySpaces references the different CE versions, you need to supply this in the connection string for code generation:



Code generation went fine and I have my Generated and Custom classes all set to go. Next I needed to reference the EntitySpaces libraries in my Web.config file. Be sure to reference the correct provider for the Compact Edition:



Note, that we specify  "Data Source=|DataDirectory|yot.sdf;" where the Data Directory is going to default to the App_Data folder under your website root directory. This is handy too if you deploy the compact database to your intranet or production site. Because it's all relative to your App_Data folder, it will still work without having to remember to change the path etc...

Lastly, we need to configure the EntitySpaces library on startup. This is done by adding the necessary code to the _AppStart.cshtml file:


Now, all that's left to do is to load up a collection and populate a web grid to display it:


The rendered WebGrid looks something like this:



I am now ready to start putting together some more complex multi-step commits using EntitySpaces.



Tuesday, April 26, 2011

WebMatrix doesn't Publish All my Files

I'm trying to publish my project to a local website running under IIS 7 on my dev machine and I noticed that some of my .cshtml files were not being published. How does that happen??

It turns out that WebMatrix caches the list of files and whether or not they've been changed since the last publish action. But if for example you've gone and manually deleted some files from your test website (as I'd done), and then tried to publish them again - when there had been no changes to them - it will think they aren't changed, so therefore don't need to be sync'd again.

This is the default behaviour of WebMatrix thanks to a nice little checkbox that is tucked away in the options settings. Go to the Application menu and click on the Options menu item. The Application menu is the menu to the left of the Home tab:


When the Options dialog appears, click Publish on the left hand side and you will see that the first checkbox is ticked by default:



Uncheck the first option and all of your project files will be sync'd each time you go to publish your site. You will still be able to manually de-select any files you want when the Publish dialog is opened.

Lastly, if you are using a a version control system (you are aren't you?? :o) ) such as Subversion (SVN) you don't want all the SVN admin folders and files published to your production website. So it's a good idea to also check the last checkbox on the same screen so that they can be filtered out:



You may need to close and restart WebMatrix for these changes to take effect. The first time I tried it, it didn't seem to work properly, so I shutdown WebMatrix, restarted and tried again, this time successfully.

You can also clear WebMatrix' cached list of published files. See here for details.