Search code examples
c#wcfsockets

WCF or Custom Socket Architecture


I'm writing a client/server architecture where there are going to be possibly hundreds of clients over multiple virtual machines, mostly on the intranet but some in other locations.

Each client will be gathering data constantly and sending a message to a server every second or so. Each message will probably be about 128 characters or so in length.

My question is, for this architecture where I am writing both client/server in .NET should I go with WCF or some socket code I've written previously? I need scalability (which the socket code has in mind), reliability, and just the ability to handle that many messages.


Solution

  • I would not make final decision without peforming some proof of concept. Create very simple service, host it and use some stress test to get real performance results. Than validate results against your requirements. You have mentioned amount of messages but you didn't mentioned expected response time. There is currently discussed similar question on MSDN forum which complains about slow response time of WCF compared to sockets.

    Other requirements are not directly mentioned in your post so I will make some assumption for best performance:

    • Use netTcpBinding - best performance, binary encoding, requires .NET server / clients. I guess you are going to use Net.Tcp because your other choice was direct socket programming.
    • Don't use security if you don't have to - reduces performance. Probably not possible for clients outside your intranet.
    • Reuse proxy on clients if possible. Openning TCP connection is expensive if you reuse the same proxy you will have single connection per proxy. This will affect instancing of you services - by default single service instance will handle all requests from single proxy.
    • Set service throttling so that your service host is ready for many clients

    Also you should make some decisions about load balancing. Load balancing for WCF net.tcp connections requires sticky sessions (session affinity) so that after openning the channel client always calls the service on the same server (bacause instance of that service was created only on single server).