Say I start Tomcat in debug mode but have not attached to it from an IDE via remote debugging. Will my application run at same speed as if it would have been started normally or will it impact the speed and performance. If it does then how much?
Debug mode is really very convenient when it comes to fixing issues without Tomcat restart. Is it bad idea to run Tomcat in debug mode in production?
"Debug mode" means that the JVM runs with jdwp
agent.
JDWP agent enables most of JVM TI capabilities. Some of them are harmless, but some do have performance impact in HotSpot JVM.
In particular, can_access_local_variables
capability turns off Escape Analysis completely. This means, certain JIT optimizations (e.g. allocation elimination) will not work.
Other capabilities, like can_generate_method_entry_events
, can_generate_field_access_events
, can_pop_frame
etc., add extra checks in the interpreter.
Note that the presence of jdwp agent alone implies the above overhead, even if debugging session is not active. The performance overhead is often negligible, but sometimes the lack of Escape Analysis can increase the allocation pressure and slow down an application by 5-10%.
Also, applications having too many classes may badly suffer from jdwp
agent. Sometimes an application may even hang, like in this question. See bug JDK-8227269 for details.
The agent handles class loading/unloading events even when debugger is not attached, so again, only the presence of the agent may already cause problems.
In short, I wouldn't recommend enabling debug mode in production environment. Although it often works just fine, I saw jdwp related problems many times, including performance overhead, freezes and native memory leaks.