jarlah

jarlah

Coming from an experience as a jvm developer, I keep thinking about objects and memory allocation.

So, if I have a system where I dont create a shared Tesla client with predefined adapters and configuration, but instead relying on each service function to create a new client (with a method), will this cause any type of memory overhead in Elixir ?

For ex I have methods like these

def get_stuff_from_api(stuff_id, options \\ []) do
  conn = MyTeslaClientFactory.new(options)
  # possibly more logic
  MyStuffService.get_stuff(conn, stuff_id)
end

and then picture 30 of these methods. Will this be a problem?

Showing Posts 1 to 6

LostKobrakai

LostKobrakai

I won’t directly go to your question, but answer a few related ones.

Will it allocate memory (each time)? Yes
Will it require CPU to build the client (each time)? Yes
Where will it allocate memory? In the process calling that code
When will it be deallocated/garbage collected? There are various points in the lifecycle of a process when garbage collection happens per process. There are some cases in OTP where there can be global garbage collection, but those are commonly called out explicitly.

That depends a lot of where you call that function and what you or your projects constraints consider “a problem”. Are you in a memory constraint system? Do you want to expend more cpu (e.g. to fetch the client from elsewhere) to prevent additional memory allocations? How often are those functions called? Always in the same process or in different ones? Are the processes long lived or short lived? Can the client change at runtime? How much cpu is taken up to create the client?

jarlah

jarlah OP

Its for testcontainers package. So not production code. But never mind. Its not a huge problem unless you have 100+ tests i think with each having at last two test cases. Then testcontainers will now create 5-10 clients per test. So 200*10. hehe. But i guess they are cleaned away pretty fast. Problem comes when i need to make disk checks for docker sockets snd other stuff to evaluate correct base url. Which Im not doing atm. I guess this will be easily solved by passing in connection as an optional option :wink:

jarlah

jarlah OP

Maybe an genserver with connection as state after init is the proper way to handle this. As excontainers initially did. :sweat_smile: and then proxy calls to a module

LostKobrakai

LostKobrakai

Inter process communcation means data is copied though. If you want to share data as is you can look into persistent_term, including all it’s caveats.

jarlah

jarlah OP

will check it out at least. Difficult to mark this as answered, maybe its more of a discussion

jarlah

jarlah OP

ill keep that stuff on an arms length distance :S

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews