How to Estimate Object Memory Allocation in Java

Estimating Allocated Memory (Not Object Size)

Previously, I explained how to calculate an object's size considering OS binary or types of objects and primitives. In this article, I'll only review ways to estimate the size of already allocated memory for a given object. There are a couple of ways to do it. Here we review the most popular.

Estimating Memory Using Profiler

The easiest way to estimate the memory of some objects is to look right inside JVM's memory using a profiler such as Visual VM

Fantastic Symbols and Where to Find Them (Part 2)

In the first blog post, we learned about the fantastic symbols (debug symbols), how the symbolization process works, and lastly, how to find the symbolic names of addresses in a compiled binary.

The actual location of the symbolic information depends on the programming language implementation the program is written in. We can categorize the programming language implementations into three groups: compiled languages (with or without a runtime), interpreted languages, and JIT-compiled languages.

Continuous Profiling in Kubernetes Using Pyroscope

Developers typically need to look at performance bottlenecks in production applications to determine the cause of the problem. To do this, you usually need information that can be collected through logs and code tools. Unfortunately, this approach is usually time-consuming and does not provide enough details about the underlying problem.

A modern and more advanced approach is to apply and use profiling techniques and tools that highlight the slowest application code, that is, the area consuming most of your resources.

Monitoring and Profiling Your Spring Boot Application

Monitor and profile your Spring Boot application!
You may also like: Monitoring Using Spring Boot 2.0, Prometheus, and Grafana (Part 1 — REST API)

Monitoring is very essential for modern applications, modern applications are highly distributed in nature and have different dependencies like database, service, caching and many more. It’s more of a like service mesh, tracing and monitoring these services are very essential to adhere to SLA (Service Level Agreement). SLA is an agreement between client and server, It accounts for reliability, responsiveness and other service-level metrics.

We always tend not to violate any SLAs, violating any part of the SLA can have many consequences. If a service fails to meet the terms defined in an SLA, it risks brand reputation damage and revenue losses. Worst of all, a company may lose a customer to a competitor due to its inability to meet a customer’s service-level requirements.

Profiling With JVisualVM

A few days back, I faced an issue on one of the Java service-hosted servers. The server load, resource consumption, and response time of service were too high.

Everyone was under the impression that the latest deployment of the JAR caused this issue, whereas the service code and performance on the local machine looked fine.