views:

100

answers:

3

I have a .NET 3.5 server application that usually has about 8 clients. I'm using System.Net.Sockets for all the networking.

I've been told that if a client is running on the same box, it should use localhost:<port> or 127.0.0.1:<port> instead of the machine's ip or name for better performance. Several people at work have said that this skips some layers of the tcp stack.

But I'm not able to see any performance difference at all in testing (timing how long it takes to get a ping packet from server to client using System.Diagnostics.Stopwatch).

Should there really be better performance in theory?

+5  A: 

No, performance is same in both cases. If you are using your local device ip address, your operating system kernel don't transport your packets data to your network device and this data don't be was sended anywhere then you don't have any ISO layers calculations (encapsulation, decapsulation etc).

I belive the OS will see this is a local device and you treat it like it was 127.0.0.1. So in fact both will have the same effect.

Svisstack
Add to this reply, i belive the OS will see this is a local device and you treat it like it was 127.0.0.1. So in fact both will have the same effect
EKS
+1  A: 

I suppose it's possible that there will be an extremely tiny performance boost in using 127.0.0.1 (though I doubt it), but with 8 clients you'll never notice it. That performance difference would have to be aggregate over A LOT of traffic to become at all noticeable.

The larger concern would be which value is better from a maintenance perspective. If the application is always looking at localhost for external dependencies, it won't do well if run on another host. But if it's looking for a more universally understood address for those dependencies, it'll find them from anywhere on the network.

David
+1  A: 

Duplicate

Ertan
This is better in a comment than in an answer.
David
He is new, be nice to him
EKS