jarlah

jarlah

Is it costly to create a Tesla client with hackney adapters

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?

Most Liked

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?

Last Post!

jarlah

jarlah

ill keep that stuff on an arms length distance :S

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement