Earlier quoted context omitted.
Any sufficiently complicated distributed program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Erlang
That has definitely been my experience. There's been a good number of times I end up gluing things together with ZeroMQ and SQS and Redis where I start thinking "you know this would have been easier to get an equivalent (or better) product in Erlang". Sadly, I've only ever had one job at a shady startup that used Erlang; I would love to work for a company that sees its power, but sadly it seems that everyone who has…
Unpacking Elixir: Concurrency
111–120 of 138 posts
Re: Unpacking Elixir: Concurrency
#112Unlike javascript, elixir makes you write synchronous code, e.g. def process_items(items) do items |> Task.async_stream(&Processor.process/1, max_concurrency: 2, timeout: 7000, on_timeout: :kill_task) |> Enum.to_list() end Semantics of regular and concurrent code is the same
Node has kind of wrecked the term "synchronous". It convinced many people that "synchronous" also entails "only thing running on the processor at the time" and "if you're 'synchronously' waiting on a file read the entire process is waiting". So when you say "Elixir/Erlang/any threaded language 'makes' you write synchronous code", to the people who most need to hear this, those steeped in the async way of the world, y…
Re: Unpacking Elixir: Concurrency
#113Earlier quoted context omitted.
You really shouldn't be using agent for mutable state. Kind of annoying that the docs push you to that. Agent is most useful when you need to tie the transient lifetime of some state with something else (think: compilers). Otherwise, it's generally better to use a database, (or ets, if you need performance), GenServer/gen_statem if you need reactive events attached to the state. Agent is just a wrapper over GenServer…
I love elixir and am very comfortable with functional programming and generally prefer it. But being told you have to write a state machine instead of just += a var is an excellent experience in believing elixir is harder than python.
Re: Unpacking Elixir: Concurrency
#114https://spacedimp.com/blog/dockerless-setting-up-an-elixir-w...
Re: Unpacking Elixir: Concurrency
#115Earlier quoted context omitted.
I'm pretty sure erlangs :array is just a skin over tuple, so it's ~O(1) but not contiguous. might be O(log n) for dynamic arrays. The only truly array datatype in Erlang is :atomics
Erlang tuples are contiguous in memory for primitive values https://blog.edfine.io/blog/2016/06/28/erlang-data-represent...
Re: Unpacking Elixir: Concurrency
#116Earlier quoted context omitted.
Same things arrays are used for in all mainstream languages ie. index-based access.
You want tuples. They've got index-based access, and all your useful things in erlang:element/2, setelement/3, append_element/3, delete_element/2, insert_element/3. With a big caveat that modifying tuples isn't great for performance unless the compiler or optimizer determine that mutating the tuple is acceptable rather than providing a mutated copy.
Re: Unpacking Elixir: Concurrency
#117Earlier quoted context omitted.
Vs which other languages - do you have examples of better patterns?
all the C family all the JVM languages all the .Net languages Rust Ruby Python etc.
Re: Unpacking Elixir: Concurrency
#118Earlier quoted context omitted.
You want tuples. They've got index-based access, and all your useful things in erlang:element/2, setelement/3, append_element/3, delete_element/2, insert_element/3. With a big caveat that modifying tuples isn't great for performance unless the compiler or optimizer determine that mutating the tuple is acceptable rather than providing a mutated copy.
I understood tuples are only optimised for a handful of elements.
Re: Unpacking Elixir: Concurrency
#119Earlier quoted context omitted.
well my startup uses distributed elixir. we use it horde to distribute certain long lived processes accross our cluster. that does not exclusive to kuernetes. we user kubernetes to manage and handle vm crashes (its only happened twice ever) as well as porvide consistent network toplogy between the nodes. that said, having the ability to send messages between machines without having to bring in an external dependency…
Could you explain a bit more how you are using it?
Re: Unpacking Elixir: Concurrency
#120The deal-breaker for me with Elixir has always been the lack of real Elixir vectors rather than the crappy Erlang array library. Yes, I know you can use a Map with numeric keys but that's not the same.
So what do you use real arrays for? For 80% of programming lists are just fine. Are you doing cpu-bound numerical calculations?
This occurred somewhat recently when implementing stable topological sort. I ended up swapping List out for a Vector (Aja is library I used). I received a 100x performance improvement from it.
That's really the only time I've truly hit a List performance roadblock in 7+ years of Elixir.