Questions ‘n’ Answers – Technology

Just another WordPress.com weblog

Archive for the ‘Java’ Category

What are good Java Profiling Tools?

Posted by qnaguru on September 17, 2009

Java Profiling Tools included in JDK:

Visual VM – <JDK_HOME>\bin\jvisualvm.exe

This is a very good visual tool, that automatically connects to all local java processes and provides details on them.

JConsole – <JDK_HOME>\bin\jconsole.exe

This is very similar to Visual VM.

JStat - <JDK_HOME>\bin\jstat.exe

This is Java Virtual Machine statistics monitoring tool. You need to know jvmid of the java vm to use it.

JHat – <JDK_HOME>\bin\jhat.exe

This is a Java Heap Analysis Tool.

Other Java Profiling Tools:

StackProbe Profiler

http://www.stackprobe.com/

JRockit Mission Control

http://www.oracle.com/technology/products/jrockit/missioncontrol/index.html

Eclipse Memory Analyzer Tool

http://www.eclipse.org/mat/

YourKit Java Profiler

http://www.yourkit.com/

Posted in Java, Performance, Uncategorized | Tagged: , , , | Leave a Comment »

How can we get a thread dump of running java process

Posted by qnaguru on September 3, 2009

First find out java processes:

# jps
19420 MyServer
19843 Jps
8259 Bootstrap

Then using that process id, run jstack to get a thread dump:

# jstack 19420

NOTE: jps and jstack are JDK tools.

Another way to get a thread dump would be to use:

# kill -3 19420

Posted in Java, Performance, Uncategorized | Leave a Comment »

How can i monitor and improve performance of my Apache/Tomcat/MySQL application?

Posted by qnaguru on October 30, 2008

Monitor Apache

You can view status of your Apache Web Server by going to a URL of the kind:

This allows us to view status of Apache by going to a URL like:
If the above URL does not work, your apache is probably not configured to return status. For information on how to set it up for this, see Apache Mod Status.

To view the JK Status, go to a URL of the kind:

http://host/jk-status

Monitor-Tomcat

You can view a lot of useful statistics of Tomcat by looking at its Admin Console:

http://<IP:port>/ > click on status link.

Things to look for here are under the approriate headings JVM, jk-8009 (assuming apache is configured to connect via jk on port 8009), http-8080.

JVM

Free Memory – Not sure how this works.

Total Memory – Not sure how this works.

Maximum Memory – this is the maximum amount of memory available to tomcat server, it is the value of the -mx setting in your tomcat startup java command (in catalina.sh). If no mx setting is done, a default value is assumed (which is different for windows and linux)

 

jk-8009 or http-8080

Here the important things to look at are:

Max threads: 200 Current thread count: 28 Current thread busy: 8
Request count: 19 Error count: 0

Max threads – this is maximum number of threads that tomcat can have to process incoming requests (and its internal functions).

Current thread count – this is total number of threads in tomcat’s threadpool at present. Threads will get garbage collected from this pool. And the pool size can grow to ‘Max threads’ size when necessary.

Currrent thread busy – this is total number of threads that are processing variour requests at present.

Request count – total number of http requests received by tomcat since the time it was started.

Improve -Tomcat

You have a performance problem in tomcat when:

Current Thread Count is near about Max Threads. This is a clear indicator that tomcat is receiving more requests faster than it can handle. The default Max Thread setting is 200 which is good enough for most applications, but you can change it here in <TOMCAT_HOME>/conf/server.xml – look for your connector element, here you can change (or add if not present) maxThreads attribute. See http://tomcat.apache.org/tomcat-5.5-doc/config/http.html . But beware, you cannot increase this value indiscrimnately(will affect memory and performance both), the optimum value is based on your hardware, and primarily the number of CPUs you have (more the better for increasing maxThreads). Thumb Rule: Do not change defaults, unless you really have to.

You see Out of Memory Exceptions in your catalina log. See the <TOMCAT_HOME>\logs\catalina.out log file. This is a clear indicator that your application needs more memory than what is available. The min,max memory available can be changed here: <TOMCAT_HOME>\bin\catalina.sh or .bat.  You can add a entry like this somewhere  (A good place would be immediately before this line: # Set juli LogManager if it is present)

(on linux): JAVA_OPTS=”$JAVA_OPTS -ms256M -mx512M”

(on windows): set JAVA_OPTS=-ms256M -mx512M

Monitor MySQL

You can check lots of important mysql params by going to mysql prompt and typing as follows:

mysql> SHOW VARIABLES;

One of things of interest in the response would be: max_connections. This will tell you how many max concurrent connections are allowed.

You can also find out how many concurrent MySQL connections exist at any point in time by using following command:

mysql> show processlist;
The number of rows in the response is equal to number of connections to MySQL at that time.

Improve MySQL

The most important thing you need to find out is if you are running out of db connections. This you can find out by using the above mentioned commands i.e show processlist shows equal number of connections as max_connections. If this happens you need to increase the max_connections.. HOW?

Ofcourse check the usual things in your db connection pool, you pool size cannot be greater than max_connection value ofcourse.

How to see Log of DB Queries being executed?

How to find how much time is being spent in execution of each query?

How to find the amount of data(bytes) being returned by each query?

Posted in Apache, Deployment, Java, MySQL, Performance, Tomcat, Uncategorized | Tagged: , , , | Leave a Comment »

Why am i not able to connect to DB2 from java on linux?

Posted by qnaguru on August 14, 2008

This may happen because you do not have the right environment variables set up on linux machine. The best pointer to this is that, when you are logged in as db2 unix user (note that in db2 database user is also an operating system user) you are able to connect to the database, but when you are logged in as some other user, it fails.

The environment variables that you need to set are:

export DB2DIR=/opt/ibmapps/db2/V9.0
export DB2INSTANCE=mydb2inst
export LD_LIBRARY_PATH=/home/mydb2inst/sqllib/lib32
export LOGNAME=mydb2inst
export PATH=/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:

/usr/sbin:/usr/bin:/root/bin:/usr/local/JDK1.5.0_12/bin:/home/mydb2inst/sqllib/bin:

/home/mydb2inst/sqllib/adm:/home/mydb2inst/sqllib/misc

 

You can see that these environment variables do exist when you login as the db2 unix user. This you can see by typing:

$ set

Posted in DB2, Java, Linux | Tagged: , , | Leave a Comment »