9

I wonder how large the performance overhead that the -Xdebug flag introduces?

It's very convenient to debug production applications, but I guess it is expensive to leave running all the time?

Also, is there a good way to make the already running application to listen via Debug port, without re-launching it?

Thanks.

SyBer
  • 5,407
  • 13
  • 55
  • 64

3 Answers3

5

We haven't found any difference. We run all our production applications with -Xdebug.

is there a good way to add Debug mode to application already running, without re-launch it

It is what -Xdebug does. Debugger actually starts when someone connects to debugging port.

stepancheg
  • 4,262
  • 2
  • 33
  • 38
  • I meant, if there is a way to make application listen on debug port without restarting it with -Xdebug flag? – SyBer Jan 18 '11 at 09:21
  • No. Just always run application with open debug port. – stepancheg Jan 22 '11 at 20:24
  • Hi stepancheg, it seems you have experience with connecting jdb to a running process..would you be able to answer my question here...http://stackoverflow.com/questions/28528325/attach-jdb-on-uncaught-exception Thanks. – nave Feb 19 '15 at 02:15
4

Under Java 6 I would say the cost is about 15% to performance, Under Java 5.0 it was about 40%. This may be fine for you.

Another way to see what is going on in production is to use JMX/JConsole. This takes some work and has a relatively small over head. I guess at 2%.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Does JMX allow peeking at variables? – SyBer Jan 18 '11 at 09:24
  • 1
    @SyBer, not in the same way as the dbeugger does. You can create MXBeans which expose a component's fields, for view/change/graphing, and its methods but I suggest you use a framework to do this, even if you have to write your own. – Peter Lawrey Jan 18 '11 at 09:58
4

Depends what your code is doing. If you've got a network-based, database driven application the difference will probably be negligable since the bottleneck probably isn't how fast the JVM can execute instructions. If all your code does is perform scientific computations in-memory, then you can expect a non-trivial hit.

Edit

When I wrote this I thought the debugger itself was being attached. Simply running it with -Xdebug won't in itself impact performance as @stepancheg has noted. However my main motivation wasn't as much to give a technical analysis but rather to say that even if you cause bytecode to take longer to execute it probably won't matter much in a typical Java application since the processors wouldn't be under heavy enough utilization for that to be the determining performance factor. Most apps with a long lifetime are server apps, and the performance of many (if not most) server apps are bounded by I/O limitations.

Mark Peters
  • 80,126
  • 17
  • 159
  • 190
  • So the debug is mostly CPU and memory bound? – SyBer Jan 18 '11 at 09:22
  • 1
    Mark, you are wrong. Enabled debugger does not affect performance at all unless you are connected to the application. Even for scientific application. Thanks to JIT. – stepancheg Jan 22 '11 at 20:24