#.think.in
learn.create.enjoy

Network Checks

July 22, 2008 19:12 by tarn

I work with an IT manager who is very into knowing about how all the servers on the network are performing, and rightfully so. But the process isn't great; he gets an IT person to remote into all the servers daily and manually record information in a spreadsheet. These include things like disk usage, logs, log sizes, databases, web servers, processes, memory and CPU usage. 

A while back I wrote a Powershell Script that recorded heaps of the results for him. Unfortunately it didn't take many server changes before the script had more errors than results, I guess he could do stuff with all that extra time. I would fix stuff from time to time, but more often than not I was too busy with things I had to do or things I wanted to do.

The other day I decided it would be cool if I could write all the checks as NUnit tests. That way he could just run NUnit, point it towards the assembly and get cool Red/Green light testing of the network status. I could write test like:

[Test]
public void Server1_DiskUsage_CDrive_LessThan80Percent(). 

 

I also found this article: Setting up CruiseControl.NET to be a Continuous Monitoring Server. I haven't read it in detail, but I think its a pretty cool idea.

I don't have time to implement this yet, but I have started writing some of the tests from the Powershell script in C#. I started some code to get the memory usage from a server and I was immediately reminded how annoying it was trying to work out how values in WMI related to the items on the Performance tab in task manager. So marked up an image of the task manager window with the corresponding properties of the WMI.

 

Performance

 

See Win32_OperatingSystem_Class on MSDN for all the properties and descriptions

Anyway you might now be asking to see the C# code, well here it is. There is no exception handling as I was running it as an NUnit test which handled them for me.

private OperatingSystemInfo GetOperatingSystemInfo(string serverName)
{
    string wmiObjectName = "Win32_OperatingSystem";
    string connectionString = string.Format("\\\\{0}\\root\\cimv2:{1}", serverName, wmiObjectName);
    ManagementClass os = new ManagementClass(connectionString);
    foreach (ManagementObject obj in os.GetInstances())
    {
        OperatingSystemInfo osInfo = new OperatingSystemInfo();
        osInfo.NumberOfProcesses = (uint)obj.GetPropertyValue("NumberOfProcesses");
        osInfo.TotalVisibleMemorySize = (ulong)obj.GetPropertyValue("TotalVisibleMemorySize");
        osInfo.TotalVirtualMemorySize = (ulong)obj.GetPropertyValue("TotalVirtualMemorySize");
        osInfo.FreeVirtualMemory = (ulong)obj.GetPropertyValue("FreeVirtualMemory");
        osInfo.FreeSpaceInPagingFiles = (ulong)obj.GetPropertyValue("FreeSpaceInPagingFiles");
        osInfo.FreePhysicalMemory = (ulong)obj.GetPropertyValue("FreePhysicalMemory");
        return osInfo; 
    }
    return null;
}

public class OperatingSystemInfo
{
    public uint NumberOfProcesses { get; set; }
    public ulong TotalVisibleMemorySize { get; set; }
    public ulong TotalVirtualMemorySize { get; set; }
    public ulong FreeVirtualMemory { get; set; }
    public ulong FreeSpaceInPagingFiles { get; set; }
    public ulong FreePhysicalMemory { get; set; }
}
 

I hope it helps. I'm getting back to playing with the Microsoft MVC Preview 3 which is really cool and lots of fun. I hope to get a post out about what I like and don't like about it soon. 

 

Tags:
Categories:
Comments (2)

YSlow Performance Grade Improvements : Gzip components

July 18, 2008 14:10 by brodie

Up until now adding useful features to our ASP.NET IIS 6.0 hosted site has been the main driving force.  Recently though, as our web site begins to take on a greater user load, performance, optimization, and scalability are becoming more of a focus for us.

I've had Firebug installed on FireFox3.0 for some time now, which is an essential tool if you are a web developer, or designer for that matter. I can't tell you how much easier it's made debugging javascript and and fiddling around with CSS.

Recently I installed YSlow which is a plugin for the Firebug plugin (*vision*: a chain of double adapter plugs)  - it allows you to determine why your pages are slow (and they will be) and gives you some rules for speeding it up ... as defined by the Yahoo crew.

So I ran YSlow and this is the current state of play ... a big fat 'F' - FAIL! That simply won't do, so my goal over the next few weeks will be to get an 'A' grade.

image

 

The first item I thought I'd look at is Gzip components.

What is gzip? Basically it a file compression program that's supported by most browsers and web servers and allows you to serve up compressed http, therefore potentially making downloads a little faster.  You can read all about it on wikipedia.

 

So how do you turn it on?

Well here's what I did for IIS 6.0. (When we switch to IIS7.0 I provide an update)

Well, as usual, search the internet and found these useful resources at MS TechNet, Coding Horror, and Scott Forsyth's Blog.  Read all these and you'll be an IIS 6.0 Http Compression master! There are many scenarios and more advance things you can do but I'll list below the simple steps I took to get it working...

 

Step 1. Turn on Http compression in IIS 6.0

Right click on your Web Sites folder, go to properties  and open up the 'Service' tab and make it look like this...

image

 

Step 2. Allow direct metabase edit

Next we'll go and edit the IIS metabase so if you don't want to shutdown IIS then right click on the IIS Server node, go to Properties and enable Metabase Edit.

image

I'm sure that there are security problems with leaving this switched on so switch it back off after you've done your edit in step 3. Easy.

 

Step 3. Edit the Metabase.xml

Open the C:\Windows\system32\inetsrv\metabase.xml file in notepad.

Find the IISCompressionScheme sections and change them to look like this...

<IIsCompressionScheme    Location ="/LM/W3SVC/Filters/Compression/deflate"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="0"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="FALSE"
HcDynamicCompressionLevel="9"
HcFileExtensions="htm
html
txt
js
css"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="asp
dll
exe
aspx
asmx"
>
</IIsCompressionScheme>
<IIsCompressionScheme    Location ="/LM/W3SVC/Filters/Compression/gzip"
HcCompressionDll="%windir%\system32\inetsrv\gzip.dll"
HcCreateFlags="1"
HcDoDynamicCompression="TRUE"
HcDoOnDemandCompression="TRUE"
HcDoStaticCompression="TRUE"
HcDynamicCompressionLevel="9"
HcFileExtensions="htm
html
txt
js
css"
HcOnDemandCompLevel="10"
HcPriority="1"
HcScriptFileExtensions="asp
dll
exe
aspx
asmx"
>
</IIsCompressionScheme>

 

Obviously there are a few things to try in here (read the resource links above for more info) but all I did was change the HcFileExtensions, HcScriptFileExtensions, and the HcDynamicCompressionLevel.

 

Note: There are alternatives to editing this file directly like using the Adsutil.vbs, I tried some of the suggestions but it wasn't working for me initially (i'm sure it was something simple), so I moved on to editing the file directly ... much easier.

 

Step 4. Reset IIS

Now checking my YSlow results again and, ... only get a 'B' grade! WTF! Apparently this is because we're using MS ASP.NET AJAX and the WebResource.axd won't compress, hmm I did some searching and found that there were a few options available to me, so I checked out MbCompression on CodePlex.

 

Step. 5 Compress WebResource.axd

Do this by following his instructions here.

(UPDATE: The correct instructions can be found in the source code download from CodePlex)

Unfortunately though he indicates the wrong namespace to use  (Miron.Web.HandlersAndModules) ... so with the help of Reflector I found the correct namespace (Miron.Web.MbCompression).  To get the basic compression happening modify your web.config ... it should look something like below ...

 

<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, "/>
<add name="PageCompressionModule" type="Miron.Web.MbCompression.PageCompressionModule"/>
<add name="WebResourceCompressionModule" type="Miron.Web.MbCompression.WebResourceCompressionModule"/>
</httpModules>

 

Now, run YSlow again ... overall Performance Grade of 'D' (60) ... which is not great,  but better than a fail.  And now if you check out the Gzip components ... grade 'A'!!

 

image

 

The MbCompression seems to have a few more tricks up it's sleeve which I will try to use to minify js and css.

 

Next Time : Minify JS, Put JS at the bottom, and Put CSS at the top.


Microsoft Robotics Studio

July 17, 2008 20:50 by tarn

I finally decided to download Microsoft Robotics Studio (MSRS) and have a look at it. I had no idea what I would get, but I was hoping I could use it to simulate autonomous robot soccer matches and I wanted to see what else it could do. I spent an evening having a play with it, and here are my first impressions.

The SDK

The download was much smaller than I expected (approximately 87Mb), for some reason I thought it was going to be a plug-in for the Visual Studios IDE. It's just a collection a projects and some tools. I haven't yet download the April CTP which must have a bit more; its around 400Mb.

I looked at a few projects and most appear to be based around a Decentralized System Services (DSS) application model, or framework. The application model provides a framework for concurrent distributed services to interact. These could be sensors and actuators, controllers or processors. The services use a light-weight REST messages to communicate and interact. During simulation your services run normally, but instead of getting real images from the camera and really actuating motors you communicate with a simulated environment. The DSS is setup and linked to relevant service assemblies by XML files. There is a visual editor to assist configuring these files.

The simulations uses the AGEIA physics engine and DirectX 3d. I don't know much about the physics engine, except its made by NVidia and it can use dedicated physics hardware if you have it, which I don't. I have a mate who writes low level tests for graphics cards as a job and writes his own physics engine for fun. I'm sure he'll have plenty to tell me about it. Actually - Bryce you know we want you to post on this blog 

A visual programming language is provided. Its a visual data flow designer that can connect services that fit into the DSS framework. It seems similar to event based circuit simulation tools I've used, but with a very simple user interface and debugging tools. I did some of the tutorials but the only thing that really kept me interested was that I could send text to the Text to Speech convertor. I don't have a robot that I want to work right now, maybe then I would rate this tool more highly.  

The Robots

There is a fairly wide price range of off-the-shelf robots and robot kits that the Microsoft Robotics Studio that have been can be simulated (I found a list of these in this article). I was immediately drawn to a robot described as a "fighting Japanese robot" (for around $1500). When I looked him up on YouTube I was surprised to find that I'd seen him before, but he was dancing! Lego also has a more reasonably priced Robotics kit ($120). There is also the Nao which will apparently be used in RoboCup 2008! (I'm not sure if those Sony dogs compete in a different category, or are obsolete)

I haven't yet decided how much, if any, I am willing to fork out for a robotic toy. Can I write it off as tax deduction?

RoboCup and RoboChamps

The RoboChamps site was disappointing for me, it seems to be Silverlight 2. It caused javascript errors didn't rendering anything for me. I didn't want to spend the evening updating my Silverlight installation so I moved on.

Things started looking up when I found the Microsoft Soccer Simulation download. This download has the soccer simulation framework and a demo project with a two-on-two autonomous robot soccer match setup. The robots aren't humanoid, they're two wheeled things with a kicker and a camera. The robots have only been setup for two tasks; Find Ball and Approach Ball. Hence its not really a great spectacle, but a fantastic starting point.

There is a very basic vision processing method the robots use in the demo. The purpose of the method is simple; it takes a 320x200 array of colours from the camera and determines whether or not the ball is in the image. I had a look at the code and quickly realised I'd need to read up on some vision processing theory to really understand how it was working.

I then looked into an announcement: MSRS Nao Simulation Competition for RoboCup 2008 is now available. The post has everything you need to get started writing code for the humanoid Nao robots and simulating 4x4 or 8x8 soccer competitions. The RoboCup simulations uses the Microsoft Soccer Simulation. While these guys are much cooler than the Microsoft robots, they also take a lot more grunt to simulate and there are more of them on the pitch. My quad core processor and low range graphics didn't simulate them very well. (I've never been into computer games, I spend too much timing working and developing on computers and prefer board games, till now, my low range graphics card has always done enough for me).

Conclusion?

I only scratched the surface but I'm glad I checked it out. I'm wrapped there's a framework I can write C# services for autonomous robotic soccer players. I just need a better graphics card, more time and some mates to contribute. 

It seems the framework can only be used to make truly autonomous that have a processor running Windows and the .NET framework. This is a big step from the 8-bit microcontrollers at university. Robots have got cooler since then, but I'd look further into other operating systems, languages and tools before I started developing code for a real robot in MSRS.

If you just want to write some cool bot code and battle you mates, checkout this Scott Hanselman article, Learning Opportunity - .NET Terrarium is back! I haven't tried the original or the new, but I'm looking forward to it.

Finally, if your feeling a little concerned that the rise of the machines is fast approaching, this video won't give you any comfort. But it's also the topic of one of my favourite XKCD cartoons that doesn't involve velociraptors.


Web Development Frameworks

July 17, 2008 10:40 by tarn

I've just started getting into the Microsoft MVC Preview 3. Its cool and I'm having heaps of fun with it. Who thought you could have multiple form tags on a page ;-)

I wrote a post earlier this year after spending a couple of weeks in Ireland with some Java developers. I originally posted it internally at work with the intention of stirring up some .NET developers in my team. Today I decided to check out what I'd written to see if added any value to Microsoft MVC framework I am using now. It doesn't, but I decided to post it publicly anyway.     

It’s taken a while but you knew it was coming. Having come in contact with some Java development from a .Net world I wanted post some observations and opinions. I’ve really only had one day of exposure to server side Java, so I’m sure this article won’t be completely technically correct and I’m happy for people to comment on my errors or oversights.

Firstly I’ll start with the background. These boys are using Java SE (Standard Edition I guess) and not EE (Enterprise Edition). My understanding is that Java EE comes with some additional web framework elements, but I stand to be corrected on this.

Java SE at first glance actually looks like classic ASP with Java code. Just to clarify, both a server side languages and not VBScript and Javascript respectively. Both use the “<% %>” characters to separate the code from the response. Both can just write to the output directly. Both .jsp and .asp files can be called directly by URI and can respond (provided they are hosted on suitable web servers). So right now this looks like I should be comparing Classic ASP to Java, but that’s no brainer. Java is a native OO language, platform independent and also has native support for threading; game over classic ASP.

There still is the issue that Java server side code can very quickly degenerate to the spaghetti code we have seen in classic ASP code. And it can, and would if written badly. But to be fair, any language can. In some ways being a native OO language you have the tools to protect you against this. Really its still pretty primitive for a web framework.

The comparison with the ASP.Net framework becomes a much more interesting when you add the Apache Struts framework to Java. Basically the Struts framework is an implementation of the Model View Controller (MVC) pattern. The MVC pattern has is roots in an Apple SmallTalk framework. It wasn’t a framework that was used for web applications, but it did have clearly defined model, view and controller components.

MVC is a pattern to implement a system that takes requests and deliver responses. This is what HTTP is all about, all web servers do it.
The MVC pattern consists of three components. There is the “Model” which is the domain logic (a.k.a business logic or middle tier) and it also includes the data persistence the domain logic works with. There is also the “Controller” which is responsible for taking the request and routing them to the correct business logic, it then routs the output of the logic to a “View”. The “View” selected by the “Controller” takes the output from the domain logic and presents it to the user.
These guys weren't using the standard "View" from Apache struts they used XSLT to transform XML data from the model to HTML.

ASP.Net uses a page life cycle pattern to handle the same problem. We know this well; An .aspx page is requested, the aspx page points to some page logic, which can then calls some domain logic. The page then binds data to objects capable of rendering a view of that data. It seems normal that events on the rendered page are posted back and handled by that same page code. This is vastly different to how the MVC pattern works.

This has already got to long, so I’ll post another blog soon to continue this discussion and hopefully get stuck into the inevitable debates about the merit of both.

Feel free to comment corrections, additional information or opinions.

Tarn 

I hope to write some more relevant posts about my recent experiences with the Microsoft MVC framework soon. At the moment I'm having too much fun coding with it, and don't yet have much to say that Rob Connery, Scott Hanselman and Scott Gu haven't covered.  


Tags:
Categories:
Comments (0)