porech / engarde

A go network utility to create a reliable IP tunnel over multiple connections
GNU General Public License v2.0
280 stars 41 forks source link

Optimization: Reduced CPU usage on bandwidth load. #22

Open Marctraider opened 5 years ago

Marctraider commented 5 years ago

Optimization: Reduced CPU usage on bandwidth load.

Noticed the software is quite CPU bound, although it doesn't currently appear to give me any issues, it could maybe be beneficial for higher throughput on load).

ale-rinaldi commented 5 years ago

Yep, I'm pretty sure CPU usage and bad throughput are really related. I never had a good enough look at this aspect, since my main usage of engarde (and the reason why I wrote it) is to reliably forward a 256Kbps audio stream across the Internet... But I think it's time to seriously work on it. Thank you

Marctraider commented 5 years ago

I typically noticed this when I first transitioned from ARM based router to Intel NuC and my clock speed was stuck on 800Mhz due to some linux quirks. (intel_pstate vs acpi-cpufreq driver).

At first I thought it was the cumulative bandwidth with wireguard and the encryption it uses, but that doesn't seem to be the case! :)

Marctraider commented 5 years ago

I see your comment in mail, not here though.

either way, I can sometimes sustain 175+mbps which the max my fastest connection can achieve, I assume its also drawing about 80mpbs from the two other lines, so an accumulation of 250+mbit, and at that point i'm not even sure if the application or my cpu is at its limits.

Its not a severity thing for me, but any optimization is always welcome (Mostly in regard to unable to write socket / short ping spike thingy)

No sweat :)

ale-rinaldi commented 5 years ago

You're right, I can't see the comment here, too :/

Well, by the way I don't like it using so much CPU anyway, it's a nonsense thing for just taking UDP packets from one place and putting them in another.

For the ping issue, maybe I have a solution for it, even if I'll need your help to test it since it's not easy for me to reproduce. I'll update the relative issue as soon as I have something ready to test.

BTW, if you're finding engarde useful for your workflow, we just added a Bitcoin address for donations in the readme :)

Marctraider commented 5 years ago

Do you have paypal instead? I don't actually have a bitcoin wallet.

But sure, I'm more than happy to test stuff it it makes the program (and redundancy) even more efficient. You should promote this tool a bit more, It took me 2 months of screwing around before I even knew this existed, and I searched quite a lot. Could've saved me so much time :-(

Currently my setup is basically a testbed, still dealing with some usb quirks on my ethernet dongles etc, but eventually I just want it to run and keep it at that. (Until there are updates or other improvements ofcourse)

So for now I'm all yours!

Marctraider commented 5 years ago

Edit: Made a bitcoin wallet, cheers!

ale-rinaldi commented 5 years ago

Hi @Marctraider , wow, that's great, thank you very much! Unfortunately I'm still working on your issue, expecially regarding the latency peaks. I didn't make a test build with reduce throughput because it's simply insane: it doesn't go over 1.5Mbps and that's not a viable solution at all.

I tried different approaches about it but none of them gave the expected results: I hope to be able to find a solution soon!

Thanks again :)

Marctraider commented 5 years ago

@ale-rinaldi Np man, it is for the appreciation for your current code :-)

Does the 'buffer overflow' issue also happen if engarde detached a specific interface faster? In that case maybe it is more easily handled with a simple check somehow with high polling rate? To at least diminish the effects.

Seems it is now just writing to something even if it is no longer possible. No clue how this would have to be checked though.

And no, 1.5Mbps seems practically unusuable lol.

Anyway, the issue rarely ever happens, just under certain circumstances. Seems like the last culprit to solve, to make engarde truly 100% solid.

ghost commented 4 years ago

I'm able to pull 25mbit/s (my internet limit) on 720mhz ar71xx Archer C7v2, will test over lan to see max, I simply compiled engarde-client with mips flag without any effort, works like a dream! Thank you dev!

My journey for usable internet from worse to best on unstable lines: Speedify on RPi -> OpenMPTCProuter(best of all for TCP only + aggregate) -> borrowed Peplink -> Glorytun UDP (bad with packet loss, even at 1% limiter) -> ExitLag -> Engarde (no aggregation), finally done :)

Edit: And yes it spikes 100% cpu, average 75 on full speed, but with no side effect, no latency increase, no speed decrease, and even LuCI webui isn't sluggish, running stress-ng only brings the speed down to 8mbit.

Marctraider commented 4 years ago

I also tried most of those, but non can properly handle link loss without major rubberbanding. And TCP is even worse for general internet usage and gaming/voip.

Engarde beats all those solutions for stable connection ;-)

ale-rinaldi commented 4 years ago

Hi @talalmash , I'm really happy you're finding engarde useful, thanks for your feedback :)

Marctraider commented 2 years ago

Any update on this? Possible to somehow adjust code without a complete rewrite?

I wonder maybe if compiling it with more cpu specific optimizations could yield a few more megabits of throughput, but I never really compiled any GoLang stuff.

xavierleung commented 2 years ago

I am also curious if someone figure out any optimizations by now.

cjangrist commented 1 year ago

Is there a set of tests that can be run offline to triage and diagnose any CPU bottlenecking or throughput issues?

Llorx commented 1 year ago

I'm able to pull 25mbit/s (my internet limit) on 720mhz ar71xx Archer C7v2, will test over lan to see max, I simply compiled engarde-client with mips flag without any effort, works like a dream! Thank you dev!

My journey for usable internet from worse to best on unstable lines: Speedify on RPi -> OpenMPTCProuter(best of all for TCP only + aggregate) -> borrowed Peplink -> Glorytun UDP (bad with packet loss, even at 1% limiter) -> ExitLag -> Engarde (no aggregation), finally done :)

Edit: And yes it spikes 100% cpu, average 75 on full speed, but with no side effect, no latency increase, no speed decrease, and even LuCI webui isn't sluggish, running stress-ng only brings the speed down to 8mbit.

Hey! So Peplink is not that good?