Send Email Causing High CPU Usage

Hello,

We are using Metabase with 2 vCPU and 2 GB of RAM. We set JAVA_OPTS="-Xmx1024m".

We are also using AWS SES as our SMTP.

When we wanted to try our SMTP connection, we tried it with 2 usecases:

  1. Create a simple question, a table with 4 columns and 5 rows and then clicked “Send Email” from alert section
  2. Create an aggregated query question, a sankey chart and then clicked “Send Email” from alert section

The result, no significant CPU usage on no. 1. However, when it came to no. 2, the CPU usage suddenly spiked and metabase crashed.

My question, is it normal to have CPU usage spike when sending email from the question? If it’s normal, based on your experience, what should I do to prevent this from happening again (maybe adjust some configs)?

Thank you!

I just had a discussion with another user about this.

2GB is too small for Metabase and the OS, especially if you are using dashboard notifications. I would bump your instance up to 4GB and set a 2-2.5GB heap to ensure there’s enough space for everything, and monitor the Metabase log closely for any OutOfMemory exceptions.

The java service needs more than just the heap value to operate. In particular with Hotspot VM and Clojure, it needs to have a copy of the compiled JAR in RAM outside of the Java heap, so Metabase will use ~1GB RAM before it even starts running.

The CPU spike you see is the JVM spending all its time garbage collecting just before it crashes from running out of memory.

Some CPU is expected because Metabase is running a JavaScript engine (like a mini web browser) to render the charts for the email. Making charts from large amounts of data will exacerbate memory issues. Recent version of Metabase have instituted some countermeasures to keep from loading all the data in memory, but it isn’t foolproof.

Thank you very much for your detail explanation, now I understand.

Can adding swapfile resolve this?

If not, then we’ll increase the RAM into 4 GB .

Every OS already has a swap file, and it’s not memory

In our server (AWS Lightsail), it’s 0 by default.

Nevertheless, we have decided to increase RAM to 4 GB and swapfile 2 GB.

Already tested sending email and the server didn’t crash