Glassfish Tuning and Thread Dumps

Once you get into a production like stage with more data volume, more users, etc. you will find yourself pretty fast in the situation where Glassfish gets some hickups or slowness. An expected situation if you did not change the default parameters  out of the box which are chosen to make Glassfish to run even on a small box.

We ran into some kind of concurrency problems with JDBC pools and thread where Glassfish appeared to be hanging. One approach is to create thread dumps for the JVM.
With Glassfish we have a few options:

  1. jstack
    Run jps which returns you the list of applications running a JVM, choose the PID and execute
    jstack <PID>
    or jstack -F <PID> > td.log
  2. asadmin
    Go the Glassfish_HOME/bin folder and execute
    ./asadmin --user admin generate-jvm-report --type=thread > threaddump.txt
  3. kill -3 <PID>
    Supposed to create a dump in the default log folder of Glassfish. Doesnt work for me.

With the (or better more than 1) file at hand you can evaluate them by hand or use some of the tools around. I am still struggling to make the tool analyzing my dumps. They simply open the files like a editor.

tda tool

tda tool

Some References

Monitoring Glassfish V3.1.2 Options

There are 2 crucial phases you want to look under the hood of your running Glassfish or inside the JVM underneath: Performance Tuning and Health Monitoring during production.

With JMX (Java Management Extensions, Wikipedia) at hand, there are a few options to choose from.

JConsonsole

The graphical monitoring tool is great for local deployment, it allows you to connect to a JVM on the same host or a remote host. It creates line graphs for your for all relevant from the moment you connect, it is perfect to observe a server while you do some testing or other actions, though it does not record any values while you are not connected. I have a hard time to get it running on a remote server and I do not favour the ‘open’ approach (see previous blog entry) which allows anyone to access the JVM with the disabled authentication settings. I also had situations where the JVM was frozen and it was no longer possible to access the JVM for monitoring, here I would rather have snapshots before the problem started together with server.log.

JConsole

JConsole

Glassfish Rest Interface

Note: You need to enable the areas you want to monitor with the admin console (or the asadmin command line) because per default all are OFF. Continue reading

Glassfish and https running secure applications

By default Glassfish listens to http on port 8080 and https on port 8181.
It is better to listen to the default ports 80 for http and 443 for https, usually you dont want the user to enter port numbers as part of the URL.

Even the Glassfish Admin Console allows to change the ports (Configurations/Server Config/Network Config/Network Listener), certain server OS such as Ubuntu do not allow non-root users (you should run Glassfish as separate user !) to ports below 1024. We can achieve this by port rerouting with the iptables command (under Ubuntu)


iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 8181
iptables-save -c > /etc/iptables.rules
iptables-restore < /etc/iptables.rules

vi /etc/network/if-pre-up.d/iptablesload
#!/bin/sh
iptables-restore < /etc/iptables.rules
exit 0

Additionally you can get a proper SSL certificate to stop annoying the user with a no proper certificate warning. See previous tutorial here.

SSL Error

SSL Error (Chrome)

If you operate an enterprise application with a known URL to the users, unlike a regular website where the portal should be reached with regular http, I would completely disable regular http.

Disable http

Disable http

Glassfish V3.1.2 and SSL

After almost 3 years (see previous post) I revisit the topic this time using the latest version og Glassfish 3.1.2 and GoDaddy as certificate provider. I created a certificate for a sub-domain (sub.whateverdomain.com) this time and make use of the extremly cheap 5.99 U$/year offer (no wildcard included)

Let me summarize the key steps here: Continue reading

Netbeans and JBoss 7

As much I like to use Glassfish, customers might have different taste or policy. We are challenged now to run our EJB/Web-application on JBoss as well. Netbeans supports JBoss up to version 6 but not the latest version 7 which is fully EE6 web profile compatible. Version 7 is not (yet) supported due to major revamp of the management API of JBoss. I found one plugin provided by Oleg Kulikov on github, a working prototype that can control Jboss 7 server from Netbeans, but cannot deply an application to it or debug it. I wish I know more about Netbeans RCP development, but it is not an easy task to create this kind of highly integrated NB plugin.
Discussion as Netbeans issue here.

JBoss Plugin

JBoss Plugin

Remote Glassfish V3.1 and the mystical JMX settings

Once you have any serious sized application running on Glassfish, you need to profile and tune your server settings. A good tool to look under the hood of a running Glassfish is to to connect jconsole (part of JDK) to its JVM. This works without problem for a local Glassfish but when it comes to a remote instance you cant connect to the default Glassfish setup.

Lets look at the default setup

Glassfish Admin Console

Continue reading

Glassfish V3.1 running embedded ActiveMQ for JMS (Part 3)

In the third and final part of this tutorial we will crate a MDB (Message Driven Bean) that listens to our embedded ActiveMQ from Part 1.

Pre-Requirements:

Tutorial:

Glassfish V3.1 running embedded ActiveMQ for JMS (Part 1)

Updates 2012-10-18

I am quite OK with the build-in JMS in Glassfish (OpenMQ), as long you dont want to access queues from external applications or you need an admin console to easily create, delete queues, send messages and browse the queues. ActiveMQ is a good alternative. Unfortunately we could  not find any end2end description hot to get the couple Glassfish-ActiveMQ up and running (under Linux, Windows should be a quite similar affair).

This tutorial describes how to install and configure ActiveMQ as embedded JMS broker, and connect a MDB to it.

Pre-Requirements:

  • Running Glassfish 3.1 instance (or later).

Tutorial