can you set jvm memory settings on an aws lambda?

You’re approaching this from the wrong direction. Per the Java8 docs:

The amount of native memory that can be used for class metadata is by default unlimited. Use the option MaxMetaspaceSize to put an upper limit on the amount of native memory used for class metadata

So, the only thing that explicitly configuring metaspace size does is limit the amount of metaspace memory; it won’t increase it. If you want to give more memory to metaspace, you need to decrease predefined size of the rest of the heap.

However, that’s the wrong thing to do.

The real problem is that you’re doing something that loads more classes than can fit in available metaspace. The most likely cause is that you’ve just picked a memory configuration that’s too small for your deployment bundle. You didn’t say what your configured value was, but if I had to guess it’s around 512 MB. Try 1024 or 1536.

It’s also possible that you — or one of the libraries that you use — is dynamically creating classes in an unconstrained manner. In this case it doesn’t matter how much memory you give to your Lambda, you’ll eventually run out of space.

The way to diagnose this is to run your code outside of Lambda, using the TraceClassLoading and TraceClassUnloading flags. You’re looking for classes that have “generated” names, typically random sequences of digits or letters.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top