I am looking at using the rotuer sample that comes with the samples in the
Vista sdk (Microsoft
SDKs\Windows\v6.0\Samples\WCFSamples\TechnologySam ples\Scenario\Router\CS\router)
I am using .Net 3.0, C# 2.0, on win2K3 servers.
I have stripped down almost all of the non-essential code from the message
processor , leaving me with this code:
//ProcessMessage implemenation
Message IRequestReplyDatagramRouter.ProcessMessage(Message message)
{
string newEndPoint = ///destination server endpoint.
EndpointAddress to = new EndpointAddress(newEndpoint);
// If the router doesn't already have a two-way datagram channel
to the 'to' EPR or if that channel is no longer opened, create one.
IRequestReplyDatagramRouter forwardingChannel;
if (!this.extension.RequestReplyDatagramChannels.TryG etValue(to,
out forwardingChannel) || ((IClientChannel)forwardingChannel).State !=
CommunicationState.Opened)
{
lock (this.extension.RequestReplyDatagramChannels)
{
if
(!this.extension.RequestReplyDatagramChannels.TryG etValue(to, out
forwardingChannel) || ((IClientChannel)forwardingChannel).State !=
CommunicationState.Opened)
{
ChannelFactory<IRequestReplyDatagramRouterfactory
= new
ChannelFactory<IRequestReplyDatagramRouter>(this.e xtension.Bindings[to.Uri.Scheme], to);
// Add a channel behavior that will turn off
validation of @mustUnderstand on the reply's headers.
factory.Endpoint.Behaviors.Add(new
MustUnderstandBehavior(false));
forwardingChannel = factory.CreateChannel();
this.extension.RequestReplyDatagramChannels[to] =
forwardingChannel;
}
}
}
Message response = forwardingChannel.ProcessMessage(message);
return response;
}
This is almost exactly the same as the sample, except for these changes I made
1) I am hosting the service in IIS (6.0)
2) I replaced the custom binding class in the extension class with "new
basicHTTPBinding()" ( i.e., where it calls
"this.extension.Bindings[to.Uri.Scheme]")
3) For now the destination URL is hardcoded (the "to" endpoint")
Here's the question:
The Router works fine, but I am concerned about CPU usage.
Stress testing on our development servers shows that the CPU hits 90-100%
on the routing server when I hit about 50 requests a second. When I call my
destination server (the actual app logic) directly from the test client, the
application server rarely goes over 20% CPU. The operation is a very light
operation , mainly looking up data in a static dictionary.
I verified by logging that the forwarding channel is *not* being created
every time. It is cached in the extension class.
The only code which is executing every call is
Message response = forwardingChannel.ProcessMessage(message);
Why would this use so much CPU, and where could I look to tune this for more
efficiency?
Thanks.
JS
--
Jonathan Steinberg
Jefferies & Co.