Luke C.
Luke C.

Reputation: 21

Sending lots of small packets out of Node.js UDP doesn't send all of them

I have a project that I'm working on that needs to send a small 9 byte packet to 7000 different hosts outside the local network, after which it waits for their replies back on the same port and processes the responses.

The problem I'm having is Node.js dgram (udp4) doesn't seem to be sending all packets out. I'm not rate limiting in any way so there might be an issue there.

I'm looping, creating the packets, then firing them straight out using .send(). With Wireshark open I can see that out of the 7000 being "sent" only ~1300 of them appear to be hitting the wire and leaving.

The script itself is reporting all packets as sent with no errors, Wireshark shows a different result, and the hosts at the other end reflect what Wireshark says, they don't receive the packet. I'm using the following to send and verify, packet is a buffer.

udpServer.send(packet, 0, packet.length, port, address, function(error) {
  if (!error) {
    successes++;
    console.log(successes + "/" + total);
  } else {
    console.log(error);
  }
});

Any ideas on what I am doing wrong here, or what's been overlooked?

Upvotes: 2

Views: 893

Answers (1)

jdizzle
jdizzle

Reputation: 4154

There are many junctures where your packet could be dropped:

  1. dropped when sending to kernel. Are you on linux? Try using strace to find the system call (probably send, sendmsg, or sendto) return value. If the system call is returning an error, I'd expect that to be reported in "error" by Node, though.

  2. dropped in the kernel tx queue. On linux you can check, eg, /sys/class/net/eth0/statistics/ and see if any drop counters are incrementing.

  3. dropped in hardware tx queue. If using an Intel NIC you can run ethtool -S eth0 to see if any drop counters are incremented.

  4. dropped in intermediate hardware (eg switches/routers). This is trickier to see, as it's vendor dependent and maybe invisible. You can eliminate this by hooking your machines up directly to each other.

  5. dropped in hardware rx queue. On the remote end, check all same stats to see if an overflow is occurring there.

Upvotes: 1

Related Questions