A Simple Guide to Heaps, Stacks, References, and Values in JavaScript

A common concept in software engineering, in general, is the idea of reference versus value. JavaScript has an interesting way of storing variables, objects, and functions, and misunderstanding this can lead to confusion further down the road. Developers need to know how these concepts work since it is fundamental to JavaScript. This article will cover how JavaScript manages values and references, which will pay dividends when working on complicated applications and websites.

Memory Storage in JavaScript

To understand what we mean when we say JavaScript stores values and references, we need to understand where JavaScript stores them. There are two places JavaScript stores this data:

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

Dive Deep Into Resource Requests and Limits in Kubernetes

As you create resources in a Kubernetes cluster, you may have encountered the following scenarios:

  1. No CPU requests or low CPU requests specified for workloads, which means more Pods “seem” to be able to work on the same node. During traffic bursts, your CPU is maxed out with a longer delay while some of your machines may have a CPU soft lockup.
  2. Likewise, no memory requests or low memory requests specified for workloads. Some Pods, especially those running Java business apps, will keep restarting while they can actually run normally in local tests.
  3. In a Kubernetes cluster, workloads are usually not scheduled evenly across nodes. In most cases, in particular, memory resources are unevenly distributed, which means some nodes can see much higher memory utilization than other nodes. As the de facto standard in container orchestration, Kubernetes should have an effective scheduler that ensures the even distribution of resources. But, is it really the case?

Generally, cluster administrators can do nothing but restart the cluster if the above issues happen amid traffic bursts when all of your machines hang and SSH login fails. In this article, we will dive deep into Kubernetes requests and limits by analyzing possible issues and discussing the best practices for them. If you are also interested in the underlying mechanism, you can also find the analysis from the perspective of source code. Hopefully, this article will be helpful for you to understand how Kubernetes requests and limits work, and why they can work in the expected way.

Easy and Fast Adjustment of Kubernetes CPU and Memory

Assigning and managing CPU and memory resources in the Kubernetes can be tricky and easy at the same time. Having done this task for numerous customers, I have decided to create a framework zone. I will show you what Kubernetes resources and limits are and how to manage them.

The framework contains the following steps.

  • Infographic Guide shows what algorithms to follow to determine and assign the resources and limits.
  • Code templates allow applying those algorithms with minimal adaptation.
  • Algorithms and tools to gather the metrics about resource consumption and set up the limits.
  • Links to the official documentation where you can quickly grab some examples and read more detailed information.

What This Article Doesn't Contain

My goal here is simplicity. So you won't find detailed descriptions of how resources, limit ranges, and quotas work. There are plentiful articles written about it, as well as Kubernetes thorough documentation. Instead, here you will find information on how to quickly start adjusting Kubernetes resources in your projects.

Microservice Performance That Saves You Money

For many years, the most important metric for application servers was throughput: how many transactions or requests can we squeeze out of this application?  The adoption of finer-grained architecture styles, such as microservices and functions, has led to a broadening in the performance characteristics we should care about, such as memory footprint and throughput.

Where you once deployed a small number of runtime instances for your server and application, now you may be deploying tens or hundreds of microservices or functions.  Each of those instances comes with its own server, even if it’s embedded in a runnable jar or pulled in as a container image there’s a server in there somewhere. While cold startup time is critically important for cloud functions (and Open Liberty’s time-to-first-response is approximately 1 second, so it’s no slouch), memory footprint and throughput are far more important for microservices architectures in which each running instance is likely to serve thousands of requests before it’s replaced.

Will a BLOB Eat All My Memory?

Probably the most common usage for large objects (CLOBs and BLOBs) is to store them in a database table. In this circumstance, it feels intuitive that you won't have a lot of concerns about memory, because the database will simply store those objects in datafiles like it would any other kind of data.

But BLOBs and CLOBs can also be declared as local variables in a PL/SQL block. We typically expect local variables to be housed within the memory for that session (the PGA). There are explicit calls in the DBMS_LOB package to create a temporary large object, but what if we do use that API? What if we just start bludgeoning a local variable with more and more data? Is this a threat to the session memory and potentially the database server?

Pros and Cons for Using GraalVM Native-Images

Java is becoming very progressive with a new release policy and we receive regularly every 6 month new features, enhancements or just previews to test it out and write them back our feedback that can be taken into account in further development.

The second line might be even more interesting. It's GraalVM Project that especially contains a new C2 JIT Compiler and multi-language support based on Truffle Framework. There is one more technology that deserves our attention — GraalVM Native-Image. Native image is a utility for converting Java applications into fully compiled binary code which is called native-image. The process of creating a native-image is called ahead-of-time compilation.

General, Safe, and Deterministic Foreign Memory Access in JDK 14

Let's look at the numerous JDK 14-targeted features available, specifically the Foreign Memory API.

In the post "JDK 14 Rampdown: Build 27," I summarized the numerous JDK 14-targeted features newly available with JDK 14 Early Access Build #27. There is already another JDK 14 Early Access Build available and this one [ Build 28 (2019/12/18)] includes one particularly interesting feature: Enhancement JDK-8234049 ["Implementation of Memory Access API (Incubator)"].

Memory Wasted by Spring Boot Application

Spring chickens and spring boots!


One of the widely wasted resources in the world today is Memory. Due to inefficient programming, a surprising (sometimes ‘shocking’) amount of memory is wasted. We see this pattern repeated in several enterprise applications. To prove this case, we conducted a small study.

TCP: Out of Memory — Consider Tuning TCP_Mem

What happens when you're out of memory?
You may also like: Java Out of Memory Heap Analysis

Recently we experienced an interesting production problem. This application was running on multiple AWS EC2 instances behind Elastic Load Balancer. The application was running on a GNU/Linux OS, Java 8, Tomcat 8 application server. All of a sudden, one of the application instances became unresponsive. All other application instances were handling the traffic properly. Whenever the HTTP request was sent to this application instance from the browser, we were getting the following response to be printed on the browser.

Proxy Error

The proxy server received an invalid response from an upstream server.

The proxy server could not handle the request GET /.

Reason: Error reading from remote server


The JVM Architecture Explained

Every Java developer knows that bytecode will be executed by the JRE (Java Runtime Environment). But many don't know the fact that JRE is the implementation of Java Virtual Machine (JVM), which analyzes the bytecode, interprets the code, and executes it. It is very important, as a developer, that we know the architecture of the JVM, as it enables us to write code more efficiently. In this article, we will learn more deeply about the JVM architecture in Java and different components of the JVM.

What Is the JVM?

A Virtual Machine is a software implementation of a physical machine. Java was developed with the concept of WORA (Write Once Run Anywhere), which runs on a VM. The compiler compiles the Java file into a Java .class file, then that .class file is input into the JVM, which loads and executes the class file. Below is a diagram of the Architecture of the JVM.

Pitfalls in JVM and Docker Defaults

First, there are a lot of articles about JVM and container-awareness:

In this post, I use Java 11, which means the default for garbage collector is supposed to be G1GC! Let's look at the defaults, which are automatically chosen by the JVM depending on memory size and provided CPUs.

‘BuggyCow’ Is Yet Another MacOS Flaw With Serious Security Implications

Apple is once again in the news for something they’re certainly not happy about: Another coding bug has been found in the MacOS operating system, this time allowing hackers to change the data of a computer’s most privileged code.

As this piece from Wired explains, the BuggyCow trick (named after the loophole hackers found in the OS’s copy-on-write or CoW protection) “takes advantage of the fact that when a program mounts a new file system on a hard drive – basically loading a whole collection of files rather than altering just one – the memory manager isn't warned. So a hacker can unmount a file system, remount it with new data, and in doing so silently replace the information that some sensitive, highly privileged code is using.”