find which thread is consuming CPU in a Java process

Identifying the thread

You can identify which thread is consuming CPU in a Java process as follows:

  1. Determine the process ID (PID) of the affected server process using the following command: $ jps -v
  2. Determine which thread in the PID identified in step 1 is consuming the CPU:
    • On Unix® and Linux® systems, you can use the top command: $ top -n 1 -H -p [pid]replacing [pid] with the process ID of the affected process.
    • On Solaris®, you can use the prstat command: $ prstat -L -p [pid]replacing [pid] with the process ID of the affected process.
    • On Microsoft® Windows®, you can use the Process Monitor.

These commands all give an output listing all the threads in the selected process along with various details, including the CPU usage percentage. For example, the top command gives an output similar to this:Tasks: 152 total, 0 running, 152 sleeping,   0 stopped,   0 zombie  Cpu(s):  2.0%us,  1.4%sy,  0.0%ni, 94.7%id,  0.8%wa,  0.0%hi,  1.1%si,  0.0%st  Mem:   5008484k total,  4854428k used,   154056k free,    85624k buffers  Swap:  5013496k total,     6516k used,  5006980k free,  3393948k cached PID  USER     PR  NI  VIRT  RES  SHR S  %CPU  %MEM   TIME+  COMMAND               8706 user.1   20   0 2433m 561m  10m R  32.0  11.5  0:35.45 java 8624 user.1   20   0 2433m 561m  10m S   0.0  11.5  0:00.01 java                  8625 user.1   20   0 2433m 561m  10m S   0.0  11.5  0:10.12 java                  8626 user.1   20   0 2433m 561m  10m S   0.0  11.5  0:35.60 java                  8627 user.1   20   0 2433m 561m  10m S   0.0  11.5  0:00.01 java                  8628 user.1   20   0 2433m 561m  10m S   0.0  11.5  0:00.02 java 

In this example, we can see that thread ID 8706 is consuming 32% of the CPU.

  1. Produce a stack trace for the PID identified in step 1 using one of the following commands:
    • jstack command: $ jstack [PID] > jstack-output.txt
    • kill -3 command (Unix® and Linux® systems only), which consistently produces better results: $ kill -3 [pid]The kill -3 command outputs the stack trace to the log file where the standard output is directed (typically the error log file). The kill -3 command does not stop the running process; it will continue to run after outputting the stack trace.
  2. Convert the thread ID identified as problematic in step 2 to a hex value. In our example output, the thread ID decimal value 8706 converts to hex value 2202.
  3. Search the stack trace output for this hex value using grep. You are looking for a thread nid that matches this hex value: $ cat jstack-output.txt | grep -i 2202This command gives an output similar to this: "Concurrent Mark-Sweep GC Thread" prio=10 tid=0x00007f1448029800 nid=0x2202 runnableIn this example, we can see that the problem is a Garbage Collector (GC) thread, which suggests that GC is not properly tuned.

selfsigned certificates and selfsigned CA root certificate

Option 1 (setting up your own CA) is preferable when you need multiple certificates. In a company you might set up your own CA and install that CA's certificate in the root keystore of all clients. Those clients will then accept all certificates signed by your CA.

Option 2 (self-signing a certificate without a CA) is easier. If you just need a single certificate, then this is sufficient. Install it in the keystores of your clients and you are done. But when you need a second certificate, you need to install that again on all clients.

 Self-signing is the simpler route to take, but making one's own CA allows the signing of multiple server certificates using the same CA and involves only a few extra steps. 


https://web.archive.org/web/20160403100211/https://metabrot.rocho.org/jan/selfsign.html

zfs tunables SSD

 ####

# ZFS tuning

# https://www.svennd.be/tuning-of-zfs-module/

###

echo > /etc/modprobe.d/zfs.conf

echo -e "\

# ---------------- BEGIN ----------------  \r

# ZFS tuning for SAS3 ALL SSD + nVME Storage Tank \r

# total arc size limited to 90% of free -m - factor is 1024  \r

# zfs_arc_max={{ '%d' | format(memtotal_mb*1024*1024*0.9) }} \r

options zfs zfs_arc_min=262144000000 \r

options zfs zfs_arc_max=283115520000 \r

options zfs zfs_compressed_arc_enabled=0 \r

###\r

# txg timeout \r

options zfs zfs_txg_timeout=5 \r

###\r

# disable prefetch \r

options zfs zfs_prefetch_disable=1 \r

###\r

# tune l2arc \r

# max write speed to l2arc \r

# default : 8 * 1024 * 1024 \r

# setting here : 500 * 1024 * 1024 \r

options zfs l2arc_write_max=524288000 \r

options zfs l2arc_write_boost=524288000 \r

options zfs l2arc_noprefetch=0 \r

options zfs l2arc_headroom=24 \r

###\r

# dirty pages \r

options zfs zfs_dirty_data_max_percent=40 \r

###\r

# sync zfs_vdev_* \r

# increase them so scrub/resilver is more quickly at the cost of other work \r

options zfs zfs_vdev_scrub_min_active=24 \r

options zfs zfs_vdev_scrub_max_active=64 \r

# sync write \r

options zfs zfs_vdev_sync_write_min_active=8 \r

options zfs zfs_vdev_sync_write_max_active=32 \r

# sync reads (normal) \r

options zfs zfs_vdev_sync_read_min_active=8 \r

options zfs zfs_vdev_sync_read_max_active=32 \r

# async reads : prefetcher \r

options zfs zfs_vdev_async_read_min_active=8 \r

options zfs zfs_vdev_async_read_max_active=32 \r

# async write : bulk writes \r

options zfs zfs_vdev_async_write_min_active=8 \r

options zfs zfs_vdev_async_write_max_active=32 \r

###\r

# scrub \r

options zfs zfs_top_maxinflight=320 \r

options zfs zfs_resilver_delay=0 \r

options zfs zfs_scrub_delay=0 \r

options zfs zfs_resilver_min_time_ms=5000 \r

###\r

# scheduler \r

options zfs zfs_vdev_scheduler=deadline \r

###\r

# cpu limits \r

options zfs zio_taskq_batch_pct=85 \r

options zfs zfs_sync_taskq_batch_pct=85 \r

###\r

# history \r

options zfs zfs_read_history=100 \r

options zfs zfs_read_history_hits=100 \r

options zfs zfs_txg_history=10 \r

###\r

# other tuning\r

options zfs zfs_nocacheflush=1 \r

###\r

# --------------- END ------------------" \

> /etc/modprobe.d/zfs.conf

cat /etc/modprobe.d/zfs.conf

/sbin/modprobe zfs


cat /proc/spl/kstat/zfs/arcstats

zfs tunable SAS

zfs tunables


####

# ZFS tuning

###

echo > /etc/modprobe.d/zfs.conf

echo -e "\

# ---------------- BEGIN ----------------  \r

# ZFS tuning for SAS3 12GE Storage Tank \r

# tank-a  Total Memory: 327680 MB

# tank-b  Total Memory: 393216 MB

# total arc size limited to 90% of free -m - factor is 1024  \r

# zfs_arc_max={{ '%d' | format(memtotal_mb*1024*1024*0.9) }} \r

options zfs zfs_arc_min=262144000000 \r

options zfs zfs_arc_max=314572800000 \r

options zfs zfs_compressed_arc_enabled=0 \r

###\r

# txg timeout \r

options zfs zfs_txg_timeout=5 \r

###\r

# disable prefetch \r

options zfs zfs_prefetch_disable=1 \r

###\r

# tune l2arc \r

# max write speed to l2arc \r

# default : 8 * 1024 * 1024 \r

# setting here : 500 * 1024 * 1024 \r

options zfs l2arc_write_max=524288000 \r

options zfs l2arc_write_boost=524288000 \r

options zfs l2arc_noprefetch=0 \r

options zfs l2arc_headroom=24 \r

###\r

# dirty pages \r

options zfs zfs_dirty_data_max_percent=40 \r

###\r

# sync zfs_vdev_* \r

# increase them so scrub/resilver is more quickly at the cost of other work \r

options zfs zfs_vdev_scrub_min_active=24 \r

options zfs zfs_vdev_scrub_max_active=64 \r

# sync write \r

options zfs zfs_vdev_sync_write_min_active=8 \r

options zfs zfs_vdev_sync_write_max_active=32 \r

# sync reads (normal) \r

options zfs zfs_vdev_sync_read_min_active=8 \r

options zfs zfs_vdev_sync_read_max_active=32 \r

# async reads : prefetcher \r

options zfs zfs_vdev_async_read_min_active=8 \r

options zfs zfs_vdev_async_read_max_active=32 \r

# async write : bulk writes \r

options zfs zfs_vdev_async_write_min_active=8 \r

options zfs zfs_vdev_async_write_max_active=32 \r

###\r

# scrub \r

options zfs zfs_top_maxinflight=320 \r

options zfs zfs_resilver_delay=0 \r

options zfs zfs_scrub_delay=0 \r

options zfs zfs_resilver_min_time_ms=5000 \r

###\r

# scheduler \r

options zfs zfs_vdev_scheduler=deadline \r

###\r

# cpu limits \r

options zfs zio_taskq_batch_pct=85 \r

options zfs zfs_sync_taskq_batch_pct=85 \r

###\r

# history \r

options zfs zfs_read_history=100 \r

options zfs zfs_read_history_hits=100 \r

options zfs zfs_txg_history=10 \r

###\r

# other tuning\r

options zfs zfs_nocacheflush=1 \r

###\r

# --------------- END ------------------" \

> /etc/modprobe.d/zfs.conf

cat /etc/modprobe.d/zfs.conf

/sbin/modprobe zfs


cat /proc/spl/kstat/zfs/arcstats