Programs start in 2 seconds on my machine, but 15 seconds on others

I have two programs written in C ++ that use Winsock. They both accept TCP connections and one sends data, the other receives data. They are compiled in Visual Studio 2008. I also have a program written in C # that connects to both C ++ programs and forwards the packets it receives from one and sends them to the other. In doing so, it counts and displays the number of packets forwarded. In addition, the elapsed time from the first to the most recent packet is displayed.

A C ++ program that sends packets just loops 1000 times, sending the same data. When I run all three applications on my development machine (using loopback or actual IP), packets go through the whole system in about 2 seconds. When I run all three on any other PC in our lab, it always takes 15 to 16 seconds. Each PC has a different processor and memory size, but they all run Windows XP Professional. My development PC actually has an older AMD Athlon with half the memory capacity of one of the machines that takes longer to run. I have observed the cpu timeline in the task manager on my machine and another one and none of them are using a significant portion of the cpu (i.e. over 10%) while these programs are running.

Does anyone have any ideas? I can only think of installing Visual Studio on the target machine to see if this is related to this.

The problem is solved =========================================================== ==

I first installed Visual Studio to make sure it has some effect and it doesn't. Then I tested the programs on my new development PC and it ran just as fast as my old one. Running programs on a Vista laptop brought another 15 seconds.

I was printing timestamps on either side of certain instructions in the server program to see what was taking the longest, and I found that the delay was caused by a 1 millisecond call to Sleep (). Apparently, on my old and new systems, Sleep (1) was ignored because I would have 10 to 20 packets being sent in one millisecond. Sometimes I would have a performance gap of about 15 or 16 milliseconds, resulting in a time of about 2 seconds for 1000 packets. On systems that took about 15 seconds to run through 1000 packets, I would have a gap of 15 or 16 milliseconds between sending each packet.

I commented out the call to the Sleep () method and now packets are sent immediately. Thanks for the help.

+2


source to share


2 answers


You should profile your application in a good 2 second case and a 15 second lab case and see where they differ. The difference could be due to any number of issues (disk, antivirus, network) - without any data they support, we just shot in the dark.



If you don't have access to a profiler, you can add sync to different phases of your program to see which phase takes longer.

+3


source


You can try checking your Winsock performance tuning registry settings - perhaps installing some game or utility has changed the settings on your PC.



0


source







All Articles