by falcolas · 9y ago · 0 comments
I think the problem is that all of the focus arrows in on X vs Y, and not "rewrote the application". My opinion, and my experience, has demonstrated that once you understand the domain, a re-write in any language (including the original) is going to result in an improvement of similar magnitude.
They could have re-written it in Cobol and probably seen an improvement of similar magnitude.
But of course, "Y is n-times better than X" makes for a better headline and looks great on a Key Result slide...
"tl;dr Phoenix showed 10.63x more throughput over Rails when performing the same task, with a fraction of CPU load"
https://littlelines.com/blog/2014/07/08/elixir-vs-ruby-showd...
You can tack on a Phoenix app on top of a Rails app's database and immediately get big improvements as Rails can be a bottleneck.
Sure. So is Java, C#, C, C++, Haskell, Node.js, F#... I could go on. But let's be honest with each other here. What is the real chances that their speedups were really due to a computation bottleneck? And frankly, if it was due to a computation bottleneck, a language on the Beam VM was probably a bad choice.
> get big improvements as Rails can be a bottleneck.
Rails can be a bottleneck. It probably wasn't, though. I can (and have) take an average web app and short circuited a re-write by adding a few choice indexes to the DB. Or I could rearchitect it and move some data processing outside of the critical response sections and do the same. Or I could move a few choice resources onto CDNs and improve end user performance. Or do better compression on PNGs... Or change an O(n) function into a O(log(n)) function...
The list of potential improvements that have nothing to do with the speed of the language in question is almost endless. Ruby and RoR are pretty easy to scale, and if I were a project manager, I would personally have a hard time justifying limiting my hiring pool for the sake of a mere 8x speedup (unless I was honestly operating at a really silly scale).
Seems like you can choose either rails or ecto to manage DB migrations, but not use both simultaneously. This makes migrating to elixir more challenging.
I have this software that I've been rewriting since I was in university---so about 16 years of rewrites give or take.
Every time I pick up a new language, I rewrite it in the new language. It's an image gallery with bells and whistles, talking to databases, and video conversion. It's not totally trivial.
What can I tell you [1]?
My Java version that I wrote as a 2nd year student was the fastest overall for the next 8 years. Rewrites in Smalltalk, PHP, and Ruby were all worse by many orders of magnitudes. The Haskel rewrite actually made it perform worse [2]. Architecturally they were 'better', but that's only API expression.
The only time I've gotten a 'win' is when I replaced the core database technology (moved from Postgres to Elasticsearch), replaced caching tech (moved from Redis in App-layer to Redis in Nginx) and with Elixir (like Java its fast enough that there's no need for caching).
Elixir has a lot of built in tools and libraries that make handling concurrency a breeze. To give an analogy, it's like working with Lua in Nginx---it feels like you are writing your application right inside of the webservers event loop.
[1] Disclaimer: I am a language hipster, and Elixir is the last language I tried.
[2] Haskel and I do not get along. Odd really. I get along with other functional languages.
That said, cool set of experiments, and IMO a great way to learn new languages.
It'd be interesting too see how well the PHP version does now adays. It was written in 2007, PHP 5.1, and the main issue back then was memory consumption when handling multiple processes. I've heard PHP 8 is much better in that respect, with lower amounts of memory used in name brand applications like Worpdress.
Even if not, I love this idea for learning new toolsets.
Nope, I just fell in love with a class project and expanded it greatly.
If you decide to go this route, I'd suggest picking an old class project too. Class projects are pretty much cut down to whatever a student can build within 2 months, taking into account that their time is split 5 different ways and they are inexperienced in the language.
It's the perfect amount of depth so you're not writing a toy project, but you are also not overwhelmed and consider this a real "side project" or 2nd job.
If you want something smaller---do a chat app. They're dead simple, and will teach you the network stack of whatever language you are using. Add some bells and whistles like image sharing to make it like Yahoo 2.0, and you'll have something fairly meaty.
It is easy to paint everything with ones or zeros but it is most likely a combination of factors.
A team with more knowledge of the domain, a management willing to try new technologies and a technology that excels at concurrency, which seems to be the problem they had at hand, sounds like a good combination for success.
Ruby is, sadly, just slow. From my testing, Elixir/Phoenix is out of the gate 10x faster than Rails. Now, they saw a 30x speedup here, so I wouldn't be surprised if some of that came from a rewrite, but it's definitely not the case that all of it was.
There's a lot of optimizations which had a larger effect on the speedup than the choice of language.
The way Rails apps often work is that something like unicorn is used to maintain a pool of worker rails processes, which handle requests synchronously. That worker process will block while it waits for IO requests such as DB and HTTP requests.
In this model, the worker memory footprint can end up being the problem, rather than speed of execution. Particularly in large Rails with many gems, loading the application can take up to hundreds of MB. This sets a fixed limit for the number of concurrent workers/requests.
Rails doesn't _have_ to be used this way, but trying to write a concurrent-safe application in Ruby/Rails can be an uphill battle, because many gems do not work this way.
Elixir does not have this constraint, because only a small part of the system (a single actor) is blocked waiting on I/O. This makes it much easier to support many more concurrent requests.
Accessing a slow DB in elixir will be faster than accessing a slow DB in ruby.
You're not wrong - that's certainly a factor - but Elixir is also just massively faster.
Yes, understanding the problem domain helps. But we already knew the domain and had done refractors in Ruby before then: this isn't our first rodeo ;)
Elixir is just much better suited to the highly concurrent tasks we use it for. Seeing 5-10ms response times on some of our services would just not be reasonable in Ruby/Rails. We know - we tried!
But you're not wrong: understanding the problem IS key to building an efficient solution. It's just that the tools you use will also have an impact. Elixir is a great tool.