News for hackers. Stuff that matters.
Re:Elixir RAM and the Template of Doom by rdtsc on Tuesday April 26, 2016 @12:30PM (#11573273)
I like and use Erlang full time, but I am very glad to see Elixir gain traction.

BEAM is really a marvel of engineering.

I've mentioned this before, but I've head experience engineers show disbelief at what things it can do -- lightweight processes with isolated heaps, with ability to have millions of them, isolated faults (if one crashes in anyway it won't scribble over memory of others), very low latency garbage collection, awesome monitoring and tracing facilities, live code replacement and so on.

It really feels like having superpowers using it so nice to see a whole new ecosystem of languages on top of it.

Re:Elixir RAM and the Template of Doom by MichaelGG on Tuesday April 26, 2016 @01:26PM (#11573819)
The isolated faults thing: how is this different than every other managed language? Especially if shared state isn't used?
Re:Elixir RAM and the Template of Doom by jlouis on Tuesday April 26, 2016 @02:45PM (#11574495)
It is only half the story. In reality it is isolated resources: memory, CPU usage, files, sockets, ...

The key benefit is that a single process has a harder time monopolizing the system and taking over the system as a whole. This allows you to write code where the code is known to be suboptimal because it cannot take over the machine. In contrast, many other systems relies on a proactive model where each line of code has to be scrutinized for utmost correctness, or your system as a whole will fall.

As for the faults, there is a subtle but important difference compared to exceptions: you handle any error, not just the ones you figured could happen. And because resources are bound to processes, when the process goes away, so does its resource. Usually you would have to handle this in other languages.

The final point is that a fault is made transient: the system recovers and reestablishes the last known good state/invariant of the system. This allows you to try again which often handles the fault. And if it keeps failing, the fault is escalated to gradually larger and larger parts of the program.

There is nothing magical about the model. It is just that other languages have next to no convenient support for it.

Re:Elixir RAM and the Template of Doom by rdtsc on Tuesday April 26, 2016 @02:16PM (#11574284)
Start multiple threads. They write some data from them. One of them crashes. Is it safe to just restart that thread and continue?

Not always, because that thread might have written to so some shared data structure and left it in an inconsistent state. Restarting that one thread might seem to work but because there is no guarantee, the safest way is to restart the OS process.

It might not even be your code. Maybe your RPC library or some other package did it internally. You might restart and 99% of time it will work, but it will not be a guaranteed thing.

Now, of course the equivalent counterpart to this is not threads but you can do this with OS processes. And I've done it in Python. You can use pipes, file system writes, sockets to create a reliable system were some processes can crash without bringing down the whole service. But it is cumbersome.

But imagine the sever handles a million connections. Certainly doable in Erlang. Each one handled by one lightweight process. Connection does something unusual, maybe uses a new feature which was added last night. It crashes, that's fine. Other 999999 are ok. If this was a C++ program, it might have segfault-ed and caused the other 999999 connections to be dropped.

I've seen systems which had a periodically crashing subsystem that was being restarted behind the scenes for a while most of the system stayed up without noticeable issues. In business terms that means a smaller ops team, it means not having to wake up at 4am to answer pages (if subsystem heals itself, can just fix it in the morning) and so on.

Moreover, live code hot-patching is often touted as a gimmick. But I've used on a large production clusters while it was serving tens of thousands of requests per second without stopping. Sure it was scary and by that time something has already gone wrong (to need that fix), and it was nice not having to to shut down everything just to add an extra trace or log statement.

Re:Elixir RAM and the Template of Doom by illumen on Tuesday April 26, 2016 @02:34PM (#11574421)
I don't think it's so cumbersome with modern python. There's first class coroutines, futures, process pools and such now. Also there are a number of queues systems in python which easily allow running failed tasks again. One project I use is basically task(func, args). That's it. Then if it fails we can have them automatically restart, or wait for review etc. This is over multiple machines too. It's only about 60 lines of code, including nice gui interfaces to manage the tasks, and deploy the whole lot to various machines.

Erlang is amazing of course. Just wanted to say that some of those patterns are now available in python and easily usable. Not common to all python code, which is where I think erlang wins out. It puts this stuff front and center, and has first class support. Looking at a random erlang code base, you'll probably see it there. Random python code bases... not so much (ok, queue systems are quite common in Django/Flask projects). It's very rare to see python greelets/eventlets in the wild for example, but generators and async stuff are becoming quite commonplace.

Also python has single dispatch now (built in, not in a third party library). Another thing which Erlang does well (pattern matching). Again, not so commonly used except in modern python shops. These combined with quickcheck for python (hypothesis), and gradual typing really have made modern python a much more happy place. Erlang deserves some big respect for spreading good ideas.

Re:Elixir RAM and the Template of Doom by rdtsc on Tuesday April 26, 2016 @02:41PM (#11574468)
Sure. Individual aspects of Erlang/OTP are all present in other systems. OS processes, queuing backends, light weight co-routines, Java has some code reloading too.

But it makes a difference if it is in one language/framework and built-in. It makes tracing/debugging/developing easier.

Like with Python, yeah can use a queuing subsystems and submit jobs. But that is another service to configure and manage. Can use multiprocessing (and I've done that), but can't launch 1M of sub-processes. Which now changes how you develop. It has a green-thread co-routine support via greenlet (eventlet & gevent) but those share memory and if you do any CPU intensive work will block each other and will also share the heap.

Re:Elixir RAM and the Template of Doom by vvanders on Tuesday April 26, 2016 @05:21PM (#11575751)
I'd say it's a stretch that Java has code reloading. Sure you can reload the bytecode, but unless you're marshaling the data to the new version like Erlang does you're just introducing more errors than fixing things.
Re:Elixir RAM and the Template of Doom by jerf on Tuesday April 26, 2016 @04:09PM (#11575172)
Mutable languages fundamentally can not replicate the totality of Erlang's fail-first approach because the possibilities of partial state updates are fundamental issues. You can personally write code that is still fairly safe to use that way, but you're doing it by hand without compiler/runtime support, and you can't control your libraries.
Re:Elixir RAM and the Template of Doom by rtpg on Tuesday April 26, 2016 @11:02PM (#11577574)
I think it's pretty easy in Python (things like Celery), but I think the interesting thing is that for Erlang this stuff comes baked into the language, so it's even easier.

So there's all this nice fault tolerance by default, whereas in Python you have to look for it (and you can forget it)

Re:Elixir RAM and the Template of Doom by gamache on Tuesday April 26, 2016 @01:47PM (#11574024)
One way it's different is that there is rich support for specifying what should happen when subsystems crash. You make what's called a "supervision tree" where supervisors are notified when a child process crashes, and can choose what to do -- restart that child, restart all similar children, halt execution, do something completely custom, etc.

Scala's Akka library is another place you can find this (although a bit harder to configure) but I don't know many other languages that offer this.

Re:Elixir RAM and the Template of Doom by brightball on Tuesday April 26, 2016 @02:59PM (#11574596)
I really wish the Phoenix folks would spend some time on the Techempower benchmarks. In the latest round it did not show very well and had lots of errors.

Usually we see Elixir compared directly to Go and across the board Phoenix looks like it's not even coming close. I realize it's not the end all of comparisons, but it's just about the best thing we have going at the moment for comprehensive cross-language benchmarks.

Re:Elixir RAM and the Template of Doom by chrismccord on Tuesday April 26, 2016 @03:04PM (#11574623)
The techmeme results are not representative of the framework as they report extremely high error rates in their results. We don't know what caused the errors and unfortunately we didn't have a chance to collaborate with them on a true run as they didn't publish their preliminary results like they normally do before the final set. A few months ago they added Phoenix in a preview, but it was a very poor implementation. They were testing JSON benchmarks through the :browser pipeline, complete with crsf token generation. They had a dev DB pool size of 10, where other frameworks were given of pool size of 100. And they also had heavy IO logging, where other frameworks did no logging. We sent a PR to address these issues, and I was hoping to see true results in the latest runs, but no preview was provided this time and we weren't able to work with them on the errors.

tldr; these results are not representative of the framework.

Re:Elixir RAM and the Template of Doom by brightball on Wednesday April 27, 2016 @07:50AM (#11579522)
Thanks for clearing that up! Now I'm excited again.
Re:Elixir RAM and the Template of Doom by merb on Tuesday April 26, 2016 @05:48PM (#11575989)
actually no framework in techempore is a representative of the framework. also the test cases say nothing about the real performance either.
Re:Elixir RAM and the Template of Doom by out_of_protocol on Tuesday April 26, 2016 @03:06PM (#11574636)
Long story short: last round was made in a hurry (due to hardware issues), no feedback loop at all, results were vastly different from preliminary tests. Hope the next round will be done sane way
Re:Elixir RAM and the Template of Doom by Fennhella on Tuesday April 26, 2016 @01:44PM (#11573991)
Im curious, what do you use/recommend for monitoring and tracing?
Re:Elixir RAM and the Template of Doom by rdtsc on Tuesday April 26, 2016 @02:22PM (#11574334)
Others mentioned Observer. That is very cool.

When without a GUI I use the built-in dbg module. Sometimes via the recon_trace wrapper to get the tracing to be rate limited (if on a production cluster).

ttb built-in modules used for tracing on multiple nodes, capture more data and then save to a file and inspect later.

eflame or eep (not the Erlang Proposal, the profiling tool) + kcachegrind to view results.

Re:Elixir RAM and the Template of Doom by alexgaribay on Tuesday April 26, 2016 @01:47PM (#11574025)
Erlang has Observer, a built in tool that lets you monitor and trace things as well as well see your process hierarchy.
Re:Elixir RAM and the Template of Doom by davidw on Tuesday April 26, 2016 @02:25PM (#11574349)
I'm often not much of a GUI tool guy, but Observer is really cool - the GUI really does give you a nice view of how the supervision tree of a more complex Erlang system is put together.
Re:Elixir RAM and the Template of Doom by bobwaycott on Tuesday April 26, 2016 @06:51PM (#11576414)
Yep. Not only that, but I find it to just be insanely fun to go double-clicking with wanton abandon throughout Observer, digging in to everything just because I can. That it's all there, with no setup and effort required, makes it feel almost magical.