CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2010
    Posts
    6

    Multicast speed limits issue!!

    I recently made a very small test program, almost same as the example from msdn

    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    I change the source code a little bit, so that it will be multicast, and it keepsending data as soon as possible, and I will look at task manager to see how much network is utilized.

    If ip address is a multicast address, the program only uses 10% of the network bandwidth.
    While the program use almost 100% bandwidth, if the ip address is a unicast address.

    2 PC connected to a switch, both use a fixed ip address, (There is no rounter involved)

    I like to make multicast tranportation faster, so that my application can have better performance. I wonder if there is any setting in windows or somewhere else for making multicast fast, or there is any function for the multicast socket.

    Please please help.
    Code:
    #ifndef UNICODE
    #define UNICODE
    #endif
    
    #define WIN32_LEAN_AND_MEAN
    
    #include <winsock2.h>
    #include <Ws2tcpip.h>
    #include <stdio.h>
    
    // Link with ws2_32.lib
    #pragma comment(lib, "Ws2_32.lib")
    
    int main()
    {
    
    	int iResult;
    	WSADATA wsaData;
    
    	SOCKET SendSocket = INVALID_SOCKET;
    	sockaddr_in RecvAddr;
    
    	unsigned short Port = 27015;
    
    	char SendBuf[1024];
    	int BufLen = 1024;
    
    	//----------------------
    	// Initialize Winsock
    	iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    	if (iResult != NO_ERROR) {
    		wprintf(L"WSAStartup failed with error: %d\n", iResult);
    		return 1;
    	}
    
    	//---------------------------------------------
    	// Create a socket for sending data
    	SendSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    	if (SendSocket == INVALID_SOCKET) {
    		wprintf(L"socket failed with error: %ld\n", WSAGetLastError());
    		WSACleanup();
    		return 1;
    	}
    	//---------------------------------------------
    	// Set up the RecvAddr structure with the IP address of
    	// the receiver (in this example case "192.168.1.1")
    	// and the specified port number.
    	RecvAddr.sin_family = AF_INET;
    	RecvAddr.sin_port = htons(Port);
    	RecvAddr.sin_addr.s_addr = inet_addr("234.10.10.10");
    
    	//---------------------------------------------
    	// Send a datagram to the receiver
    	char ttl = 0;
    	int r = setsockopt(SendSocket, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));
    	wprintf(L"Sending a datagram to the receiver...\n");
    	while (true) {
    		iResult = sendto(SendSocket,
    			SendBuf, BufLen, 0, (SOCKADDR *)& RecvAddr, sizeof(RecvAddr));
    		if (iResult == SOCKET_ERROR) {
    			wprintf(L"sendto failed with error: %d\n", WSAGetLastError());
    			closesocket(SendSocket);
    			WSACleanup();
    			return 1;
    		}
    	}
    	//---------------------------------------------
    	// When the application is finished sending, close the socket.
    	wprintf(L"Finished sending. Closing socket.\n");
    	iResult = closesocket(SendSocket);	
    	if (iResult == SOCKET_ERROR) {
    		wprintf(L"closesocket failed with error: %d\n", WSAGetLastError());
    		WSACleanup();
    		return 1;
    	}
    	//---------------------------------------------
    	// Clean up and quit.
    	wprintf(L"Exiting.\n");
    	WSACleanup();
    	return 0;
    }
    Last edited by chiyuwang; September 9th, 2015 at 02:53 AM.

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Multicast speed limits issue!!

    What you're seeing is normal. There are many reasons why multicast will see (significant) slowdowns. Mostly these are related to hardware and the need to keep the entire multicast stream synchronised.
    Whle the names unicast/multicast are similar, and the implementation interface is similar and usually just takes a couple lines of code to change from one to the other. the underlying low level technology beging unicast and multicast are quite different.


    1) multicast is typically slowed to compensate for the slowest computer on the network segment.
    Find out what the slowest one is, take him off the network segment.. (this may of course not be an option).

    2) Make sure IGMP snooping is NOT enabled on any devices.
    Note that when any device (including the switch) has IGMP snooping turned on. Multicast packets will be treated as broadcast. While that will only show up as a single packet leaving your pc and on the network monitor, it'll have a much heavier penalty on the network wire, and could cause extremely high network load.

    3) Make sure all devices on the network(segment) support multicast. If one of them doesn't, again this could end up having your multicast being treated as a broadcast.


    4) Also and this is something many people don't get when they start out with networking.

    Multicast is NOT a method for improving network traffic. It is intended as a means to decrease potential bandwidth overload problems in an environment where you will be communicating in a one-to-many approach with a significantly large payload. Stressing on the "many" here, we're talking at least a dozen or so other computers before multicast will even start to see a benefit over unicast.

    If your number of target machines is low, then multicast overhead will ruin your attempts.
    If you're payload is very small packets, then synchronisation will ruin your attempts and it would be faster to use unicast.
    Last edited by OReubens; September 9th, 2015 at 07:13 AM.

  3. #3
    Join Date
    Mar 2010
    Posts
    6

    Re: Multicast speed limits issue!!

    Thank you so much for the detailed reply.

    I will go through them and find out which reason that causes the problem.

    Quote Originally Posted by OReubens View Post
    What you're seeing is normal. There are many reasons why multicast will see (significant) slowdowns. Mostly these are related to hardware and the need to keep the entire multicast stream synchronised.
    Whle the names unicast/multicast are similar, and the implementation interface is similar and usually just takes a couple lines of code to change from one to the other. the underlying low level technology beging unicast and multicast are quite different.


    1) multicast is typically slowed to compensate for the slowest computer on the network segment.
    Find out what the slowest one is, take him off the network segment.. (this may of course not be an option).

    2) Make sure IGMP snooping is NOT enabled on any devices.
    Note that when any device (including the switch) has IGMP snooping turned on. Multicast packets will be treated as broadcast. While that will only show up as a single packet leaving your pc and on the network monitor, it'll have a much heavier penalty on the network wire, and could cause extremely high network load.

    3) Make sure all devices on the network(segment) support multicast. If one of them doesn't, again this could end up having your multicast being treated as a broadcast.


    4) Also and this is something many people don't get when they start out with networking.

    Multicast is NOT a method for improving network traffic. It is intended as a means to decrease potential bandwidth overload problems in an environment where you will be communicating in a one-to-many approach with a significantly large payload. Stressing on the "many" here, we're talking at least a dozen or so other computers before multicast will even start to see a benefit over unicast.

    If your number of target machines is low, then multicast overhead will ruin your attempts.
    If you're payload is very small packets, then synchronisation will ruin your attempts and it would be faster to use unicast.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured