Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Memory issue when migrating from java 8 to java 17 running app engine java

We are currently migrating from Java 8 to Java 17 in a Google App Engine environment, but we're encountering memory leaks that eventually lead to an OutOfMemory (OOM) error. When running the application on a local machine with Java 17, everything works fine. However, in the App Engine environment, where we're using Cloud SQL and Datastore for database access, we are seeing issues. We're looking for recommendations on the best tools to profile memory usage in a Java 17 application running on App Engine's second-generation environment. Any advice on how to integrate memory profiling into this setup would be greatly appreciated.

1 2 813
2 REPLIES 2

greb
Former Googler

Hi @mlumbrer,

Welcome to Google Cloud Community!

It sounds like you’re hitting memory issues from the Java 8 to Java 17 migration on App Engine, especially with Cloud SQL and Datastore connections. A few things to try:

  1. Use Cloud Profiler: This will help you track memory use and identify leaks directly in App Engine. It’s easy to set up in GCP and works with Java 17.
  2. Enable GC Logs: Turn on garbage collection logging to check if certain objects aren’t being cleaned up as expected, and adjust the G1GC settings if needed.
  3. Check Connection Pooling: Double-check that your Cloud SQL and Datastore connections are optimized for Java 17. Libraries like HikariCP for SQL pooling can help manage memory better in this setup.

I hope the above information is helpful.

Hello Greb

It seems we've identified the issue with the database connection. When using a connection pool, the bulk of the memory leak is resolved. However, since our server is multi-instance and multi-tenant, we might reach the connection limit. I believe there’s a problem with opening and closing connections for each request, as we encountered a similar issue a few years ago. It’s possible that either the database connector or the cloud SQL proxy has a leak during the open-and-close process.

Top Solution Authors