Rails 5.0: Action Cable, API mode, and more
weblog.rubyonrails.org
weblog.rubyonrails.org
Sales actually just launched on Tuesday (announcement here: https://news.learnenough.com/rails-5-edition-of-rails-tutori...), and you can pick up your copy of the new 4th edition here:
http://railstutorial.org/code/launch
That link includes a 20% launch discount, which expires tonight at midnight PDT.
As with previous versions, the new edition focuses on the core principles of web development, so there isn't much Rails 5–specific material in the update, but I am planning standalone Learn Enough tutorials on things like Action Cable and Rails API (http://learnenough.com/).
[1]http://softwareengineeringdaily.com/2016/01/11/learning-rail...
Thank you so much Michael.
Thank you so much for keeping the tutorial alive!
Here are the docs if anyone is interested: http://edgeapi.rubyonrails.org/classes/ActiveRecord/Attribut...
Definitely also checkout the episodes where he talks about Diesel.
You can also just ping me on Twitter and I can talk about it more. :)
http://confreaks.tv/videos/railsconf2016-rails-5-features-yo...
Any framework can be tuned to do anything. Rails right now is the only truly comprehensive framework with tight integrations to Coffee, LESS, CSS, etc. As someone who is writing his own framework in Scala, I learned this the hard way after under-estimating how much of work is already done for you in Rails.
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.
As a polite reminder, I'd like to link to an old comment of mine I made at the time of Rails 4.2:
https://news.ycombinator.com/item?id=8201244
Have a great weekend everyone!
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.
> You're right basically, but the migration wave from
> rails to phoenix has noticeably started, and
> it shows.
People have previously said this about: * Clojure
* Node
* Go
And lots of things before that.And then there's its competitor, Arachne: http://arachne-framework.org/
While you're around: Elixir/Erlang in itself is a rather slow language when it comes to number crunching performance. The canonical way currently is to write NIFs in C for these parts. But if this native code crashes, the reliability promise of BEAM goes out the window. For me it would make much more sense to write native extensions in Rust. Have you ever considered to include a plugin to "mix", Elixir's build tool, that allows one to ship Rust source files alongside the Elixir application, which then at compile time fetch a Rust compiler, compiles the code on the current platform and generates a NIF? This would be so huge.
Uh...
"Drop-in replacement is a term used in computer science and other fields. It refers to the ability to replace one hardware (or software) component with another one without any other code or configuration changes being required and resulting in no negative impacts."
That's not the case at all with Phoenix, nice as it may be.
> But this time (tm) it's different.
Everyone always says that :) That said, your sibling comment makes good points here. > While you're around:
I think this idea is _really_ cool, but I'm not equipped to build such a thing, since I haven't had enough experience with them yet. I agree that that would be super cool.Truth to be said: there were some good languages but never good frameworks. After rails it's really hard to touch these semi-baked flawed "rails copies". And Phoenix is the first framework that not only replicates good rails sides (other web frameworks failing even that) but also fixes most (actually important) rails issues.
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).
We have release various Passenger updates to ensure that Passenger plays well with Rails 5, Action Cable etc:
https://blog.phusion.nl/2016/02/18/passenger-5-0-25/
https://www.phusionpassenger.com/library/config/nginx/action...
However we found a bug in Action Cable yesterday which may cause issues with app servers such as Passenger and Puma. Unfortunately the fix didn't make it into 1.0. I recommend anybody who uses Action Cable to apply our patch locally for now: https://github.com/rails/rails/pull/25615
Feel free to look at the relevant merge requests and use them as guides to upgrade your own apps :) We're still on 4.2.6 since we have a few gems we're waiting on, but I hope to change that in a month or two!
Favorite features are probably the various performance improvements and underlying improvements to the framework, as well as quiet_assets being moved into sprockets-rails.
I also wanted to give a shoutout to BigBinary's Rails 5 series, since it's been great for finding out about new features[2].
[1]: https://gitlab.com/gitlab-org/gitlab-ce/issues/14286#note_42... [2]: http://blog.bigbinary.com/categories/Rails-5/
Don't get me wrong, I think Rails is an amazing technology but it doesn't fit the use cases and demands our clients have today.
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.
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.
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)
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).
Chris McCord talks about it here https://www.reddit.com/r/elixir/comments/48ke69/any_reason_w...
I used Erlang at the last place I worked and like it a lot, but Rails is pretty good too in my book.
- 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.
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.
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.
---
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.
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.
Depends on what you're doing though. Seems to excel when having low CPU intensive workloads but high traffic pressure from my experience.
Here's that slide, I believe: http://i.imgur.com/QzTCJS8.png
This too shall pass.
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.
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?
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`
We run 100s of dynos for our service, but could probably run just a couple if we moved to elixir/otp.
On one project my team was convinced that Redis was our bottleneck. Profiling was showing that Redis calls were where the most time was spent. I spent some time looking at the redis-rb source and it does a lot of block nesting (4 or 5 levels for every call, IIRC). So, I tried replacing the redis-rb client with something a bit lower level and our throughput doubled. It turned out that all that block processing cost as much as the network call did.
I suppose this isn't all that new: many performance issues are really a "death by 1,000 cuts" situation. Oftentimes your profiler can lead you astray.
In situations where a blocking redis client like redis-rb doesn't interfere with other running code (synchronous web requests), I've found zero performance issues with redis-rb (latency caused by redis is measured in single digits, usually < 5ms).
My intention wasn't to rail against redis-rb. It's written very nice, idiomatic Ruby. The faster solution was decidedly less Ruby-like. I was just suggesting that even when your profile looks to be telling you the DB is to blame, you should probably prod a bit more.
ActiveRecord is as another case where I've hit performance issues. I had just swapped out most AR usage for Sequel, so my data on that is probably well out-of-date. But, for us, materializing rows as full DAOs was often a very costly process that could dominate the cost of the DB query.
I see a lot of comments here about Elixir/Phoenix. Is the performance gain really that big? I currently serve 2-3 mil requests on Rails per day on around $200 worth of servers with at least one database call per request. In defense of Rails, there are so many libraries out there already built I can get an app up and running fairly quickly. I really think it's a matter whether the tool fits the bill.
If you spend $200 you could theoretically hosting the same product on $50 worth of hardware.
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 trace, debug, hotpatch a running system. Some parts of the cluster would be crashing and restarting for a while, and there would be no need to wake everyone up. It can be fixed in the morning kinda deal.
An interesting observation to think about -- importance of fault tollerance grows as quickly or quicker than concurrency. What I mean is if you have a service that handles more concurrent requests, it now becomes are lot more important to have solid fault tollerance, because a single failed request, maybe causing a segfault, can kill all of them for example.
That is a bit hard to understand unless you see it practice. You can think of it this way -- it doesn't matter if the system can handle 100K requests / second. If it is not fault tollerant, when it crashes it handles 0 requests / second. Depending how crappy the uptime is, you can average those number and get something that's pretty low.
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 the vocal early adopting crowd. If it makes your team vastly more productive, that sounds like a great win for you. If you subjectively like it better, that's also perfectly valid. But 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.
Get off my lawn.
Not sure what your point it. I shared my experience working with systems, you can share yours (if you have any).
Yes, you can write any of the stuff in assembly. Erlang, Java, Rust, all can be written in assembly. You can serve web pages in that too, and even create distributed system by twiddling bits directly in the network card's receive buffer.
> This stuff is what frustrates me most about the vocal early adopting crowd.
Lol, early adopters ;-) Erlang turned 30 this year. It is probably older than the median age of people reading this comment.
> Again, this isn't language or framwork-specific.
Again, point to where I said "nothing like this can be done in any other frameworks". Code reload -- can do it in Java. But you'll get paper cuts. Python -- can spawn an OS process to get fault isolation, but, can only spawn so many. Distribution -- spin another instance in AWS, talk gRPC with it, but now you are paying more money and have another library to maintain.
> But citing resilience, efficiency, scalability, and handling traffic spikes seems thin
Well would you prefer a whitepaper? It is an informal conversation. Do you ask for proof / benchmarks / whitepapers every time you talk to someone at a meetup? That must be fun.
But if you want a fun reference, pick up your smartphone, navigate to a web page. Does it work? Good. There is 50% chance it works because Erlang works. There you go, scalability, resilience and efficiency ;-) can share that at the next meetup's beer hour.
> 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.
A greenfield project? Sure why not, it's a great choice.
Not to say you shouldn't choose this solution, just do it with an eye to the future.
I am relatively new to rails and have been astonished at the number of high quality gems that I can drop in and accelerate development. If I need to build something, my first step is always to google for a gem and see if some kind soul has already solved my problem.
Drupal had some of the same rich libraries, but in my short time working with it, I felt less like a software engineer and more like a software mechanic, piecing together pre built parts. For whatever reason, perhaps rhe emphasis on TDD,rails doesn't make me feel like that (which makes work more enjoyable for me).
All this is to say, I don't have any idea what the elixir/Phoenix ecosystem is like, but until it is sizable, rails has an edge in my book.
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 applications that spend most of the time in the DB I am not sure how switching languages would give you 12x improvement.
For non-dynamic stuff what is behind rendering don't matter anyway cause you can cache before it even hits the app.
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.
For example, we use pgbouncer transaction pooling, so our connection counts are low. Tons of caching is done in NGINX and first middleware in the stack, we are not afraid of using SQL where needed for performance reasons and so on.
For an application that is taking data from a database and turning into JSON or HTML, spending 50% of the time in the database is not really a crime of bad architecture. In fact even when we built Stack Overflow in superfast C# we often saw a similar breakdown.
I just really object to the sentiment of "abandon ship" Y is 12x faster.
Looking forward to Heroku working out of the box[1] and quiet assets moved to core[2]
Smart money at this point seems like a significant portion of the Rails community could begin moving to Elixir/Phoenix over the coming years. The advantages from a language/VM level just look impossible for Ruby to overcome, along with a blub effect kicking in.
*edit: For clarification, I use Ruby every day and I think its awesome! However, I don't want to see it lose popularity the way Pearl did. I'm concerned that if the language doesn't continue to innovate and improve, that I will lose ground. Lots of new languages have similarly great ergonomics, but get concurrency right, or are faster. I don't think improved concurrency is really on the table for Ruby 3, so I think 3x3 is going to be critical to the long term future of the language.
But, that's just my prediction and its likely wrong.
http://engineering.appfolio.com/appfolio-engineering/2015/11...
https://blog.heroku.com/where_will_ruby_go_now_talking_with_... https://www.reddit.com/r/ruby/comments/3tje5a/ruby_3x3_ruby_...
I don't know how mature it is, but couldn't jruby be the answer to this?
It's the same reason you'd never find a modern CPU without multiple layers of caching.
That said, I'd call it a fundamental architecture requirement (and one you can't really avoid anyway), given fundamental limitations imposed by the speed of light.
Which is exactly what makes Rails 4 and 5 a reasonable choice for slow-moving projects on a budget (i.e. no money to pay for massive library updates every N months).
I think the vocal early adopters are going to jump ship, if they haven't already. But I'm more likely than ever to start new projects on Rails.
Of course, if there's anything in particular that you are missing from Rails, then the lack of fundamental changes can be a showstopper.
Post.where('id = 1').or(Post.where('id = 2'))Another implementation is Post.where(id: [1, 2]) which is SELECT * FROM posts WHERE id IN (1, 2). I guess a db would compile it into exactly the same code (dbs use different terms but that's what it is) but the performances could be different inside AR/Arel.
Works in Rails 4
Post.where(id: 1).or Post.joins(:author).where(author: { name: 'John' }) Post.join(:author).where(:author__name => "John")
(the above is purely from memory and may have syntax errors).In any case, it lets you drop into raw SQL as a last resort.
Post.where(id: 1).or Post.joins(:author).where(author: { name: 'John' })
ArgumentError: Relation passed to #or must be structurally compatible. Incompatible values: [:joins, :references]
It appears that only the filter clauses are allowed to be different (similar errors if :select, :order, :group, :limit are different), in which case it's no more powerful than Sequel, just more of a pain to use. You can easily implement ActiveRecord's behavior in Sequel if you want to combine filter clauses for arbitrary datasets: ds = Post.where(id: 2)
Post.where(id: 1).or(ds.opts[:where])
It's also interesting what happens if you mix where and having clauses (I'm not saying it doesn't make sense, but it may bite someone): Post.where(id: 1).or(Post.having(id: 2)).to_sql
# SELECT "posts".* FROM "posts" Post.where(id: 1).or(Sequel.&({:id=>2}, {:name=>'Foo'}))
# SELECT * FROM posts WHERE ((id = 1) OR ((id = 2) AND (name = 'Foo')))Big fan of Sequel; it's super sleek. As a side-note to Jeremy's comment, while (i guess) he used Sequel.& to demonstrate that OR and AND conditions can be combined freely, there are more succinct ways of expressing that particular query:
# Using the a "virtual row" block:
Post.where(id: 1).or{(id =~ 2) & (name =~ 'Foo')}
# Or, if you don't fancy that kind of block magic, simply passing a Hash,
# the same way as with .where
Post.where(id: 1).or(id: 2, name: 'Foo')That's rad.
Good work rails team!
I'm glad that rails has been looking at projects like Phoenix for
inspiration
Other way around.Phoenix was explicitly inspired by Rails and founded by Rails core members. Elixir was first created by a Rails core member. Phoenix is the performance-really-matters successor to Rails.
So you want a list it seems
> l=[1,2,3]
> [h | t] = l
[1, 2, 3]
> h
1
> t
[2, 3]
> If I want to process data as a large indexed array Elixir isn't going to help meBut neither will Python. You'd want a large indexed array you probably want numpy.
See now you are revealing a bit more about your usecase that's helpful. So you have large amount of data and want to query it and process it. In that case you might want to check out ETS. The nice benefit, you have have cool matching or query list comprehensions of it. Can also access it concurrently from multiple processes:
http://elixir-lang.org/getting-started/mix-otp/ets.html
This is the Erlang side of it:
http://learnyousomeerlang.com/ets
> but the question here is whether it is deficient in other areas, making it too much of a niche language.
Of course it is deficient. C is deficient. Java, C++ is they all. Every language is deficient in some way. I haven't found a Perfect one yet. Still looking... Maybe Rust, who knows, still struggling to learn it.
Python comes with array.array¹ natively.
There is no native array syntax, but there are array functions in the stdlib:
> making it too much of a niche language.
No language will be the "one true language" that excels at everything.
I used Erlang for many years, and in the last one full time. Not one time have I needed an "array". It seems you picked one odd feature no-one uses and are upset about it, I thik it is just a small misunderstand, if you share a bit more about what you are trying to do, you'll get more help.
> I just find this disappointing
Did you explain your use case to them. If you just said "I need an array" I see their response as perfectly rational. And from what I've seen, that is probably the friendliest and most approachable community, especially for newcomers.
If it's iterated over sequentially then a list works perfectly.
If it's random access then a map works.
I think it is John Hughes that said "The real question is not 'when should i use functional programming?' but 'when should i use imperative programming?' And the answer is 'When you need random access and complete control of your memory'"
I suspect that to use Elixir, you need to study a new way of doing things first. Then you'll see arrays in a different light.
I suspect that Elixir's maps are not different in this regard, as are Erlang's arrays, or maps in Haskell or OCaml. This is the canonical way to make an immutable map (see picture here: http://programmers.stackexchange.com/questions/195718/functi...).
For certain types of programming - generally in lower-level languages - arrays can be essential for performance. But then my assumption is that if you needed that kind of performance, you'd be using those languages.
So outside of performance, what's the functional difference between an actual array implementation - and a thing that looks, walks, and quacks like a duck?
Because of the immutable data, your best hopes are actually vectors or maps.
Btw, the erlang library you mention implements arrays on top of a tree of 10-ary(-ish) tuples. It'd need to be measured, but I'd be willing to bet that the native maps are faster at access, insert, and delete. The maps are implemented in C, and worst case for all operations would be O(n log n) or similar.
Complaining in the abstract isn't helpful.
If Elixir had arrays, why would that be better than using other enumerables like lists or tuples?
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.
However there are other school of thoughts and not everybody likes the Rails way. It's fair and it's a big world with space for every opinion and tool.
I guess being implicit just makes it harder to find out which part of abstraction is leaking when it happens..
But again I'm not a good rails programmer. I was just never a fan of how conventions play such a big part, and was not well documented.
Now, let the job of upgrading begins.
Also, I love how everyone found a feature they've been waiting for and celebrating it. Rails, always bring joy (pain comes in few years ;) )
This will be great for, eg, creating reports or receipts in background jobs.
48 contributors total (Yes, Andrew is doing most) - https://github.com/andrewgodwin/channels/graphs/contributors
It sounds like it wasn't decided to keep 3rd party as much as decided not to not combine yet:
> The feedback I got during the proposal process for putting Channels into Django 1.10 (it did not get in before the deadline, but will still be developed as an external app with 1.10) was valuable; some of the more recent changes and work, such as backpressure and the local-and-remote Redis backend, are based on feedback from that process, and I imagine more tweaks will emerge as more things get deployed on Channels.
https://www.aeracode.org/2016/6/16/philosophy-channels/
You can still use Channels today in 1.8–1.10.
https://blog.heroku.com/in_deep_with_django_channels_the_fut...
This project is very much in the spotlight, was heavily discussed at PyCon, etc. I don't think it's going anywhere.
If it's a big hit like South was, it'll get rolled in and we won't have to immediately start deprecating things due to an un-tried design.
https://groups.google.com/forum/#!topic/django-developers/QR...
Here's why you shouldn't be jealous: https://www.cvedetails.com/product/22568/Rubyonrails-Ruby-On...
There are still remote code execution and even SQL injection flaws being discovered in Rails.
The dreadful security record of Rails really seems like the elephant in the room.
Compare to Django https://www.cvedetails.com/product/18211/Djangoproject-Djang...
WebSockets would have been a cool addition four years ago. There is little compelling case for new development. Sorry to be so harsh.
Besides which, I can't see that a switch from Rails to Node is going to have any strong advantage if you are equally proficient in each. If they're really about the same, this would boil down to "I like JS more than Ruby," which is not about the technology so much as personal feelings.