Question

I want to write the application (daemon) what synchronizes files and runs in background. And i want to use only a part of bandwidth (better in percents, but fixed limit is acceptable) because full access to bandwidth will interfere user's applications. How can i do it programmaticaly? ipfw affects any application (and i want limit only my app) and in apple manual page it is deprecated. And i use https port, so i cant just throttle connection to that port. Are there any other solutions? Thank you.

Was it helpful?

Solution

It's not clear if this is a case where you know what the target bandwidth is, or if this is a case where you don't know.

If you know that the available bandwidth is 100KB/s then the simplest (and probably best) thing to do is in your application do the math and meter the amount you are reading and writing to the socket. That is run counters of amount read and time passed and enforce sleeps in your loops to ensure that you achieve those limits in aggregate.

If you don't know what the target is, (and I don't really know how you could, given that all environments are different) then it gets a bit more complex. Most applications simply provide a way for the user to pick a bandwidth ceiling for the app. This is the only portable way.

For OS X-only apps you can rely on specific additional features, but OS X has transitioned across firewall implementations across versions, and they are not application-aware firewalls. Therefore, if you want to use their functionality to throttle your application you'll have to set rules based on host and/or port that are likely to only match your application.

There are more esoteric actions you could take implementing NETBLT as your communications protocol instead of plain TCP to indicate your traffic is "bulk" or large and latency insensitive. But most applications just give the user control.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top