eran
eran

Reputation: 15136

limiting the network bandwidth of a java process

Is there an efficient way to limit the bandwidth of a certain java process?

I am familiar with solutions like trickle to limit bandwidth of a certain process on run time

sudo trickle -s -d 1024 /path/to/app.sh

But when dealing with java processes it makes it more of a challenge because the application initiates a JVM or in some cases a WRAPPER service that initiates a JVM - that means that solutions like 'trickle' will not work.

I can try and limit (using trickle) the whole java process (by wrapping / messing up with /usr/bin/java s.link) - UGLY. Does anyone know of a better solution for limiting the bandwidth of a java process (JVM)?

Thanks!

Upvotes: 9

Views: 3222

Answers (2)

MeIr
MeIr

Reputation: 7326

Unfortunately I don't think trickle can do it. I have similar issue and I solved it via throttling bandwidth on a particular port. For example you application opens port 34567 to communicate, then you can apply firewall setting and throttle it down.

On a mac I am using "ipfw", example:

sudo ipfw pipe 1 config bw 5KByte/s
sudo ipfw add 2 pipe 1 src-port 6666

On linux I am using "tc", examples & source: http://www.cyberciti.biz/faq/linux-traffic-shaping-using-tc-to-control-http-traffic/

As a final solution, you can create bash script that monitors processes and picks ones you need and throws port throttling on it.

Upvotes: 3

JeanValjean
JeanValjean

Reputation: 17713

The question is not really clear. Do you have control of the Java code? Otherwise, are you the System Administator?

If you are using a Java code you could use the Socket paradigm and then limit each socket connection by using the following method: setPerformancePreferences(int connectionTime, int latency, int bandwidth). In the other case, the bandwidth limitation capability depends by the OS and the way the Java applications are executed.

Upvotes: 0

Related Questions