Wincer

Wincer

Hello everyone, I am using Mnesia to build a cacheing system, Encountered a problem:

Every time I use :mnesia.transaction, it will bring little memory consumption. Almost 10,000 :mnesia.transaction calls will consume 1MB of memory.

After some work, I found that the memory occupied by ets’s table: mnesia_transient_decision will continue to increasing. Every call to :mnesia.transaction will insert a record into table mnesia_transient_decision, and even if I use :mnesia_recover.allow_garb and :erlang.garbage_collect, the memory will not decrease. And I can’t delete this table.

Can someone help me? very appreciate

test code:

defmodule TestTransaction do
  alias :mnesia, as: Mnesia
  def init_mnesia do
    Mnesia.start()
    Mnesia.create_table(Person, attributes: [:age, :username], disc_copies: [node()])
  end
  def case_trans_read do
    f = fn ->
      Mnesia.read(Person, 2)
    end
    Mnesia.transaction(f)
  end

  def print_memory_info do
    IO.puts("total: #{:erlang.memory[:total]}, ets: #{:erlang.memory[:ets]}")
  end

  def benchmarking(_, 0), do: nil

  def benchmarking(f, n) do
    apply(TestTransaction, f, [])
    benchmarking(f, n-1)
  end

end

TestTransaction.init_mnesia

TestTransaction.benchmarking :case_trans_read, 10000

:observer_cli memory usage of ets:
|Table Name |Size | Memory |Type |Protection |KeyPos |Write/Read |Owner Pid |
|mnesia_transient_decision | 10002 | 1022.1172 KB | set | public | 2 | false/false | <0.214.0> |

Showing Posts 1 to 4

krp

krp

Saw your post yesterday and thought this was a chance to dig into a bit of mnesia. I’ve been able to reproduce this although I needed to remove the disc_copies options to get it to run. I see the same issue. Nothing added to the table but memory tied up with ets increases with each transaction call. Have you been able to figur eout the cause of this and any solution ?
Thanks

Wincer

Wincer OP

@krp Thanks reply.
Actually I have been troubled by this issue for several days. After reading the source code, I found that the increase in mnesia transaction memory is inevitable. The mnesia transaction does not provide an option to avoid inserting records into the ets table(see source code: mnesia_recover:note_decision).

Also according to the code(mnesia_recover:do_allow_garb), even if allow_grab is run, it will still retain the existence of the last 10 ets tables.

So, I haven’t found a solution yet.

krp

krp

I found this similar discussion from 2007 Memory Usage by Mnesia Growing. I tried to reproduce what they found but saw no reset even after 3740006 transactions and memory was up around 400 Mb.

I imagine that eventually it will reset but this is based on the total amount allocated to Erlang. I know I’ve looked at that before but don;t recall the details. If you knew it was going to eventually reset would that work for your needs ?

Wincer

Wincer OP

Thanks reply, this discussion is helpful, but may not solve my problem. My needs are more sensitive to memory usage…

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Stef-Verniers
Hello I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews