Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory usage steadily increases without recovery in Electric instance #2229

Open
sullyo opened this issue Jan 14, 2025 · 5 comments
Open

Memory usage steadily increases without recovery in Electric instance #2229

sullyo opened this issue Jan 14, 2025 · 5 comments
Labels

Comments

@sullyo
Copy link

sullyo commented Jan 14, 2025

We're experiencing steadily increasing memory usage in our Electric instance that doesn't recover until restart.

Current behavior:

  • Memory usage shows continuous growth over time
  • No automatic recovery of unused memory
  • Requires manual restarts to reset memory levels

Environment:

  • Electric deployed on render via container
  • 2gb memory, 1 cpu

Theory:

  • Could be related to total requests. Saw memory exceed limit with more requests

Reproduction steps:

  1. Run Electric instance
  2. Monitor memory usage over time
  3. Observe steady increase in memory consumption
  4. Eventually requires restart to recover

Current workaround:
Manual restart of the instance clears the memory back to normal levels.

Image

Image

Image

@balegas
Copy link
Contributor

balegas commented Jan 15, 2025

Hi, we've seen this happen before. We think it is related with how Elixir manages processes memory. We're gonna work on a fix ASAP.

@balegas balegas added the bug label Jan 15, 2025
@robacourt
Copy link
Contributor

robacourt commented Jan 15, 2025

Please could you try something for us? We think garbage collection is causing the issue so please could you try running it manually:

On the machine with the electric docker image running run

docker exec -it IMAGE_NAME bin/entrypoint remote

(Use docker ps to get the IMAGE_NAME)

This will get you into an elixir shell, where you can run:

:erlang.garbage_collect()

It's worth running this 5 times to get the memory use right down.

Let us know if this helps, if it does we can automate the garbage collection to solve your issue.

@robacourt
Copy link
Contributor

Another thing to try is to let electric use all 2GB of your container's RAM and see what happens. If our hypothesis is correct then hitting the container limit will cause a garbage collection and so electric should flatline at 2GB memory use and continue to operate normally.

If you'd like it to flatline at a lower value, the container's memory can be restricted with the --memory=1g docker run flag or with your cloud provider's settings.

@sullyo
Copy link
Author

sullyo commented Jan 15, 2025

 :erlang.garbage_collect()
true
iex(electric@)2> :erlang.garbage_collect()
true
iex(electric@)3> :erlang.garbage_collect()
true
iex(electric@)4> :erlang.garbage_collect()
true
iex(electric@)5> :erlang.garbage_collect()
true
iex(electric@)6> :erlang.garbage_collect()
true
iex(electric@s7> 

Ran it a few times here

And not seeing any memory reducing here

Image

@sullyo
Copy link
Author

sullyo commented Jan 15, 2025

Another thing to try is to let electric use all 2GB of your container's RAM and see what happens. If our hypothesis is correct then hitting the container limit will cause a garbage collection and so electric should flatline at 2GB memory use and continue to operate normally.

If you'd like it to flatline at a lower value, the container's memory can be restricted with the --memory=1g docker run flag or with your cloud provider's settings.

Going to try something like 1.5g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants