Skip to contentSkip to conversation

udp packet loss even with large socket buffer

DISCUSSION johnny zhao 2 participants 2 messages Feb 28, 2004 – Mar 2, 2004

lore
Share & tools
lore
#0 lore raw

hi,

Since my program is coping with MSN, it's not easy to post a small example. But I will try :)

I use the following code to initialize the socket:

*****************************

	session->rtp.loc_addr.sin_family = AF_INET;
	session->rtp.loc_addr.sin_addr.s_addr = INADDR_ANY;
	session->rtp.loc_addr.sin_port = htons (port);
	session->rtp.socket = socket (PF_INET, SOCK_DGRAM, 0);
	g_return_val_if_fail (session->rtp.socket > 0, -1);
	err = bind (session->rtp.socket,
		    (struct sockaddr *) &session->rtp.loc_addr,
		    sizeof (struct sockaddr_in));
	/* set the address reusable */
	err = setsockopt (session->rtp.socket, SOL_SOCKET, SO_REUSEADDR,
			  (void*)&optval, sizeof (optval));

	optval = 8388608;
	int optlen;
	err = setsockopt (session->rtp.socket, SOL_SOCKET, SO_RCVBUF,
	      (void*)&optval, sizeof (optval));
	err = getsockopt (session->rtp.socket, SOL_SOCKET, SO_RCVBUF,
	      (void*)&optval, &optlen);

**************************

the following code is used to receive data:
**************************

     while ( ( error = recvfrom (session->rtp.socket, mp->b_wptr,
					  1500, 0,
					  (struct sockaddr *) &remaddr,
					  &addrlen) ) > 0 )
     {
       mp->b_wptr = mp->b_rptr + error;
       rtp_parse(session, mp);    //this function parses and enqueues the 
received packet
       mp = allocb (1500/*session->max_buf_size*/, 0);   //wang
     }

**************************

These codes are executed in a thread with the highest priority. Thank you in advance!

Best regards,
Johnny

Quoted 31 lines

From: Denis Vlasenko <[email protected]>
To: "johnny zhao" <[email protected]>, [email protected]
Subject: Re: udp packet loss even with large socket buffer
Date: Sat, 28 Feb 2004 23:22:50 +0200

Quoted 3 lines · johnny zhao

Hi,

I have a problem when trying to receive udp packets containing video

data

Quoted 8 lines

sent by Microsoft Windows Messenger. Here is a detailed description:

Linux box:

    Linux-2.4.21-0.13mdksmp, P4 2.6G HT
socket mode:
    blocked mode
code used:
    while ( recvfrom(...) )
Quoted 5 lines

socket buffer size:
8388608, set by using sysctl -w net.core.rmem_default and rmem_max

I used ethereal(using libpcap) to monitor the network traffic. All the packets were transferred and captured by libpcap. But my program

constantly

Quoted 1 line

suffers from packet loss. According to ethereal, the average time

interval

Quoted 5 lines

between 2 packets is 70-80ms, and the minimum interval can go down to ~1ms. Each packet is smaller than 1500 bytes (ethernet MTU).

Can anybody help me? I googled and found a similar case that had been solved by increasing the socket buffer size. But it doesn't work for me.

Quoted 8 lines

I

Quoted 1 line

think 8M is a crazily large size :(

Post a small program demonstrating your problem.
(I'd test udp receive with netcat too)
--
vda

_________________________________________________________________
Find and compare great deals on Broadband access at the MSN High-Speed Marketplace. http://click.atdmt.com/AVE/go/onm00200360ave/direct/01/

#1 lore raw
Quoted 11 lines · johnny zhao

hi,

Since my program is coping with MSN, it's not easy to post a small example. But I will try :)

I use the following code to initialize the socket:

*****************************

    session->rtp.loc_addr.sin_family = AF_INET;
    session->rtp.loc_addr.sin_addr.s_addr = INADDR_ANY;
    session->rtp.loc_addr.sin_port = htons (port);
    session->rtp.socket = socket (PF_INET, SOCK_DGRAM, 0);
                                                        ^^^

This should really be IPPROTO_UDP as defined in <netinet/in.h>

Quoted 9 lines
    g_return_val_if_fail (session->rtp.socket > 0, -1);
    err = bind (session->rtp.socket,
            (struct sockaddr *) &session->rtp.loc_addr,
            sizeof (struct sockaddr_in));
    /* set the address reusable */
    err = setsockopt (session->rtp.socket, SOL_SOCKET, SO_REUSEADDR,
              (void*)&optval, sizeof (optval));

    optval = 8388608;

You are right, this is really a huuuuuge buffer. If you are getting a 1.5kb packet every 80 ms on average, this is about 20kb/second. Even a 64kb buffer should be much more than enough.

My advice is just request a 64kb buffer, and stop messing with the rmem_default and rmem_max parameters.

Signature · 2 lines
Paulo Marques - www.grupopie.com
"In a world without walls and fences who needs windows and gates?"