9

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!

Ofir Farchy
  • 6,501
  • 7
  • 35
  • 58
eran
  • 12,534
  • 28
  • 87
  • 133
  • 2
    Check if this is of any use http://stackoverflow.com/questions/3246345/making-a-reliable-web-service-unreliable-but-in-a-controlled-way/3247133#3247133 – Kennet Apr 16 '12 at 15:33

2 Answers2

3

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.

MeIr
  • 7,044
  • 6
  • 40
  • 70
0

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.

JeanValjean
  • 15,832
  • 22
  • 103
  • 145