5 second TCP client/server interruptions
Hi all, I am currently working on a project that is giving me trouble for quite some time now. Using c++ and VS2010 I wrote a client and server application that is TCP/IP based on a really basic level. The project idea is simple. A server sends some image data to a client. (Later on to multiple clients) The amount of data may change depending on how fast the server can acquire images (e.g. webcam 30fps ~30 MB/s or more). By design the client/server connection must not be delayed sine all delayed data is immediately thrown away. I know some of you will say "use UDP" but since it obviously should also work with TCP and I don't want to lose any packages at all I want to use TCP. During server/client execution I now noticed some unexpected image freezes. Observing the process monitor's/task manager's I/O tab I noticed a 5 second delay during each of the freeze periods. These freezes are occurring randomly and I cannot reproduce them at will. Here is a log print of the data rate per seconds. 380 MB/s 379 MB/s 381 MB/s 231 MB/s 0 MB/s 0 MB/s 0 MB/s 0 MB/s 139 MB/s 367 MB/s 376 MB/s 380 MB/s First I thought that the sdk I'm using had some problems with winsockets. Therefore I also implemented a version of both server and client using another c++ sdk and later on for confirmation java. Testing all combinations on MS Windows 7 I realized that the error is occurring with each server/client combination. Then I checked the same (portable) java code on XP and Linux systems. The result was that on XP and Linux the server/client system worked without any freezes. On Windows 7 it did not. And since I have no idea what the problem could be, I am now asking you, the community for some ideas. I already tried to turn of the Nagle algorithm that according to some forum post, may sometimes cause problems. Using Google I've found a link to a similar question. But for me, none of those answers are helpfull. I also tried the suggestions in the following forum. I guess since the problem is only occurring on Windows 7 systems something has to be different in the way Windows 7 handles TCP connections compared to Windows XP. Thanks in advance for any responses.
January 9th, 2012 5:23am

Hi Rhodanos, Based on my knowledge. Windows 7 create some new feature about the TCP/IP offload on it which will cause the incompatible with the other machine, which is created for strenthing its transaction. So could you please try disabling them by following steps: Step One: reset the reference value of TCP offload. netsh int tcp reset netsh int tcp set global auto = normal netsh int tcp set global ecn = en Netsh int tcp set heuristics wsh=disabled netsh interface tcp set global chimney=disabled netsh interface tcp set global rss=disabled Step Two: disable the feature on your NIC card. IPv4 Checksum Offload Large Send Offload IPv4 TCP Checksum Offload IPv4 UDP Checksum Offload IPv4 Step Three: disable the SMBv2 on both servers. 1) Run the command below to disable SMB2 on Windows 2008 R2 sc config lanmanworkstation depend= bowser/mrxsmb10/nsi sc config mrxsmb20 start= disabled 2) Set the following registry key to 0 to disable SMB2 on the Windows 2008 R2 HKLM\System\CurrentControlSet\Services\LanmanServer\Parameters Value name: Smb2 Value type: REG_DWORD 0 = disabled Step Four: Reboot the server. If you have any problem, please let me know. Thank you. Annie Gu
Free Windows Admin Tool Kit Click here and download it now
January 11th, 2012 3:42am

Hi Annie Gu, first of all thank you for your answer. I have tried your suggestions with the following results. 1: I applied all commands with execution response "OK". But I could not observe any changes to the network output. 2: Only the network traffic seems to be half it's original speed. From the 380 MB/s down to ~170 MB/s. And the freeze is still occurring. Unfortunately I could not execute part 3 and 4 since I do not utilize a Windows 2008 Server. I just use two Windows 7 pc's or for faster testing, one Windows 7 pc with a localhost TCP socket connection between the server/client software. Rhodanos For testing I use the following Java code for client and server. import java.io.*; import java.net.*; import java.util.*; public class server { public static void main(String argv[]) throws Exception { InetAddress addy = InetAddress.getByName("127.0.0.1"); ServerSocket server = new ServerSocket(33001, 1, addy); int x = 512; int y = 512; int size = 4 + 4 + 4 + 8 + x*y*4; byte[] img = new byte[size]; Random rnd = new Random(System.currentTimeMillis()); for(int i=0; i<size;i++) img[i] = (byte)Math.abs(rnd.nextInt() % 256); System.out.println("waiting for new connection"); Socket connectionSocket = server.accept(); connectionSocket.setTcpNoDelay(true); connectionSocket.setTrafficClass(10); System.out.println("incomming new connection"); OutputStream out = connectionSocket.getOutputStream(); System.out.println("start sending data to socket"); System.out.println("Size: " + size + "x" + x + "y" + y); speedTimer timer = new speedTimer(1000); try { while(true) { //Thread.sleep(22); out.write(img); out.flush(); timer.bytesWritten(size); } } catch(IOException ioe) { ioe.printStackTrace(); } } } import java.io.*; import java.net.*; public class client { // client public static void main(String argv[]) throws Exception { Socket clientSocket = new Socket("127.0.0.1", 33001); clientSocket.setTcpNoDelay(true); InputStream instream = clientSocket.getInputStream(); int size = 10000; byte[] buf = new byte[size]; speedTimer timer = new speedTimer(1000); int read = 0; try { while(true) { read = instream.read(buf); if(read >= 0) { timer.bytesWritten(read); } } } catch(IOException ioe) { ioe.printStackTrace(); } } } import java.util.Timer; import java.util.TimerTask; public class speedTimer { Timer timer; RemindTask task = new RemindTask(); int millisec; public speedTimer(int millisec) { this.millisec = millisec; timer = new Timer(); timer.schedule(task, 0, millisec); } public void bytesWritten(int bytes) { task.bytesWritten(bytes); } class RemindTask extends TimerTask { int numBytes = 0; public void run() { System.out.println(((numBytes/1024)/1024)+" MB/s" ); //System.out.println(((numBytes/1024)/1024)/(1000/millisec) + " MB/s" ); // MB/s numBytes = 0; } public void bytesWritten(int bytes) { numBytes += bytes; } } }
January 11th, 2012 9:34am

Hi rhodanos, Sorry for the confusion in my steps, for steps three, it can be also applied into the Windows Vista later. So you can try the command on Windows 7 for disabling SMBv2. After that, please let me know the result. Besides, I'm not familiar with the script, so I'm afraid I couldn't help you to check this. Thanks for your understanding. Annie
Free Windows Admin Tool Kit Click here and download it now
January 12th, 2012 3:56am

Hello again, after applying all 3 proposed steps I still see no change in the network behaviour when running both programs. Further investigation into the problem revealed some new and maybe important information. The random 5 second network freeze seems to be occurring with localhost connections only. Running the client and server software on two different computers seems to prevent the error occurrence. In any case the localhost server/client connection still works on XP and LINUX. Does Windows 7/Vista handle localhost connections in a different way? Rhodanos
January 19th, 2012 8:59am

Hi Rhodanos, I have exactly the same problem with a localhost client/server application running on Windows 7. I observed non regular freeze of approximatively 5 seconds. Did you find a solution to this problem ? Thank you in advance Julie
Free Windows Admin Tool Kit Click here and download it now
May 25th, 2012 5:59am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics