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
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
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security










