views:

183

answers:

7

I'm currently in the process of performance profiling. We have a basic client/server application. Would the TCP transfer speed be different if I ran client/server on the same machine (localhost) vs across two computers on a LAN?

A: 

It really depends on what your application does....

As an example: If it transfers 10GB files from client to server, then yes, it will make a difference.

Sergio
+3  A: 

Yes definitely, the latency of sending it across the network would slow the program down. The throughput wouldn't but if you're waiting for replies before sending data then this builds up because of extra latency.

LnDCobra
For localhost, I get ping times of 0.024ms, for pinging my router, I get times of 0.339ms
Earlz
LnDCobra, this is actually a great answer. "If you're waiting for replies"... this happens when you talk to somebody on skype. The whole conversation slows down due to a few ms of latency.
Yar
Yes, if you think about the difference between 0.024 and 0.339 is massive, according to those timings localhost is about 15x faster than LAN.
LnDCobra
A: 

I don't know if it measurable (that also depends on your LAN's speed) but from a logical point of view, of course there is a difference. Localhost will always be the fastest as the data has not be sent through another medium (like air or copper wire).

But depending on what your application does, this might or might not matter.

Felix Kling
A: 

TCP transfer speed will be! because if you ran it on same computer it will forward packets locally without even touching LAN and network adapter.

But overall speed of client+server may be better on different machines, especially if you do not communicate with server too often.

Andrey
@Andrey: This is not necessarily true. Local connections are still passed through the adapter using the loopback if the application dictates that it use the network layer for transfers.
Joel Etherton
please explain how can application dictate to use network?
Andrey
+1  A: 

When using localhost, local resources are more likely to be the performance bottleneck because of memory, disk, cpu, etc. When using two computers, its more likely the network will be the bottleneck because of latency, bandwidth, throughput, packet loss, etc.

It depends on what your application does and how it uses the network, client, and server.

Richard Levasseur
A: 

The transfer times would almost certainly be faster if the client and server were on the same machine. That may not actually matter to the performance of your program as a whole depending on the other resources consumed by the client and server.

Robert Davis
+1  A: 

I just hit this issue on a project at work. Using UDP with localhost is at least an order of magnitude faster than over a network connection (maybe two orders of magnitude), and I believe with localhost there is no MTU ceiling of 1500 as normally exists for network ports.

One unconfirmed suspicion is the built in network ports on PCs are not all the same quality, so even if they claim to be gigabit, you may not be able to really go that fast. But it may also be making lots of Windows system calls (one OS call per packet) may be a significant overhead. With TCP I can hand the OS a large chunk of data to write in a single call. With UDP I have to hand it a packet at a time, limited by the MTU size, resulting in a much larger number of OS calls. But unconfirmed as yet.

Have not tried Linux yet.

Alan Kent