Reputation: 1885
I created a WCF service; a simple getData(i). I hosted it in a windows service; wrote a client to access that service. getData(i) is "empty" - it just returns "you entered i".
Client
class Program
{
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
ServiceReference1.iRateCacheClient client = new
ServiceReference1.iRateCacheClient();
string returnString;
for(int i = 0; i < 1000; i++)
returnString = client.GetData(i);
stopWatch.Stop();
}
}
In that client it takes
Makes me think that the first call is taking too much time. My use case is that a lot of short lived client programs would be calling that service, once each. The whole purpose of writing that WCF service was that I wanted to separate out the function call from those clients to a separate process; i.e. I did not want to put that getData() inside of a dll that clients call.
2 seconds "overhead" for a service call is unacceptable. Am I doing something wrong? I expected that service call to be over in < 1 millisecond. I am accustomed to COM/DCOM; and the overhead for those was very minimal.
The local service is using HTTP transport.
Upvotes: 1
Views: 5566
Reputation: 523
First call to WCF service is always slow.
Even more it can be also slow after some idle time (see my answer how to prevent it). But for the first call the only way to handle that is to warm up the service somehow. For example make any call during application initialization and then keep the service and thead pool alive.
To make it really fast you should use any type of binding with binary serialization (netTcp or namedPipe, if you use same host) and ideally different binary serializer. From my experience simply using ProtoBuf .NET can give you 2 times better latency values. Almost all you need is to add Protobuf specific attributes to your data contract and to enable protobuf behavior in config file via extension.
Good luck!
Upvotes: 0
Reputation: 22421
If only the first call is so slow, you need to check whether it is the server that takes the time to start or the client. It is not unusual that the first call to a web service is slow, especially if IIS has to start the application pool etc.
So possible countermeasures are:
When judging performance, I'd not set too much weight on the first request. In addition, it is more about "is my approach fast enough" than about "is my approach faster than n ms". WCF is not an exotic technology; there are lots of systems that run fast enough on it.
Nevertheless, it is a technology built for interoperation; COM/DCOM were not built for interoperation and therefore can easily offer a better performance. Especially COM is not a good comparison as it runs in the same process; DCOM still uses a proprietary protocol. WCF always means that you have to transfer data to another process that is located on the same or another computer. This includes that you need to serialize the data into XML, transmit the data and deserialize it again. So there always is an overhead. One of the most efficient countermeasures is to reduce the number of requests to the server.
Upvotes: 3