Tuesday, April 1, 2008

ServiceHost vs InstanceContext

Well, I might be missing something but from what I can tell using ServiceHost doesn't make very much sense in PeerChannel application. From my experiments if you create a ServiceHost and then create a DuplexChannel, when you invoke a service operation on the channel the message actual appears to arrive twice. Also creating a 'regular' Channel (ChannelFactory instead of DuplexChannelFactory) doesn't push the message to all nodes – it seems like only some of the nodes actually receive the message. There are a few examples out there using a 'regular' Channel – but when I run more that than 3 nodes using that configuration each node just does not get the message.

So – What I do recommend is using InstanceContext housed in a separate thread and DuplexChannels for all sending of data. A quick sample might look like this…

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Reentrant,
UseSynchronizationContext = false)]
public class ServiceImplementation: IPeerServiceContract
{ /* snip */ }

public static class WorkerThread
/* snip variables */
public static void Run()
service = new ServiceImplementation();
host = new InstanceContext(service);

channelFactory = new
channelFactory.Credentials.Peer.MeshPassword = MeshPassword;
channel = channelFactory.CreateChannel();

PeerChannel Performance Improvement

My advisor wanted me to drill down into the following areas to make sure I was doing things correctly since the performance was so bad on my first test runs through. Specifically he wanted me to look into:

  1. Why was I getting "The system hit the limit set for throttle MaxConcurrentCalls"
  2. How does the graph pruning work?

Well, after digging into the protocol spec and hitting Google about a few interesting sections – I've refactor rewritten the pretty much the entire application. And the good news is that my application runs ridiculously better, and so here are some of the tips/hits I figured out (with the help of some great Microsoft folks out there, MVPs and other bloggers)…

Threading Issues
First, the biggest tip off should have been that the WinForm I was using kept locking up and not responding. Having WCF run within the WinForm context is a very bad idea. If your WinForm freezes or locks up, I would start here looking at fixing that first. There are few articles[Here, Here, or Here] that talk about the UseSynchronizationContext and how that should be false to improve performance (as stated in the articles, it doesn't synchronize your callbacks to the UI thread). It seems (to me at least) that if you decorate your actual WinForm with the ServiceBehavior setting the InstanceContextMode, the ConcurrencyMode and UseSynchronizationContext it would still get nonresponsive as I added more nodes to the mesh (testing on a single box currently).

For some reason that seems to be the popular way to setup the samples out on the net – IMHO it seems much better to separate out the responsibilities into three classes 1) The UX View, 2) The Service Implementation Class, and 3) The Worker Thread Class. The Service Implementation class contains the ServiceBehavior and handles any incoming calls. The Worker Thread Class collaborates with the Service and contains both InstanceContext (which gets an instance of the Server Class) and the DuplexChannel that implement the ServiceContract. Finally the View just launches the Worker Thread on a dedicated thread. Take a look at Perf2 version on CodePlex Version 1.0 if you want to see it in action...

Graph Pruning
When I was originally running my tests, I also created a simple way to see who was connected to who. The strange thing was that it always looked fully connected. In short, the mistake I made here is that you can't assume it will start pruning right off the back. The two most important things here are Maintenance Timer needs to run clean up nodes, but that can only be effective after the LinkUtility is calculated which runs on another Timer. I need to run some more tests on this, but to be sure but it does appear to be removing some connections, just slowly… The biggest helps here were reading the actual Peer Channel Protocol Specification, the Patent and the blog post "How many channels can a mesh handle?"

Saturday, March 29, 2008

PeerChannel Specs

While searching for detailed information about the internals of Peer Channel I came across the actual specification for the Peer Channel and the actual patent that Microsoft submitted for it. This information should be really helpful, and is actual pretty interesting just in the sense of how a company like Microsoft thinks and lays out software design. The links are below in case anyone else is interested…

Peer Channel Protocol Specification

US Patent

Update: Just noticed the release date on the document: Thursday, March 13, 2008 - no wonder I never found it before...

Wednesday, February 27, 2008

Project Update

Alright, the project is starting to come together. Here is the current feature list

  1. Launching the Monitor/Controller on multiple machines allows you launch and manage multiple Nodes from one any Monitor/Controller.
  2. You can toggle between sending messages through PeerChannel or TCP
  3. At the end, each node can be told to upload it's data collected to the central SqlExpress server
  4. You can enable Graph Monitoring which uses a Microsoft Research Project called GLEE (Graph Layout Execution Engine) to graphically show the connections between machines for the Peer Network (Traditional TCP obviously looks like a star)

Here is a link the GLEE – it works really well. The biggest problem with my implementation is that the nodes are being updated periodically, and my graph view only updates on button click events which copies the data that was being stored. So it's not well synchronized or anything yet – and so if you click quickly it can show you different graphs. That is a pretty easy bug to address.

The next plan is get the software running on multiple machines and start testing the performance.

Once again – here is the link to the CodePlex Project -- http://www.codeplex.com/peerchannelperf

Saturday, February 16, 2008

PeerChannel Performance Code

We use Team Foundation Server at work, and now that I've been playing with my PeerChannel Performance application – I'm realizing how much I miss having source control. So I put my entire source up on CodePlex. The project is a Visual Studio 2008 – and I'm using TFS Explorer 2008 to connect to it.

Here is the Project Page -- http://www.codeplex.com/peerchannelperf

Sunday, February 10, 2008

Starting a Masters Project

Getting started on this project is much harder than I expected. I'm about 6 weeks in and feel very behind – being in New Hampshire all last week for work didn't help either. So far I have created two prototypes of WCF PeerChannel applications – one to simulate a Computer Aided Dispatch solution using PeerChannel and the beginnings of sample Chat Application. Both focus on the one way transmittal of information across the mesh and have gotten more specific in terms of handling people joining and leaving the mesh and finally creating a MessagePropagationFilter to avoid receiving any locally created messages (Thanks Peer Channel Team Blog). The next big task for a real implementation would most likely be synchronization of new nodes with the existing nodes – but for this project I'll focus on determining good ways to log and determine the performance limitations of the system.

Now that I have gotten my hands a little dirty with WCF, I really wanted to focus on the paper and getting an outline for my project created. I really didn't know where to start, so I started where I always start when I don't know what to do -- Google for it. So one quick Google for 'master thesis outline' and I have some where to start. A few articles seem very helpful and so I wanted to post them here…

How to Organize your Thesis

How to Write a Master's Thesis in Computer Science

Monday, January 28, 2008

My Masters Project Kickoff...

Welcome, I've created this site to help document and track my progress on my Masters Project for the University of Michigan - Dearborn. I've been attending school for the last 3 years working towards my Masters in Computer and Information Science.

My final project is a study on the latency of a WCF PeerChannel application when applied to systems where the message delivery is time sensitive and critical. One specific system that I will investigate though out my work which contains these types of constraints is a Law Enforcement Computer Aided Dispatch application.

I also have created a googlepages site to store any documents created and research notes that I find along the way.

My hope is that this helps others and at the same time keeps me honest on my progress and my findings. Thanks