News for hackers. Stuff that matters.
Re:Rails 5.0: Action Cable, API mode, and more by davidw on Thursday June 30, 2016 @06:43PM (#12012424)
> more maintainable

I get that the Erlang VM is really nice for some things (I made my first contribution to it in 2004!), but I'm curious about the above statement, as I haven't had the time to dig into Elixir/Phoenix yet.

Re:Rails 5.0: Action Cable, API mode, and more by bratsche on Thursday June 30, 2016 @07:16PM (#12012625)
I'm still fairly new with Elixir/Phoenix (as I think most of us still are), but so far I feel intuitively that it's more maintainable and I admit that I don't have the experience or numbers to back that up yet.

There are some things that you simply must use other tools for in Rails, because it can't maintain state like Erlang can. Once you start adding in these other things, you're no longer just a "Rails app" but you're really creating an entire system. Now you've got different things you potentially need to test, and you're adding in extra stuff to your system to monitor and measure the different parts of your system. You might do the same thing in Erlang/Elixir, but you also might not. You can potentially keep your entire "system" inside Erlang, either in one node or distributed. So right away simply having that option sounds like a huge improvement in maintainability. You've got everything running in Erlang, monitored and supervised in Erlang/Elixir, more easily testable using ExUnit or whatever.

And I think @bcardella talked about this in his RailsConf presentation (linked somewhere in the comments here).. but the performance you get from Elixir/Phoenix is potentially a huge improvement in maintenance. How much time have people spent in NewRelic or whatever measuring and tuning their Rails apps, getting the caching and everything working just right? People are writing Phoenix apps with zero caching that are performing better than Rails with caching. When people aren't having to go debug and diagnose these kinds of performance problems they get to work on actual features.

Again, some of this is just my intuition on it more than real experience to back it up. I've built a couple apps with Phoenix and I do enjoy it more. They're not big enough for the performance to really matter, but I do feel strongly that they're simpler because I'm keeping everything in Elixir code and not having to use, for example, Sidekiq in order to do anything async.

Re:Rails 5.0: Action Cable, API mode, and more by themgt on Thursday June 30, 2016 @07:27PM (#12012685)
Exactly this. It's easy to do 'rails new' and push to Heroku, but when you've got redis, memcache, the worker process & scheduler etc etc you're really maintaining your own ecosystem. It's a lot of where time gets spent on production Rails apps.

Here's that slide, I believe: http://i.imgur.com/QzTCJS8.png

Re:Rails 5.0: Action Cable, API mode, and more by mavelikara on Thursday June 30, 2016 @08:12PM (#12012938)
And here is a Ruby vs Java meme from 2006 or so: http://i.imgur.com/1V6rdWV.jpg.

This too shall pass.

Re:Rails 5.0: Action Cable, API mode, and more by mooreds on Friday July 01, 2016 @07:47AM (#12015272)
What's old is new again!
Re:Rails 5.0: Action Cable, API mode, and more by sayelt on Thursday June 30, 2016 @08:17PM (#12012959)
So NIH is the appealing factor of Elixir according to this slide?
Re:Rails 5.0: Action Cable, API mode, and more by bratsche on Thursday June 30, 2016 @10:06PM (#12013417)
No.

In a Rails system you've got Rails running, maybe across X number of instances with Unicorn or whatever, sitting behind nginx. If you want to have a long-running request or websocket you've typically used Go or Node or Elixir. If you need to store state between requests you may be using Redis. For background jobs and general async things you've probably got something like Sidekiq.

Erlang already has an http server that Elixir apps are using now, it's called Cowboy. It's not that Elixir is creating their own just because. One of the reasons nginx is often used for Rails apps is to handle static assets, because Rails just isn't as well-equipped to handle those. Cowboy seems to be fine with handling static assets, so a lot of people just take nginx out of the equation for an Elixir app.

Typically Rails apps have used something else like Node or Go or Elixir for long-running requests or websockets. Maybe that will change with ActionCable, maybe not. Either way, Elixir/Phoenix happen to be quite good at this already. Phoenix's equivalent to ActionCable is called Phoenix Channels and it's able to handle 2 million+ websocket connections on a single server, which is pretty cool I think.

Rails apps use redis to manage state between requests. Elixir apps just don't need something like this. Elixir doesn't have something different, it just happens to be easy to store state between requests already.

Rails apps may use Sidekiq or something to deal with background jobs or async operations. This is another case where Elixir doesn't have anything special to occupy that role in the stack, it just happens to be good at that already.

Most of these properties are things that Elixir inherited from Erlang, which has been around for years. I wish I had started learning Erlang a long time ago but unfortunately it just wasn't really on my radar. But really the only thing on this list which is a relatively recent thing is Phoenix Channels, and I don't think that's really a NIH thing. At least, certainly not any more than ActionCable is.

Re:Rails 5.0: Action Cable, API mode, and more by baudehlo on Friday July 01, 2016 @12:14AM (#12013831)
I'd love to see an active record (npi) of that 2m active web sockets. It's trivial these days to make 2m connections (it's just a RAM problem), but marshalling data between them is the non-trivial problem, as is actually having active data crossing those sockets.
Re:Rails 5.0: Action Cable, API mode, and more by gamache on Friday July 01, 2016 @05:52AM (#12014849)
Re:Rails 5.0: Action Cable, API mode, and more by bcardarella on Thursday June 30, 2016 @08:23PM (#12012985)
Considering that nearly all of those features were in Erlang before the other services listed I don't think NIH applies. Elixir just exposes the Erlang tools.
Re:Rails 5.0: Action Cable, API mode, and more by davidw on Thursday June 30, 2016 @07:21PM (#12012659)
I would love to see someone take a deep dive into why their Phoenix thing is "so much faster" than with Rails. I mean really look at the whole stack from the VM, to different pieces of the framework like views and DB interaction. Erlang definitely does concurrency well, but it is not that much faster than Ruby in terms of "raw speed". I'd be fascinated to see someone actually do the work and look at where Phoenix is eking out those gains.
Re:Rails 5.0: Action Cable, API mode, and more by anonyfox on Friday July 01, 2016 @02:39AM (#12014243)
Some bigger details why phoenix is so fast despite erlang being a "slow" language:

- macros: fancy syntax and "magic" can be resolved at compile-time. Less work to do on runtime.

- templates: they get handled at compile-time, too, resulting in functions with blobs of binaries. This matters a lot, since a specific template-binary exists only once throughout the application and gets re-used whenever needed. This way you get near instant templating, instead of the usual string processing on every request.

- dispatching code like the routing that must be done on every request is like rails a DSL, but actually a macro, that gets compiled down to basic pattern matches, which is extremely fast.

- the concurrency model is extremely lightweight, handling more requests and/or doing more stuff per request is much more efficient hardware-wise. Indirect performance gain.

Just a few points that have a very noticeably impact, there are probably more. It boils down to the erlang vm's concurrency and pattern matching performance, plus elixir's compile-time macros and the fact that they treat strings as immutable binaries.

Re:Rails 5.0: Action Cable, API mode, and more by davidw on Friday July 01, 2016 @11:32AM (#12016909)
> macros

All well and good, but Erlang/beam code is not that fast.

> templates

Ruby's templates are parsed into code that stays in memory, too, so it's not like they're re-parsed each and every time.

> routing

Perhaps clever use of pattern matching helps here. But my point is: someone should dissect these things in a real-world-ish application to see what's actually true.

> concurrency

Yes, but let's be precise. Everyone knows Erlang's concurrency is way better than Ruby's. The claim was 'fast' though. As well as maintainable, which seems curious given that there are no really old Phoenix apps out there.

Re:Rails 5.0: Action Cable, API mode, and more by anonyfox on Friday July 01, 2016 @12:21PM (#12017430)
> but Erlang/beam code is not that fast.

True, no doubt. You wanted a comparison why phoenix is faster than rails. And simply doing things at compile time reduces work at runtime. In Ruby, all Metaprogramming must be done at runtime, for example via method_missing trickery (been there, done that).

> Ruby's templates are parsed into code that stays in memory, too, so it's not like they're re-parsed each and every time.

This is actually not the same. A single immutable blob of binary (elixir strings) which is shared throughout the whole application can leverage hardware caching better. Jose could answer this probably better than I can do.

> someone should dissect these things in a real-world-ish application to see what's actually true.

Moz.com recently had fun with Elixir [1]. You may also have a look at https://www.youtube.com/watch?v=OxhTQdcieQE from latest RailsConf.

> The claim was 'fast' though

Well at least I know that BEAM processes are far lighter than eg: goroutines. Also there is a per-process GC, so no "stop the world", much smaller units for individual collects, and when a process finishes before the heap grows full, it can be discarded directly.

> maintainable, which seems curious given that there are no really old Phoenix apps out there

Fair enough.

Personally I'd not wait until a software stack is a decade old before even considering it. I have at least worked on Elixir/Phoenix projects for many months now on-off with multiple colleagues, and it was/is still pure joy. Aesthetically pleasing syntax helps (broken window syndrome I guess), plus functional programming style in general, plus phoenix' foundation in "plug" and the clear modularity. "Let it crash" with supervisors also is incredibly robust, and robustness in itself leads to less maintenance costs.

---

[1] https://moz.com/devblog/moz-analytics-db-free/

Re:Rails 5.0: Action Cable, API mode, and more by davidw on Friday July 01, 2016 @12:55PM (#12017770)
All good points. As I keep saying, I'm an Erlang fan. I actually used it at my last job, and have used it on and off since 2004-ish. It definitely has some advantages, but I'm just curious where it's actually beating Rails, and with what kinds of workloads and test methodology and so on.

Stuff like "Erlang processes are lighter" matters in some contexts, but not in a straight up speed contest. It matters a lot when you start trying to handle a bunch of concurrent connections, so maybe that's where we're getting some of the claims from.

Re:Rails 5.0: Action Cable, API mode, and more by anonyfox on Friday July 01, 2016 @02:27PM (#12018523)
I'd say you really should have a look into https://www.youtube.com/watch?v=OxhTQdcieQE . A really great presentation, including numbers and real world backup data, plus conceptual overviews.
Re:Rails 5.0: Action Cable, API mode, and more by davidw on Friday July 01, 2016 @03:25PM (#12019001)
It's pretty good, but a bit hype-y.

Functional programming is not an 'antidote' to having to go back and read old code or necessarily understanding it easily.

It references this:

http://sorentwo.com/2016/02/02/caching-what-is-it-good-for.h...

Which is interesting, but I don't see source code. 1.5-2X is pretty believable, but quite a bit less than "12 times" - which someone quoted here.

Re:Rails 5.0: Action Cable, API mode, and more by anonyfox on Friday July 01, 2016 @04:06PM (#12019268)
I can personally confirm above 10x improvements over rails, but can't Share the code :)

Depends on what you're doing though. Seems to excel when having low CPU intensive workloads but high traffic pressure from my experience.

Re:Rails 5.0: Action Cable, API mode, and more by perishabledave on Friday July 01, 2016 @12:25AM (#12013866)
It sounds like you're undervaluing concurrency. Concurrency is huge for a web application. If you were say doing image manipulation or other DSP where you needed "raw speed" you'd want to choose a language like C, Go, Rust. But in a web application you're handling hundreds, thousands, to millions of requests per second; concurrency is crucial for that kind of throughput. A developer on my team did some quick benchmarks and found that that Phoenix gives an order of magnitude better performance than Rails. Thats not negligible.
Re:Rails 5.0: Action Cable, API mode, and more by davidw on Friday July 01, 2016 @01:23AM (#12014034)
Yes, concurrency is better - way better - in Erlang, but I'd like to see things broken down in detail. Show times with 1 client, 10, 100 etc...
Re:Rails 5.0: Action Cable, API mode, and more by percept on Thursday June 30, 2016 @08:12PM (#12012937)
I was a bit surprised by its performance in the last TechEmpower benchmarks: roughly equivalent to Rails and other Ruby-based solutions (PHP, too).

It could be a case of not yet being optimized for the tests, but I was expecting much more impressive numbers out of the box (particularly after the full-court press on the boards and blogs).

Re:Rails 5.0: Action Cable, API mode, and more by asdf1234 on Thursday June 30, 2016 @10:13PM (#12013445)
The Phoenix tests had a ton of errors and there was no preview run so whoever submitted them wasn't able to fix them. This has happened with a bunch of different languages/frameworks in the past and until the errors in the implementation are sorted out the benchmarks are basically meaningless.

Chris McCord talks about it here https://www.reddit.com/r/elixir/comments/48ke69/any_reason_w...

Re:Rails 5.0: Action Cable, API mode, and more by eric-hu on Friday July 01, 2016 @12:52AM (#12013954)
From what I've read in the comments so far, you won't see it thinking in terms of speed of Erlang vs Ruby. It sounds like the gains come from baked in behavior, so that "Rails + Redis" or "Rails + Redis + nginx" is equivalent to Phoenix alone. I'm still only reading about this, though. No Elixir experience here.
Re:Rails 5.0: Action Cable, API mode, and more by davidw on Friday July 01, 2016 @01:28AM (#12014055)
Erlang definitely does a lot out of the box without needing to rely on other systems and that's a great thing, but we're hearing claims about "fast" and "more maintainable" and I'd like to see more details.

I used Erlang at the last place I worked and like it a lot, but Rails is pretty good too in my book.

Re:Rails 5.0: Action Cable, API mode, and more by dogweather on Tuesday July 05, 2016 @01:13PM (#12037952)
For me, it's "fast" meaning developer time. A typical first pass at a Rails view might be 300ms vs. 300 micro secs in Phoenix. This extra headroom represents hours of optimization I don't need to do, in order to stay under 200ms per request.
Re:Rails 5.0: Action Cable, API mode, and more by bratsche on Thursday June 30, 2016 @07:29PM (#12012699)
I would love to see that too!

The one thing that comes to mind is that since each process has its own isolated memory space, Erlang's GC is not a "stop the universe" kind of thing, the GC can run in parallel with other processes.

(edit: again, this is just intuition on my part, I haven't remotely done the deep dive you're talking about)

Re:Rails 5.0: Action Cable, API mode, and more by fchopin on Thursday June 30, 2016 @08:29PM (#12013009)
What I use Rails for these days is (1) as a backend to our SPAs, so ActiveRecord, Rails controllers, and a view to serve JS assets and CSS via the Asset Pipeline, and (2) to serve Active Admin.

I see there is Ecto, Brunch, and ExAdmin for Phoenix, to cover our primary bases I spoke of, in Elixir/Phoenix.

For those that have switched to Phoenix, and have experience with these three- was it as smooth transition? What are the significant gaps, if any?

Re:Rails 5.0: Action Cable, API mode, and more by RobertKerans on Friday July 01, 2016 @03:45AM (#12014470)
A Devise equivalent. There are a number of alternatives, but I've found them all a little raw: with many Rails projects, I know I can just add Devise, and be confident it'll Just Work with minimal work. Valim said he wasn't interested in building a Devise equivalent for Phoenix - I think the reasoning was that each context is different enough in its own way that a monolithic one-size-fits-all solution like Devise isn't preferable, which is fair enough. But authentication is a pain, and carefully wiring up slightly immature solutions is a little hairy.

I've found this only really applies to CRUD-like, Rails-like projects, so about half of the projects I've built, so YMMV: it's maybe just me making the jump from Rails and expecting things to be more similar than they are.

Ecto is good; it's not quite an ORM, so there were a few WTFs when I tried to do things the same way, but on balance I prefer the Ecto approach; a Linq-like query language I like better than a [somewhat magic] ORM, the way it seperates concerns is good, and (in common with most of Phoenix) the way it works is pretty transparent. Not quite mature yet, though Ecto 2 seems to cover most of the functionality I found to be missing in 1.x.

I work primarily front-end,and I always had issues with the asset pipeline. I've found Brunch to be fantastic - there are always going to be a few issues when dealing with NPM, but other than that, I think they picked the absolute simplest JS-based task runner, and having direct access to the JS ecosystem is great. Brunch has been almost zero-config for me, has Just Worked with only a few `rm -rf node_modules`

Re:Rails 5.0: Action Cable, API mode, and more by rozap on Thursday June 30, 2016 @06:48PM (#12012455)
I think most folks are finding that distribution in an erlang based application is a lot simpler, because you don't need to pull in things like redis for pubsub, memcached for caching, etc etc. erlang solves a bunch of problems in a rather elegant way that are solved in the java/python/ruby world through gobs of duct tape.
Re:Rails 5.0: Action Cable, API mode, and more by davidw on Thursday June 30, 2016 @06:51PM (#12012475)
Good point, but I'd see the actual codebase on a single node as the most important thing for most people. Even with Rails you can do a lot with one server.
Re:Rails 5.0: Action Cable, API mode, and more by Scarbutt on Thursday June 30, 2016 @07:02PM (#12012538)
Performance wise, I wouldn't put Java next to ruby and python, in what workload would the erlang vm beat the jvm?
Re:Rails 5.0: Action Cable, API mode, and more by felixgallo on Thursday June 30, 2016 @07:15PM (#12012623)
low jitter, low latency, high concurrency workloads.
Re:Rails 5.0: Action Cable, API mode, and more by rozap on Thursday June 30, 2016 @07:06PM (#12012563)
I'm talking more about concurrency and distribution models, not raw performance.
Re:Rails 5.0: Action Cable, API mode, and more by dmix on Thursday June 30, 2016 @06:48PM (#12012447)
I find working with functional languages and type systems (w/ dialyzer in this case) makes my projects more maintainable in general. Might just be a personal bias towards them though. Note: I haven't used Phoenix but I'm a fan of Erlang.
Re:Rails 5.0: Action Cable, API mode, and more by bcardarella on Thursday June 30, 2016 @06:58PM (#12012504)
This is mostly an observation I've had of imperative programming vs functional programming. Going back and creating the state of the application in my head is easier when I don't have to find out what else the code is affecting.