Grails Founder: What Java Developers Don’t Know About Memory Can Cost Them Money in the Cloud

Oracle Groundbreaker Award winner Graeme Rocher recently released a new open source project called Micronaut.

“Your day-to-day developer is exposed to the surface level of the framework, the tools, APIs, documentation of the framework, and how to use it. It’s only when the application gets pushed to production do they realize, ‘Hold on, this needs a gigabyte of memory to run,'” he says.

While Java applications have mainly been managed at runtime by Java Virtual Machine, today, developers often deploy to Kubernetes, called the cloud operating system because it orchestrates containerized applications at scale.

Whether it’s Kubernetes or an environment like Oracle Cloud Infrastructure that is managing the application, developers writing cloud apps need to think differently. “You have to make the app very responsive to restarts, and failover, and shutting down and coming back up again, and making it optimized in terms of startup time and memory consumption,” says Rocher, who works by day as a senior engineer at OCI, which maintains Grails. “Ultimately, your application is going to consume resources—and resources equal money.”

Optimizing for Serverless

With every new computing paradigm comes surprising gotchas. In the case of the cloud, one risk comes from the hidden costs of applications that, at face value, ought to be economical: microservices.

On the same day in October that Rocher was honored for his work in open source with a Groundbreaker Award presented at Oracle Code One in San Francisco, he released a new open source project called Micronaut. Like Grails, the open source web application framework he cofounded, Micronaut is JVM-based. The similarity ends there, however. Micronaut is a modular, easily testable framework for building modern microservice and serverless applications.

“In the Java ecosystem in general, we have a lot to learn about making apps more efficient and optimized for low-memory footprint,” Rocher says. Huge systems written in Java, such as Hadoop, Kafka, and Cassandra, support long-running processes that can benefit from just-in-time compilation in JVM. “But for shorter-running processes, which are becoming trendy with serverless computing—Lambda, functions, Knative—what you have is a situation that is more optimized for fast cold starts and low memory footprint and short-lived processes,” he says. “The optimizations that the JVM provides are lost if the process is only executed briefly and then goes away, as in the utility computing model.”

For example, SmartThings, a subsidiary of Samsung Electronics, allows its end users to control, automate, and monitor their household fixtures, such as lights, locks, and electrical outlets, through an application on their mobile devices. SmartThings recognized a need to transition away from its legacy monolith architecture to a faster, more flexible microservice-based system and selected Micronaut because of its ability to perform critical operations at subsecond speeds while also supporting a lean cloud deployment.

With Micronaut, application startup time and memory consumption do not automatically increase based on the number of lines of code in a program. As such, Micronaut works not only for utility computing, it is also a general development environment that runs handily on small memory footprint devices, such as Android, and hobby microcontrollers, such as Raspberry Pi.

Rocher’s new project fills a growing need in a cloud native, polyglot, device-independent world—and dovetails nicely with projects such as GraalVM, for compiling native, faster-running Java code. Projects like Micronaut and GraalVM also show how Java continues to evolve.

Java Doesn’t Have to Be Heavy

“People often think Java means heavyweight,” Rocher says, but that reputation has more to do with the APIs and tools that the JVM provides to build frameworks. “They have historically been based on the use of runtime reflection—the analysis of annotations at runtime—and building applications that way inevitably leads to increased memory consumption.”

In contrast, ahead-of-time compilation—the process of translating programming language into Java bytecode, or bytecode into machine code—is relatively unknown to a lot of developers, but it’s used heavily in certain application platforms. “What Micronaut does is take a lot of that philosophy and apply it to server-side programming.”

The days of waiting a few seconds for a Java application to startup are behind us, thanks to the advent of orchestrated microservices that can rapidly spin up and down. And that’s not the only advantage of Rocher’s new framework. Micronaut integrates with tools for tracing and security, and it doesn’t have to be containerized.

“If you think about Java applications, there’s this reliance on a container for a lot of features. With Micronaut, a lot of those features are compiled at runtime, so that container requirement goes away. It makes it a whole lot easier to test your application.”