Tomcat Profiling

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up tomcat profiling by attaching a Java agent or opening a JMX port. This lets your team read thread states, memory heap use, and CPU time in flight. Most teams grant full host shell access or open remote management ports to start a trace. Broad host roles let any engineer dump live memory or change server state without oversight. How to set up tomcat profiling A Java server runs inside a virtual machine that tracks every method call and object. To read this data, you attach a profili

Profiling: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You set up tomcat profiling by attaching a Java agent or opening a JMX port. This lets your team read thread states, memory heap use, and CPU time in flight. Most teams grant full host shell access or open remote management ports to start a trace. Broad host roles let any engineer dump live memory or change server state without oversight.

How to set up tomcat profiling

A Java server runs inside a virtual machine that tracks every method call and object. To read this data, you attach a profiling tool to the running server process. Teams do this in two main ways during a performance check. First, they can load a native agent when the server starts up. Second, they can connect on demand over the Java Management Extensions interface, known as JMX.

In the agent setup, the startup script loads a helper library into the process. The library watches CPU ticks, thread locks, and memory allocation events at a low level. It writes these metrics to a local dump file or streams them to a dashboard. When you use JMX instead, the server opens a network socket for management tools. An engineer connects a client tool to that port to sample threads or pull heap data.

Local tools can also attach to the process ID right on the host machine. In this flow, an engineer logs into the server over SSH first. They run a command line tool that talks to the local Java virtual machine socket. The tool captures a flame graph or a heap snapshot for a short window. Then the engineer copies that file back to their laptop to study the slow code paths.

What native profiling solves and what it leaves open

Native profiling tools show you why a Java web app runs slow or crashes. Thread dumps reveal which database calls or locks block your worker threads from finishing. Allocation traces show which methods create too many objects and trigger long garbage collection pauses. With this data, developers can fix memory leaks and speed up slow endpoints before users notice.

Still, the native setup creates a major security and audit gap in production. Both JMX ports and local attach tools rely on coarse host or role checks. Once a user logs into the host or JMX port, they hold full control. Native settings decide who can log in, not what commands they run in flight.

Profiling: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

A full heap dump contains every piece of data sitting in server memory right then. That snapshot holds active user sessions, plain text database keys, emails, phone numbers, and card numbers. An engineer who pulls a heap dump to fix a bug gets all that raw data. Native JMX roles also allow users to call management beans that stop threads or change app settings. Basic server logs rarely record which specific MBean method a user called during their session.

Managing production debugging sessions safely

To keep production safe, teams must separate code profiling from broad host and memory access. Start by turning off remote JMX ports on public or wide internal networks. Prefer low overhead sampling profilers that export only method names and CPU counts. Avoid full heap dumps in live systems unless no other option exists to find a leak.

When an engineer must run a live diagnostic check, scope their session to specific commands. Record every command executed on the host so you have a clear audit trail. If a command returns text output with emails or card numbers, mask those fields in results. This approach lets developers find slow code while keeping live customer data and server state safe.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Does tomcat profiling slow down a live production server?

Sampling profilers add very little load and are safe for live servers. Full method tracing and full heap dumps pause the server and can delay user traffic.

Why is a Java heap dump a data risk?

A heap dump copies all live memory to a file on disk. That file includes active requests, secrets, emails, phone numbers, and card numbers in clear text.

Should we leave the JMX port open on production hosts?

No, open JMX ports expose management beans that can run code or stop the app. Keep remote ports closed and use scoped, audited host sessions for local checks instead.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.