0

What I am attempting to do is ingest a lot of logs over UDP using nodejs. I ended up writing a decent bit of code to handle all of this. However, it appears I am losing a lot of the messages being sent over UDP when I am testing.

The simple code below will illustrate my problems:

var dgram = require("dgram")
, udp = dgram.createSocket('udp4')
, connections = 0

udp.on('message', function(msg){
  connections++
})

setInterval(function(){
  console.log(connections + ' msg per sec incoming') 
  connections = 0
},1000);

udp.bind(514)

All I do here is create socket and bind to 514. I use loggen (log generating tool on linux) to send 5k logs per second and my console looks like this:

2404 msg per sec incoming
2409 msg per sec incoming
2001 msg per sec incoming
2409 msg per sec incoming
2696 msg per sec incoming
2650 msg per sec incoming

However, then I increase the logs per second sent by loggen to 70k and my console looks like this:

30738 msg per sec incoming
32284 msg per sec incoming
35104 msg per sec incoming
34998 msg per sec incoming
34441 msg per sec incoming
33890 msg per sec incoming

I honestly have tried to figure out if this is a nodejs limitation or a UDP limitation or a NIC limitation, but really it doesn't seem like it is any of them. If Node can receive 30k+ messages per second at one point (despite it's lose of over 50%) why cant it receive 100% of the 5k sent previously? Regardless of the amount of messages sent it seems to be losing just over 50% of the messages.

Anyone have any suggestions as to what might be going on here? Obviously this is a very simple example but I see the same issues in my full code so the principles should probably be the same.

Jeremy Battle
  • 1,638
  • 13
  • 18
  • Try increasing the receive socket buffer size, increases latency but permits higher throughput. – Steve-o Dec 13 '12 at 19:35
  • Thanks for the comment Steve-o, I have increased the receive socket buffer size default and max and have similar results as posted above. Any other guesses? – Jeremy Battle Dec 13 '12 at 21:02
  • I've run Wireshark and it seems that when I increase the message size I am sending to 1200 bytes the numbers are accurate for the number of packets being received by the NIC (incoming messages increase to around ~3500 as well but only ~3500 are received by the NIC). However, if I keep the message size at 200 bytes the packets received by the NIC are 5k per second and I am only seeing ~2600 per second in the program. I am not sure what to make of the behavior. – Jeremy Battle Dec 13 '12 at 21:08

0 Answers0