UDP packet queue length

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am running into a limit of 64 queued datagrams.  This isn't a
data buffer size; varying the size of the datagram makes no difference
in the observed queue size.  If more datagrams are sent before some are
read, they are silently dropped.  (By "silently," I mean, "tcpdump
doesn't record these as dropped packets.")  This is a problem because
while my consumer can handle the overall load easily, the requests
often come in large bursts.

This only happens when the sending and receiving processes are on
different machines. Running on the same machine yields a higher queue length (even if you avoid loopback).

Can anyone tell me where this magic 64 number comes from, so I can
increase it?

Code to illustrate this follows.

-Jonathan

// "server" process
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    int sock;
    struct sockaddr_in server;

    setbuf(stdout, (char *)0); // unbuffer

    sock = socket(AF_INET, SOCK_DGRAM, 0);
    bzero(&server, sizeof(server));
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = INADDR_ANY;
    server.sin_port = htons(4000);

    if (bind(sock, (struct sockaddr *)&server, sizeof(server)) < 0) {
        printf("couldn't bind\n");
        exit(1);
    }
    printf("... bound.  press a key after sending packets\n");
    getchar();

    // only 64 will be printed even though 200 were sent
    while (1) {
        char buf[1024];
        struct sockaddr_in from;
        int fromlen;

        recvfrom(sock, buf, 1023, 0, (struct sockaddr *)&from, &fromlen);
        buf[fromlen] = 0;
        printf("%s\n", buf);
    }
}

// "client" process
#!/usr/bin/python
import socket

for i in range(200):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # replace *server machine* with the appropriate IP
    sock.sendto('a' * 100, 0, ('*server machine*', 4000))
    sock.close()
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux