Live data from Hacker News

Rails 5.0: Action Cable, API mode, and more

weblog.rubyonrails.org

161–170 of 225 posts

Re: Rails 5.0: Action Cable, API mode, and more

#161
Is anyone aware of a site that the memory footprints of default Rails apps? I know that this may not be the greatest indication of the memory footprint in an actual running app, but I feel it'd still be interesting data. It'd have the be segmented by ruby version, of course.

Re: Rails 5.0: Action Cable, API mode, and more

#162
post #156

I see a lot of pro-Erlang/Phoenix pushing in here, which is (as a polite reminder) an announcement about the rails framework. Not to say that one shouldn't, just that I think it's deviating from the main topic in hand. Interestingly, I wanted to find out what's the real reason behind these pushes towards Erlang/Phoenix and I realised the discussion is mostly around how you can save a few bucks worth $20-50 by opting…

> I see a lot of pro-Erlang/Phoenix pushing in here, which is (as a polite reminder) an announcement about the rails framework. Not to say that one shouldn't, just that I think it's deviating from the main topic in hand.

You're right basically, but the migration wave from rails to phoenix has noticeably started, and it shows.

> Interestingly, I wanted to find out what's the real reason behind these pushes towards Erlang/Phoenix and I realised the discussion is mostly around how you can save a few bucks worth $20-50 by opting for a faster programming language.

Actually, the high performance stuff and Rails-y organization of phoenix is just something to give you immediate benefits and a sense of familiarity. It attracts people and give them a reason to try it out. Beginners praise it, but it's by far not the actual reason to keep pushing phoenix. Just like

"hey, it works like rails, you can do everything with it like rails does, so there is just a small learning curve and we have orders of magnitude better performance!"

> Any framework can be tuned to do anything.

Yes this is true. You can also write OOP assembly or use vim as a bitmap editor like paint. The point is: while you can theoretically do everything with mostly everything, the results will differ a lot and the way to these results will vary a lot.

With phoenix, there is no "magic" (people complain about this in rails!), everything is simple, explicit and straightforward. You also do not need many third-party tools like redis, sidekiq or memcached. This greatly simplifies the application code, reducing brittle constructs/bindings.

Currently, Rails still has the edge when it comes to gems, many things are readily available. This helps when "getting started" for typical app scenarios.

But a few weeks in, maintenance is the most important factor when it comes to development speed. Here Phoenix wins by a large margin. Less dependencies, easier code, less performance tuning, less bugs (compiler/dialyzer/... arguably).

> Rails right now is the only truly comprehensive framework with tight integrations to Coffee, LESS, CSS, etc.

The asset pipeline of rails can be quite a pain in the ass. Phoenix went a different way by integrating brunch, the probably easiest of the node.js task runners, which mostly doesn't even need custom configurations. (npm install --save brunch-less, your less files are integrated as you'd expect. Same for coffeescript, ...).

> If you run a business, then all this small talk shouldn't matter as much as how profitable you are. In the end, if your business failed because of your choice of framework (which usually reflects your philosophy), then you need to fix your business model and not the framework.

The development speed does matter. when you waste time optimizing things, fixing bugs with dependencies or stuff like that, you aren't shipping features. Moving fast is crucial for startups.

And then there is scaling. Phoenix is known to handle large loads with ease, and probably most startups can go a long way before they even have to consider horizontal scaling. Not having to think about this is worth more than the money you'd throw at servers to scale up rails (which, as you said, isn't needed in that quantity in phoenix either).

And just a personal note on top of this: Once functional programming/elixir "clicks" for you, translating business requirements into working code is so much easier as functional data transformation with pipes than having to deal with forests of class structures. For many cases, it just makes more sense (and is easier to read, maintain, extend and test).

---

Finally, the actual big win of phoenix is BEAM/OTP. Performance aside, the thought model of OTP just makes so much sense and simplifies building reliable, distributing systems a lot. I'd argue that OTP is the true reason people are blown away, elixir simplifies the syntax/reduces boilerplate, and phoenix on top makes getting started a breeze, looks like rails on the surface, and once you get into how OTP works, you're hooked.

Re: Rails 5.0: Action Cable, API mode, and more

#163
post #156

I see a lot of pro-Erlang/Phoenix pushing in here, which is (as a polite reminder) an announcement about the rails framework. Not to say that one shouldn't, just that I think it's deviating from the main topic in hand. Interestingly, I wanted to find out what's the real reason behind these pushes towards Erlang/Phoenix and I realised the discussion is mostly around how you can save a few bucks worth $20-50 by opting…

I personally dislike Rails quite a bit, but I still agree with you. Personally I think the main choice of language and framework for web sites should be down to what you can easily hire developers that will be happy for.

I've chosen PHP for that in the past despite detesting it, at a time when Rails did not have enough of an eco-system. I might pick Rails now, even if I personally dislike it. I'd be concerned with niche alternatives out of consideration for whether or not I'd be able to hire replacements/additions.

Speed concerns would be extremely far down the list... I have worked on systems where speed for some APIs would necessitate something else, but it is very rarely the case for web apps.

I also do devops consulting, and at least for my customers it is extremely rare for the dynamic parts of the web frontends to make up sufficiently large portions of the overall hosting costs to be worth worrying about.

In the rare instances it is, it usually turns out that people have used a non-standard setup letting Rails serve up static content too, and/or have not made any attempt at doing even basic caching.

Doesn't mean you shouldn't consider something else than Rails. I personally rarely use Rails if I can avoid it. But most of the reasons for picking one of the other are excuses to obscure personal preference. Personal preference is fine. It's a perfectly good reason to want one over the other, as long as it meets other needs.

But people should realise it rarely actually makes that much difference, so unless you have very specific use cases and benchmarks to back it up, I'll think it's a bullshit excuse if someone comes to me and says they need X because of speed (in the context of web apps).

Re: Rails 5.0: Action Cable, API mode, and more

#164
post #151

Earlier quoted context omitted.

It's around 12 times faster in the general sense. Your mileage may vary. If you spend $200 you could theoretically hosting the same product on $50 worth of hardware.

jeez where are those numbers coming from :) For Discourse which we host in general we spend HALF the time in database calls and say 20-30% of the time in ActiveRecord bullshit. Lets say we erased all of the app cost using some magic, we would still only be saving 50%, so twice as fast, now erase some ORM bullshit, say another 50% faster, so at a super ambitious totally unrealistic setting we could be 4x faster. For a…

With ecto you tend to write less n+1 queries(if any ;)) if you use the from: query syntax, thus you can also save db time, there you have it.

Re: Rails 5.0: Action Cable, API mode, and more

#165

Earlier quoted context omitted.

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 serve…

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.

Here's a writeup of the experiment: http://www.phoenixframework.org/blog/the-road-to-2-million-w...

Re: Rails 5.0: Action Cable, API mode, and more

#166
post #67

By looking at the comments you'd assume a new version of Phoenix got released.

Agreed. It's getting pretty annoying. Every Rails post that hits the front page now feels like it's getting hijacked/side-tracked by Elixir/Phoenix evangelists.

I can remember way back when it was the vocal Rails evangelists doing the hijacking :)

Re: Rails 5.0: Action Cable, API mode, and more

#167
post #94

Earlier quoted context omitted.

> That saving of $150 is equivalent to one hour of pro dev work time. Fair point, unless you have more customers. Then it can start to add up quickly. And by customers it means requests as well. Being able to handle large traffic spikes and continous connections is a game change from what I found. Moreover. A huge benefit is using the BEAM VM, I use Erlang (but same VM) and I have seen major advantages being able to…

> Being able to handle large traffic spikes and continous connections is a game change from what I found This isn't specific to Elixir/Phoenix/Beam. > Some parts of the cluster would be crashing and restarting for a while, and there would be no need to wake everyone up Like any well-designed system that separates concerns. Again, this isn't language or framwork-specific. This stuff is what frustrates me most about th…

> This isn't specific to Elixir/Phoenix/Beam

> Like any well-designed system that separates concerns. Again, this isn't language or framwork-specific.

While it is true you can implement those systems in pretty much any turing complete language, we expect some languages and frameworks to make it simpler to write certain kinds of systems. For example, doing scientific calculations in Python or Julia is much easier than in Ruby. It it not impossible to do in Ruby but that's just how things are today. Since Erlang was designed for handling millions of connections in a fault-tolerant and scalable fashion, we expect it to shine in the areas previous listed.

> citing resilience, efficiency, scalability, and handling traffic spikes seems thin -- these are all things that can easily be attained with just about any well-factored system on any number of languages/frameworks.

Easily attainable? Err... no? Depending on which system you want to build, it is hard on all languages and Erlang (or Akka or whatever) is going to make it quantitatively less harder.

If your reference point is classical web applications that depend on the database, you still have a single point of failure (even when using primary and replicas). You could use primary-primary replication but that is still a world of pain and definitely not easy. Maybe that's fine for the applications you are building but that does not even scratch the requirements of building distributed systems at scale (and your app server talking to the database is a distributed system).

But we don't even need to go that far to see the benefits of Erlang, Elixir, Clojure, Go, etc. The fact those languages enable developers to use all of their machine resources efficiently should be enough reason for moving on. Rails developers complain about slow boot times, slow test suites, while using only 25% percent of their machine resources (1 of 4 cores, for example). The languages mentioned above have abstractions that make developers more productive and yet they refuse to adapt. We saw this happening with the adoption of garbage collectors and it is only a matter of time for us to take concurrency for granted as we do with memory management.

Re: Rails 5.0: Action Cable, API mode, and more

#169
post #133

Earlier quoted context omitted.

It would be better because lists are not accessible by index and tuples are only designed for small amounts of data.

...but why do you want to access it by index? Since you refuse to be more specific, it sounds like you're just not willing to learn the language and the way problems are solved with it. Expecting mutable C-type arrays in elixir/erlang is like expecting classes and lambdas in an assembly language. It's just not a good fit for what the language was designed to do.

not the OP, but I've had a side project in Elixir and often I wanted to browse/play with some of the last saved models in repl. When I get the collection using `ecto`'s `Repo.all..` I can't just `bets[4]` or `bets[-2]`, I have to do weird gymnastics like `hd(tl(bets |> Enum.reverse))`

Re: Rails 5.0: Action Cable, API mode, and more

#170
post #151

Earlier quoted context omitted.

It's around 12 times faster in the general sense. Your mileage may vary. If you spend $200 you could theoretically hosting the same product on $50 worth of hardware.

jeez where are those numbers coming from :) For Discourse which we host in general we spend HALF the time in database calls and say 20-30% of the time in ActiveRecord bullshit. Lets say we erased all of the app cost using some magic, we would still only be saving 50%, so twice as fast, now erase some ORM bullshit, say another 50% faster, so at a super ambitious totally unrealistic setting we could be 4x faster. For a…

I would say languages that can leverage concurrency and do pooling well will generally put less pressure on the database for the same load.

Rails in particular is very wasteful in terms of connection management, typically checking out the database connection for the duration of the whole request. If you have a machine with 4 cores, one of Rails deployments would start 4 processes each with 10 database connections. So everything you can cache at the connection level (like prepared statements) is now spread through 40 connections across 4 different processes. I believe servers that rely on copy-on-write wouldn't reuse the cache at all.

Using Erlang/Elixir/Scala, you will start a single instance that will multiplex requests across all cores and sharing the same pool. This typically means you have smaller pools, specially if you are not checking out connections for the duration of the whole request, and you can leverage database caches more efficiently, effectively putting less pressure in the database.

Not only that, proper connection pools can actually foresee when requests are not going to be served on time because the database is under high load and avoid sending the load to the database in the first place. We are using such implementation in our ad-serving Erlang system (https://github.com/fishcakez/sbroker) although there is a lot of interesting queue theory regarding sojourn times. Those requests would timeout anyway but the pool can foresee that with high precision and avoid making the database even slower.

In other words, when you say "half of the time is spent in database", it is always worth asking how much of that time is a consequence of how you are interacting with the database in the first place.

Another aspect to consider is if the language (or framework) you are using allow you to depend less on the database. For example, by processing jobs concurrently instead of storing them on Redis/DB, by building distributed clusters instead of pushing broadcasts to third party systems, etc.

Post reply on HN