News for hackers. Stuff that matters.
Re:Elixir on Google Cloud Platform and App Engine by tabeth on Monday January 22, 2018 @07:02PM (#16209447)
Excellent!

I recall someone on here (HN) saying that many of Elixir's strengths are weakened significantly because K8 does similar things (auto distribution, hot reloading, etc.)

Any truth to this? Also, can you distribute nodes on VMs and deploy them to Google Cloud?

---

As a side note, is there a front-end equivalent to Elixir? Elm is functional but is non intuitive. Elixirscript is a thing but seems a bit too early.

Re:Elixir on Google Cloud Platform and App Engine by hanrelan on Monday January 22, 2018 @08:52PM (#16210191)
I've used Elixir/Phoenix on K8s and there's some truth to this. For example - kubernetes' "if the process dies, kill the whole container and restart it" model doesn't work very well with Elixir (a process within the VM can die and K8s will have no idea). To some degree, K8s is replicating some of the BEAM functionality.

But there's still a lot from Kubernetes that Elixir can take advantage of. For example - service discovery, autoscaling, clustering, secret management - all made easier with a K8s deployment and Elixir.

I wrote a few blog posts about it a while ago if you're interested: https://medium.com/polyscribe/a-complete-guide-to-deploying-...

Re:Elixir on Google Cloud Platform and App Engine by josevalim on Tuesday January 23, 2018 @03:31AM (#16211935)
Unless Kubernetes is killing the container without respecting the shutdown time of the underlying processes, this should not be problem.

Once Kubernetes sends an exit signal to the VM, the VM will start the shutdown of its processes, and everything should terminate gracefully.

It is OK that Kubernetes doesn't know about Elixir processes terminating, because it is not its job. It is the job of the Elixir software to express its start-up and shutdown guarantees. If you don't want the VM to start when you don't have a database connection, then you should start a process right after your connection pool starts and before your endpoint runs that attempts to issue a query and act accordingly.

Re:Elixir on Google Cloud Platform and App Engine by sb8244 on Monday January 22, 2018 @11:11PM (#16210932)
Hmm I'm not quite sure I follow the process examine. If your started process crashes (let's say supervisor fails to start due to too many failures), k8s would restart the process (your app) to try again. If a managed process in elixir dies, you could make that bring down your whole app, but generally you would want to handle it yourself.

This is similar to an app server in Ruby. A single worker might die, but it's still being managed by a central coordinator. If the coordinator dies, everything is down and the app restarts

Re:Elixir on Google Cloud Platform and App Engine by dguaraglia on Tuesday January 23, 2018 @12:27AM (#16211254)
Not trying to be flippant, but by extending your analogy: if the Kubernetes supervisor dies (which is conceivable, no technology is infallible), then you are in the same scenario as something bringing your whole Elixir VM down. You can always run your Elixir VM using something like supervisord if you need another watchdog.

BTW, it's very hard to bring BEAM down. Most exceptions will bring kill the faulty process, but leave the supervisor tree untouched. Only "unmanaged" code (for example, calling a C library using a NIF) might crash the whole VM.

Then again, no technology is infallible.

Re:Elixir on Google Cloud Platform and App Engine by greenleafjacob on Tuesday January 23, 2018 @02:47AM (#16211765)
> You can always run your Elixir VM using something like supervisord if you need another watchdog.

Sounds like heart: http://erlang.org/doc/man/heart.html

Re:Elixir on Google Cloud Platform and App Engine by noemotion on Tuesday January 23, 2018 @05:23AM (#16212368)
>BTW, it's very hard to bring BEAM down. Most exceptions will bring kill the faulty process, but leave the supervisor tree untouched. Only "unmanaged" code (for example, calling a C library using a NIF) might crash the whole VM.

Not completely true. Try to allocate more memory than available and then see what happens.

Re:Elixir on Google Cloud Platform and App Engine by dguaraglia on Tuesday January 23, 2018 @02:26PM (#16216656)
I'm actually curious. Do you have some first-hand experience with that kind of issue? I've only played around with Elixir and my only experience deploying BEAM-based applications on production has been RabbitMQ and CouchDB and both of those were very solid.

Also, isn't ENOMEM a standard error that you can handle using the standard error handling techniques?

Re:Elixir on Google Cloud Platform and App Engine by noemotion on Tuesday January 23, 2018 @03:29PM (#16217342)
I have and it wasn't good. It is impossible to handle out of memory exceptions inside the BEAM. At best, you can hope for a crash of the VM. At worse, it just hangs. And one will most likely not find out about this until they hit this scenario.
Re:Elixir on Google Cloud Platform and App Engine by dguaraglia on Tuesday January 23, 2018 @05:42PM (#16218582)
Interesting, definitely worth knowing beforehand (I was thinking of implementing a small service that could be pretty memory-intensive using Elixir.) I wonder if there's a way to try and manage memory to avoid ENOMEM.
Re:Elixir on Google Cloud Platform and App Engine by lozenge on Tuesday January 23, 2018 @06:09PM (#16218769)
If BEAM is allocating memory it must either be copying a message from one process to another, allocating space in a process for its stack, or for some bookkeeping like to spawn a new process. In the first two cases why doesn't it just kill the process and send the usual link and monitor messages to let other Erlang processes handle the failure?
Re:Elixir on Google Cloud Platform and App Engine by noemotion on Wednesday January 24, 2018 @03:22AM (#16221194)
How would it send a message if it can't allocate memory anymore?
Re:Elixir on Google Cloud Platform and App Engine by dguaraglia on Wednesday January 24, 2018 @02:42PM (#16225663)
Haha, yeah, that's the problem with ENOMEM handling in general: unless you have a very clear path to free memory immediately and then try to do some reasonable cleanup, you are screwed. Back in the bad old days of running Windows machines with 8mb of memory, I'd religiously handle that kind of error code... but I can't recall the last time I actually bothered. Commoditized hardware makes us lazy.
Re:Elixir on Google Cloud Platform and App Engine by keithnoizu on Wednesday January 24, 2018 @09:28AM (#16222893)
yeah I have to make liberal use of :hibernate to avoid just this.
Re:Elixir on Google Cloud Platform and App Engine by sb8244 on Tuesday January 23, 2018 @01:15AM (#16211418)
True true, maybe there's just a single part that I was hung up on in parent comment

> (a process within the VM can die and K8s will have no idea)

I suppose that I see nothing wrong with this and would say that it's not weird or unusual to be the case. They're separate things, although they both achieve visually similar goals (keep things running as much as possible).

My point is less about K8s vs Elixir but rather a statement that this seems acceptable and shouldn't be a reason to rule out something like running Elixir on K8s.

Re:Elixir on Google Cloud Platform and App Engine by hanrelan on Tuesday January 23, 2018 @02:13AM (#16211641)
The scenario I saw with this was the following:

BEAM VM comes up and tries to connect to the database. The database is temporarily unreachable from that machine, but only the Ecto process dies and BEAM VM doesn't die. Since the last process (BEAM) in the Dockerfile is running, Kubernetes thinks it's healthy and will try sending traffic to it.

Compare this to something like node, where the node process will die if it can't connect to the database, and Kubernetes won't try to direct traffic to it and will restart it for you. You can do this with Elixir supervisors as well - that's why I said Kubernetes replicates some of Elixir's functionality.

It's definitely possible to work around all this which is why we ended up using Kubernetes for our Elixir deployment (and I'd recommend it). It's just these little things that make it clear that Kubernetes was designed with something like node in mind and not BEAM.

Re:Elixir on Google Cloud Platform and App Engine by jclulow on Tuesday January 23, 2018 @03:05AM (#16211836)
The behaviour you are attributing to Node is really just the behaviour of poorly constructed software. There are at least some Node-based software products which correctly come up and wait for dependencies to become available -- and gracefully handle their subsequent transient unavailability.
Re:Elixir on Google Cloud Platform and App Engine by atopuzov on Tuesday January 23, 2018 @08:41AM (#16213455)
There are 2 types of probes: readiness and liveness [1]. Define your readiness probe so it passes when you are ready to take the traffic (eg. connected to the db).

[1] https://kubernetes.io/docs/tasks/configure-pod-container/con...

Re:Elixir on Google Cloud Platform and App Engine by rkangel on Tuesday January 23, 2018 @04:05AM (#16212057)
That's a very helpful post series, but your links to the follow on articles are broken, and there is a 'TODO' in the middle of part 1.
Re:Elixir on Google Cloud Platform and App Engine by hosh on Monday January 22, 2018 @07:26PM (#16209634)
Elixir is great for stateless apps. So are a bunch of other platforms.

Elixir is exceptional at stateful apps. And it is true, many of those things are now handled through K8S. However, K8S doesn't handle everything and requires a lot more ceremony and infrastructure than what you can get within the Elixir/Erlang ecosystem.

I think there might be a way to work with Elixir + K8S in a way specific to the domain you are working with. Not everyone needs to be able to hot-reload code without dropping live connections, but if if you do, and you want to deploy on K8S, then you can try writing a K8S operator that encapsulates that idea. However: https://gravitational.com/blog/running-postgresql-on-kuberne... (which is more about how every distributed system requires deep domain knowledge, not just specifically about PostgreSQL)

I have not deployed Elixir on GCP. I have deployed other things though, and I can tell you the private networking is much better set up than AWS. As far as distributing nodes, you can do that with any of the cloud providers.

Re:Elixir on Google Cloud Platform and App Engine by jrs95 on Monday January 22, 2018 @07:25PM (#16209625)
That’s just crazy to me. The amount of effort you have to put in to achieve this with Kubernetes is way beyond what you would have to do to write you application in Elixir. If you already have multiple services in another language, it may be worth the effort, but the BEAM gives you nearly for free what is relatively expensive to get elsewhere.
Re:Elixir on Google Cloud Platform and App Engine by eat_veggies on Monday January 22, 2018 @07:28PM (#16209647)
Have you tried Reason[0] and Reason-React[1]?

[0] https://reasonml.github.io/

[1] https://github.com/reasonml/reason-react

Re:Elixir on Google Cloud Platform and App Engine by tabeth on Monday January 22, 2018 @07:39PM (#16209705)
This looks very interesting. Thanks for the suggestion.
Re:Elixir on Google Cloud Platform and App Engine by bpicolo on Monday January 22, 2018 @09:01PM (#16210244)
Clojurescript is also very mature and has a pretty great community and set of open-source libs
Re:Elixir on Google Cloud Platform and App Engine by willyk on Monday January 22, 2018 @07:27PM (#16209637)
If you looking into OTP, you'll see there's quite a but more and to some extent it does things differently than K8 (e.g., Observer, fault tolerance, concurrency and vertical/horizontal scaling w/message passing, etc.). See: https://www.manning.com/books/the-little-elixir-and-otp-guid...
Re:Elixir on Google Cloud Platform and App Engine by fulafel on Monday January 22, 2018 @11:11PM (#16210933)
ClojureScript is good for the front-end language. Though don't dismiss Elm easily either, it's so cool.
Re:Elixir on Google Cloud Platform and App Engine by willyk on Monday January 22, 2018 @07:24PM (#16209620)
The two options you mention are the ones I see used most often (with React & Vue being 3rd/4th), but I wouldn't say any of those are "frontend equivalents".
Re:Elixir on Google Cloud Platform and App Engine by dominotw on Monday January 22, 2018 @07:48PM (#16209764)
> As a side note, is there a front-end equivalent to Elixir? Elm is functional but is non intuitive. Elixirscript is a thing but seems a bit too early.

Purescript?

Re:Elixir on Google Cloud Platform and App Engine by thinkpad20 on Monday January 22, 2018 @11:41PM (#16211054)
Aside from both being functional languages, they have relatively little in common. Purescript has Haskell-style purity (with synchronous impurity via monads) and doesn’t have an inherent concept of processes or message passing like Elixir/Erlang do. Purescript is statically typed with no (I think?) macro system, and elixir is dynamic and makes extensive use of macros. Etc.
Re:Elixir on Google Cloud Platform and App Engine by AngeloAnolin on Monday January 22, 2018 @07:57PM (#16209825)
I've looked at learning Elixir paired with a front end tool and a lot of Elixir experts are pointing to the Phoenix Framework. [1]

[1] http://phoenixframework.org/

Re:Elixir on Google Cloud Platform and App Engine by bpicolo on Tuesday January 23, 2018 @09:48AM (#16213927)
Phoenix is a backend framework.
Re:Elixir on Google Cloud Platform and App Engine by keithnoizu on Wednesday January 24, 2018 @09:30AM (#16222910)
it includes some grub setup for compiling static assets though, and is a fast way to get an endpoint up and running.