News for hackers. Stuff that matters.
Re:Write libraries instead of services, where possible by wcarss on Tuesday March 09, 2021 @12:28PM (#26401124)
this sounds really neat and I'm going to go read about it!

I also wanted to call out that this ~sentence has just... a bunch of things that seem like jargon/names within the community? As an outsider, I have no idea what they mean:

> make a Genserver or Oban worker and mount it in the supervision tree. The Beam takes care of maintaining the process

it sounds very sci-fi :)

Re:Write libraries instead of services, where possible by cultofmetatron on Tuesday March 09, 2021 @12:40PM (#26401264)
sorry! so I'll clarify

Elixir inherits a library called OTP from erlang which is a set of primitives for building massively concurrent systems.

A Genserver is sort of like a Base Class for a object that runs as an independant process that plugs into OTP. By inheriting/implementing the Genserver behavior, you create an independant process that can be mounted in an OTP supervision tree which runs at the top of your application and monitors everything below it. Out of the box, that means your process can be sent messages by other processes and can send messages itself. If a crash happens, the supervisor will kill it, resurrect it and redirect messages to the new process.

Creating a Genserver is as easy as adding an annotation and implementing a few callbacks.

Genservers are the base on which a lot of other systems build on. Oban, a job worker essentially builds on Genserver to use a postgres table as a job processor. Since its just a Genserver with some added behavior, adding a background worker is as simple as adding a file that inherits from Oban and specifying how many workers for it should be allocated in a config file. The result is that adding a background worker is about as much work for me as adding a controller. No additional work for devops either.

And yes, it is very sci fi. Honestly I'm shocked elixir isn't more widespread. there's very little hype behind it but the engineering is pretty solid. Every scaling bottleneck we've had so far has been in the database (only because we particularly make heavy use of stored procedures)

Re:Write libraries instead of services, where possible by pkos98 on Tuesday March 09, 2021 @04:28PM (#26404517)
!Important clarification!

In the world of OTP (Open telecom platform), a process is the term for what essentially is a green-thread, not an OS process!

So it is: a) much, much more lightweight (IIRC ~ 1Kb) b) scheduled by the Erlang virtual machine (so called BEAM)'s scheduler. The BEAM's schedulers run on a per-thread-basis, inside the BEAM's process c) independently garbage collected, no mutable memory sharing

Re:Write libraries instead of services, where possible by dwohnitmok on Tuesday March 09, 2021 @07:29PM (#26406339)
> there's very little hype behind it

This isn't a knock against Elixir or the Erlang ecosystem but I would definitely say that Elixir gets a decent amount of hype. Each time a new release comes out it invariably shoots to the front page of HN.

Re:Write libraries instead of services, where possible by macintux on Tuesday March 09, 2021 @08:04PM (#26406568)
And before Elixir, Erlang itself was a frequent visitor on the HN front page. Still is.
Re:Write libraries instead of services, where possible by iudqnolq on Tuesday March 09, 2021 @02:09PM (#26402534)
Might be helpful to know GenServer is short for "generic server"
Re:Write libraries instead of services, where possible by iudqnolq on Tuesday March 09, 2021 @02:09PM (#26402541)
What's it like using stored procedures with Ecto?
Re:Write libraries instead of services, where possible by cultofmetatron on Tuesday March 09, 2021 @02:13PM (#26402609)
surprisingly easy.

1. if I'm calling directly, I can just use a raw sql query 2. views can be backed with a read only ecto model 3. triggers can be set to run without your ecto code even being aware of it. 4. for custom errors, you can add overides for the error handling in ecto to transform things like deadlocks to 400 errors

Re:Write libraries instead of services, where possible by iudqnolq on Tuesday March 09, 2021 @02:17PM (#26402659)
Cool. What language do you write the stored procedures in?
Re:Write libraries instead of services, where possible by cultofmetatron on Tuesday March 09, 2021 @02:26PM (#26402815)
plpgsql
Re:Write libraries instead of services, where possible by shoo on Tuesday March 09, 2021 @04:05PM (#26404234)
Some of these ideas are written up in the late Joe Armstrong's dissertation about Erlang and OTP "Making reliable distributed systems in the presence of software errors". It's a few hundred pages but quite readable to a programming audience -- it isn't filled with acres of formal proofs or highly specialised jargon.

https://erlang.org/download/armstrong_thesis_2003.pdf

> supervision tree

See chapter 5 "Programming Fault Tolerant Systems" & section 5.2 "supervision hierarchies"

> genserver / generic server

See chapter 4 "Programming Techniques" section 4.1 "Abstracting out concurrency" and chapter 6 "Building an Application" section 6.2 "Generic server principles"

Re:Write libraries instead of services, where possible by jorgeavaldez on Tuesday March 09, 2021 @12:36PM (#26401221)
They do sound very sci-fi. I would say it made me more or less inclined to dig a little deeper myself hahahaha.

Genservers are an abstraction encapsulating the typical request/response lifecycle of what we would consider a "server", but applied to a BEAM-specific process. Like "general server".

Oban allows for job processing, instrumented much like you would any other process in the BEAM. This is an external library while genserver is built in.

Re:Write libraries instead of services, where possible by notamy on Tuesday March 09, 2021 @03:57PM (#26404131)
Oban is a Postgres-backed job processing library https://github.com/sorentwo/oban