Generate a Thread Dump Externally
If Stash stops responding or is showing poor performance, providing thread dumps to Support can help diagnose the problem.
If you were asked by Atlassian technical support to create thread dumps please take six thread dumps – one every 10 seconds for one minute – so we can identify patterns. Attach all generated files to the support ticket in addition to a Support Zip (the Support Zip will contain catalina.out
).
Generating a Thread Dump for Windows
Method 1 - Windows scripts
We now have scripts for generating thread dumps externally on Windows. Download them from this Bitbucket Repository.
Method 2 - CTRL+BREAK (only if Stash is running in a console window)
- In the Command Console window where Stash is running, open the properties dialog box by right clicking on the title bar and select "Properties".
- [Layout] タブを選択します。
- Under Screen Buffer Size, set the Height to 3000.
- [OK] をクリックします。
- 開いているコマンド コンソール上で、CTRL-BREAK を押すと、コマンド コンソールにスレッド ダンプが出力されます。
- "Full thread dump" と書かれた行まで、コマンド コンソールをスクロールします。
- タイトルバーを右クリックし、編集 ->マークを選択します。スレッドダンプのテキスト全体をハイライト表示します。
- Right click the title bar and select Edit -> Copy. The thread dump can then be pasted into a text file.
Method 3 - jstack:
JDK と jstack ツールが合体して、スレッドダンプを発生します。
- Identify the process. Launch the task manager by, pressing
Ctrl + Shift + Esc
and find the Process ID of the Java (JIRA) process. You may need to add the PID column usingView
->Select Columns ...
- jstack <pid> を実行して、 単一のスレッドダンプを取得します。このコマンドで、プロセス ID <pid> の1個のスレッドダンプが取得出来ます。この場合のプロセス ID は22668です。
- Identify the process. Launch the task manager by, pressing
C:\Users\Administrator>jstack.exe -l 22668 > threaddump.txt
このコマンドにより、現在のディレクトリに threaddump.txt
というファイルが出力されます。
jstack のよくある問題
- You must run jstack as the same user that is running Stash.
- エラー メッセージ "Not enough storage is available to process this command" が表示された場合、ここから "psexec" ユーティリティをダウンロードして、以下のコマンドを実行します。
psexec -s jstack <pid> >> threaddumps.txt
- 実行が可能な jstack が $PATH にない場合、<JDK_HOME>/bin ディレクトリで探します。
java.lang.NoClassDefFoundError: sun/tools/jstack/JStack
が発生したら、JDK の lib ディレクトリ tools.jar があるかどうかを確認します。tools.jar がない場合、JDK のフル バージョンをダウンロードします。
Method 4 - VisualVM:
VisualVM is only provided with the JDK distribution so you must have this installed regardless of the scenario describing your environment below. You don't have to change the Java version used by the application to use VisualVM but you will have to add JMX parameters if this is the case or if you are running Stash as a service.
Scenario 1: If Stash is using the JDK and Stash is running as a console application:
- Start VisualVM:
<JDK installation directory>\bin\jvisualvm.exe
- Select the
tomcat
process in the left-hand pane under "Local". - Select the "Threads" tab in the right pane.
Click the button "Thread Dump" (and then select the "Threads" tab to get back to the button).
- Start VisualVM:
Scenario 2: If Stash is not using the JDK and Stash is running as a console application:
- Stop Stash.
Edit the
<Stash installation directory
>\bin\
setenv.bat
and add the following JMX parameters to those already defined for theJVM_SUPPORT_RECOMMENDED_ARGS
property. You must choose a free port for JMX to bind to – the following example uses port 7995:rem rem Occasionally Atlassian Support may recommend that you set some specific JVM arguments. You can use this variable rem below to do that. rem set JVM_SUPPORT_RECOMMENDED_ARGS=-Dcom.sun.management.jmxremote.port=7995 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
- Restart Stash.
- Start VisualVM:
<JDK installation directory>\bin\jvisualvm.exe
- Select "File" > "Add JMX Connection".
- Type: localhost:7995
- Select the
tomcat
process in the left-hand pane under "Local". - Select the "Threads" tab in the right pane.
Click the button "Thread Dump" (and then select the "Threads" tab to get back to the button).
Scenario 3: If Stash is running as a service:
- Stop Stash.
Edit the existing service – the default service name is
AtlassianStash
:<Stash installation directory>\bin\tomcat8w.exe //ES//AtlassianStash
and add the JMX parameters to the service configuration on the "Java" tab under "Java Options" in addition to what is already there and apply the changes. You must choose a free port for JMX to bind to – the following example uses port 7995:-Dcom.sun.management.jmxremote.port=7995 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
Restart Stash.
- Start VisualVM:
<JDK installation directory>\bin\jvisualvm.exe
- Select "File" > "Add JMX Connection".
- Type: localhost:7995
- Select the
tomcat
process in the left-hand pane under "Local". - Select the "Threads" tab in the right pane.
Click the button "Thread Dump" (and then select the "Threads" tab to get back to the button).
Generating a Thread Dump on Linux, including Solaris and other Unixes
Method 1 - jstack:
Sun JDK 1.5 and above ship with native tool called jstack
to perform thread dump.
- Find the process ID of Stash the JVM using the ps command:
STASH_PID=`ps aux | grep -i stash | grep -i java | awk -F '[ ]*' '{print $2}'`;
- Then run the following command 6 times with a 10 second interval.
top -b -H -p $STASH_PID -n 1 > stash_cpu_usage.`date +%s`.txt; jstack $STASH_PID > stash_threads.`date +%s`.txt
Look in the resulting cpu usage files to identify which threads are consistently using a lot of CPU time.
- Take the PID of the top 10 threads which are using CPU time and convert them to Hexadecimal. Eg: 11159 becomes 0x2b97
- Search up the Hex values in the thread dumps to figure out which threads are using up all the CPU
Method 2 - kill signal:
An alternative to the method above is:
- Find the process ID of Stash the JVM using the ps command:
- Find the process ID of Stash the JVM using the ps command:
ps aux | grep -i stash | grep -i java | awk -F '[ ]*' '{print $2}'
- Then run the following command 6 times with a 10 second interval:
- Then run the following command 6 times with a 10 second interval:
kill -3 <pid>
Note: This will not kill your server (so long as you included the "-3" option, no space in between).
The thread dump will be printed to Stash's standard output (catalina.out).
If you have trouble generating the thread dumps with this method, then use the method "Generating a Thread dump for Windows" as they can also apply for linux, etc.
The preferred method is the first one as we can cross-check running processes and threads.
Thread Dump Tools for analyzing the data
- Samurai
- Thread Dump Analyzer TDA TDA 1.0 Final can be obtained from the
java.net