msantos / tunctl

Erlang TUN/TAP interface
BSD 3-Clause "New" or "Revised" License
79 stars 23 forks source link

overruns and packet loss #7

Open romanr321 opened 6 years ago

romanr321 commented 6 years ago

I'm using tunctl to read UDP/VoiP packets from the TUN interface and at about 0.35MB/sec, or 1750 packets/sec, in each direction, I start seeing overruns and packets getting lost. Do you have any thoughts or suggestions on how to fix this? I optimized my code and got about a 10% improvement which indicates that it may have to do with how fast I'm reading from the TUN interface, but there's nothing left to optimize as I'm literally just reading and passing the data to a different process. The CPU is 50% idle. I'm using Ubuntu. Is there a known rate limit or any kernel settings I should look into?

msantos commented 6 years ago

Hey @romanr321! Are you using tunctl directly or the tuncer gen_server? If you're using tuncer, are you using {active, true|false}?

romanr321 commented 6 years ago

Hi @msantos! I'm using tuncer and {active, true} tuncer:create(Interface, [tun, no_pi, {active, true}])

romanr321 commented 6 years ago

I'm trying raw sockets and still experiencing similar results, no overruns in ifconfig but audible packet loss. Guessing it's not a problem with tunctl.

msantos commented 6 years ago

Just to be clear, the rate was:

0.35MB/s * 1024 * 1024 = 367001 bytes/s or 2.9Mb/s
367001 / 1750 = 210 byte packet 

Have you been able to do any profiling to see where the delay is? recon (https://github.com/ferd/recon) might be useful for live troubleshooting.

Can you try with {active,false}? That will force tuncer to read and write directly from the file descriptor.

I used to run an IPv6 over IPv4 tunnel using tunct but I can't find the benchmarks. I'll try to set up some tests in the next few days to do some debugging.

msantos commented 6 years ago

@romanr321 missed your last comment, sorry. If I can help, please let me know. I'll run some benchmarks, now I'm curious where it will break :)