Twitter jilts Ruby for Scala
theregister.co.uk
theregister.co.uk
I am curious though whether they tried running their Ruby code using JRuby ... if the bottlenecks were (as stated in the article) in the ruby VM they might have got the same result just by switching VMs (pure speculation).
And ...
> "The biggest selling point for certain organizations is that Scala is 100 per cent compatible with your existing JVM code.
No, it's not. There are problems with quite important features like annotations etc. which are now very important in the java EE space but Scala cannot do them. This was one reason I've used Groovy so far in a lot of situations.
Having said that - I'm seriously looking at Scala because groovy has plenty of faults: the complete lack of any static type checking at compile time and very poor IDE support and error reporting all weigh down on the productivity benefits to the point where it's sometimes a net negative. Scala could end up being the best of all worlds.
That would be a question for the journalist who made it up ;) I am sure the answer was "cause it sounded cool !".
Without regard to the tone of the article though, Scala and Lift are worth spending some time with.
Lift still has a ways to go in terms of providing a turnkey stack in the same vein as a Rails or Merb stack. If you thought putting together a Ruby dev environment had a lot of pieces, get ready for Lift...not so much Lift's fault as its the nature of the heavyweight JVM toolset world.
That said, most real-world uses of nested annotations in Java can also be configured with XML (I know, yuck). Or you can always write a wrapper interface in Java and use that from Scala, since Scala supports mixed compilation projects. Needing nested annotations in Scala won't be a show-stopper, just inconvenient.
Unless there are some major changes in Ruby (MORE than 1.9), I believe that it will be relegated to simple web applications, and never really be good at processing tons of data.
And honestly, isn't Ruby really just about prototyping? I admit, its great for startups who have nil for cash that need to get something written QUICK (to get money from investors), but once you cross that threshold, why not write it over with a language designed for efficiency?
Beyond that, a lot of the metaprogramming features that make Ruby cool are also expensive when done repetitively.
Also, Ruby's threads REALLY suck. And it has impossible to track down memory leaks in the interpreter. Ask mojombo about fun with those.
For my serious apps, I typically write the front end in JRuby on Rails, and migrate code back into Java as it stabilizes and/or needs more performance. Works great for me!
Prototyping tasks require efficient programing (as in, the act of putting the program together) above all else.
Ruby excels at the latter, but not (yet) at the former.
...and then I had to rewrite 80% of it in C++ because of the horrible threading, slow string manipulation and high memory usage.
It was still an interesting experiment, and I intend to continue to use Ruby for stuff where performance doesn't really matter, but I was surprised to learn so vividly that the Ruby bashing that I'd assumed was oversold was in fact pretty much spot on.
I probably would have just used JRuby for this stuff, but Scala seems fine to me. And if it works for them, thats great. But I hardly see this a "jilt" against Ruby.
I know that the pros of JRuby for running Ruby applications mean things like being able to run multiple instances of Ruby from the same process, being able to run JRuby applications in a standard Java web-server be it as Servlet or a more high-level installation, and so on.
Also, Java has had a lot experience in running server applications so Java does help with maximizing the use of the resources available, be it 100% of CPU time, gigs of memory, multiple CPUs, and so on. Java has those famous garbage collectors and HotSpot technologies. JRuby can enjoy all of that so it does improve things over pure Ruby. Let's say, Java doesn't break a sweat under heavy load, or at least it shouldn't. Whereas with pure Ruby all bets are off.
Timing is priceless.
So it's a (mild) conflict-of-interest (really, it's just a promotional opportunity). Doesn't make the arguments any less valid or his book any less worth picking up. Nice thing about code is that it's like science - every claim can be tested ad infinitum.
One idle thought: It'd be hard to eliminate the factor that they might be a better Scala dev team than a Ruby dev team. That's still, of course, a perfectly good reason to go to Scala.
"The trouble, he insisted, is that the so-called Web 2.0 languages aren't always as efficient as they need to be, especially in an economic environment threatening to bring Web 2.0 to its knees."
Is particularly dire. Sure, so if we all switch to C or machine code we'll be able to skip through the recession, right? Seriously, less drama and more reporting please.
[EDIT: dear downmodders, the intention here is that languages are tools, and you pick the one which fits your current needs best. What's good for Twitter isn't necessarily best for another app, and Scala <=> Ruby is meaningless]
I've never used Scala and I'm a Ruby dev but I'm still not sure I totally agree with that. Scala is probably great and very efficient but you probably don't need to be thinking at Twitter's level out of the gate.
Eventually, more servers == more headcount.
Won't every new developer who works on this codebase lose a week to two weeks becoming facile in Scala? Assume a 6 person dev team, and a conservative fully loaded $180k for a valley dev, and that's $43,000 out the window.
You can also swap in Java components when you need to so, depending on the architecture, you may only need a small Scala team. Java devs are everywhere. You also win by acquiring easy access to Java libraries.
Not saying Scala is the right choice... but there are big advantages besides "Scala is lighter than Ruby" -- and Scala is a lot lighter.
I find it honestly hilarious to hear it suggested that one of the early high-volume Rails shops should stick with "safe" language choices because they won't be able to hire enough developers to work with a new language.
I've read through the sources to Kestrel, and found them quite easy to grok. If anything, most real-world Scala code seems to be essentially very clean Java, with much of the syntactic cruft (redundant type declarations, inner classes, 'public static final' declarations, etc.) removed. Any experienced, effective developer is going to spend far more time getting to know your in-house APIs and coding style than they are the language.
Ruby is our house language. We've never hired anyone that came in the door knowing Ruby. We have a very high bar for hiring (typical first project: "write a programmable symbolic debugger for closed-source binaries on platform Y"). It takes people at least a week to become facile with Ruby --- a famously easy language to learn. Reading isn't writing.
If you have a house style, easily figure another week to pick up the right idioms, so that your code survives in the repository and isn't just refactored out.
When hiring for the small percentage of excellent programmers, I don't see language as a barrier. Sure, there will be spin up time, but you'll have that regardless. No one is experienced with every library, framework, or configuration. Adding in a new syntax might compound the issue, but I think that there is the definite potential for long-term productivity gains once the team is up to speed.
Within that niche, Rails does a fine job. For infrastructure and middleware code, however, Rails has little to offer other than the Ruby language, which has serious issues when applied to time + memory-intensive problem domains.
I'm a huge fan of Ruby, and a (perhaps somewhat begrudging) user of Rails, but that doesn't mean I think they're the right solution to every problem.
I'm saying that is false, over-optimization is what brings startups to their knees.
Google won because of good search results, but I remember that the first thing about the search engine that impressed me when I first tried it in 2000 was its responsiveness.
I just hope that other won't jump to porting their code without understanding the reasons. It should be pretty embarrassing to spend six month porting the codebase just to find out that reducing time server spends in your app code from 5% to 1% did not impact the overall speed of your site.
It would be interesting to see more details about those queue processing problems they have though.
Scala is 900x faster than Ruby for some workloads. Ruby is not a fast language. It works for web stuff because every language waits for IO as quickly as the others.
My side business runs off of a $20 a month VPS. My day job routinely charges millions for software that runs on one to three commodity boxes.
You'll forgive me if I don't consider "Has difficulty running Twitter" to be a knock against a language. I don't, after all, have to run Twitter.
Yes, different languages and techs for different advantages and purposes.
"Just" developing a web app with models and views and controllers is enough to create the user experience smash hits are made off. Scaling issues are big, but certainly fall in the class of problems we want to have at some point.
Well actually with a big of good design from start you may avoid this problem from the start with little efforts. You'll have to scale anyway but it will be a matter of buying more hardware and not redesigning the system.
Let's say that many folks might have had higher expectations that have been hard to meet given the reality of it all.
The Merb guys helped with further explorations themselves which probably helped with making Rails advance more decisively, given the promissed "merging" of the Merb ideals with Rails.
Also, with things like Passenger, the deployment of Ruby met an all-time high in features.
The article title is misleading since Ruby continues to be used for its core business that is the front end.
It is a snarky, piss-taking, grease-trap that mixes news with commentary with little to no discretion or fear of violating "journalistic integrity." Once you understand that, it becomes a great source of news and entertainment.
Or rather, a great site to ignore.
May just have to wait and see whether their new "beautiful code" does any better. :)
If the expected total cost of rewriting and maintaining the codebase (over and above the cost of maintaining the current code, of course) to get an N% efficiency increase is less than the amount you will save on hardware, then it's worthwhile to do.
For a relatively simple application, which Twitter is, I'm unsurprised that a re-write/port is a fairly low cost ordeal, and might provide enough savings over time to be worthwhile.
I also take issue with the implicit claim that RoR is automatically more productive than Scala + Lift - Lift might be a little younger than Rails, true, but it's still a pretty solid piece of work, especially if you don't have to beat against the edges too much. And if you put some experienced Scala people up against similarly skilled Ruby folk in a "code race," I'd expect it to be a pretty fair match. This is not Java we're talking about, Scala can be extremely powerful in the hands of someone that knows what they're doing, and I imagine the Twitter guys have enough of those people that they'll do just fine.
If one had had an experience of using java-based network tools over cellular or wireless networks, one knows.
At the same time, Erlang is around for a decade.
So unless Scala has some secret ingredient to use the JVM more efficiently, this looks to me as yet another fanboy rant.
Secondly, any "ranting" you hear in this article is the product of El Reg, not Alex. He mostly offered a calm, positive presentation about the improved speed (with relatively little, if any, tradeoff in developer productivity) that came from using Scala instead of Ruby for critical infrastructure services.
Regardless, most Java web applications' performance issues stem from framework-itis, not from the underlying runtime. By itself, Tomcat (or another modern Java servlet container) is capable of some pretty impressive throughput -- perhaps not on par with a lean, pure C server like nginx, but not nearly as limited in functionality and extensibility, either.
No matter what you think about Java the language, you at least have to admit that HotSpot blows MRI, YARV, the Python VM, and Parrot out of the water when it comes to raw performance on low-level code. That doesn't save you from bad implementation ideas, but it does at least give you the possibility of getting fast, efficient code, if you have a decent compiler and work fairly close to the metal.
Using Scala is one way to produce that sort of low-level implementation code without wanting to gouge your eyes out (which is how most Java source tends to make me feel, anyway).
The rest of your comment, you change what I said so it's not worth addressing.
> Java scales just fine thanks. FWIW, Mibbit handles a good number more messages
> per day that twitter. On a single VPS with 1.4GB ram, running Java.
I wasn't talking about that. Message passing is trivial and scale on any language, or at least it should be. Well, unless you do Java and XML. That doesn't scale, from experience. Unless something changed in the last couple of years I'm not aware of. (Just taking your red herring further, to show it doesn't make sense and it has nothing to do with what I said.)Third time lucky, I hope. My point is I seriously doubt Scala is much better at scaling than Ruby, Python, or PHP. And the author seems to have based his opinion on his experience refactoring Twitter components previously coded in Ruby in Scala. Caveat emptor, I wasn't at the conference and this rant is second hand via a questionable source, The Register.
I spoke with some people at Twitter the other day. They said that they were switching to Scala just to annoy alecco on Hacker News. The performance and scaling advantages are entirely negligible.
I don't get the sense that they are that inexperienced. If they think a switch to Scala will handle more volume, I'd be really shocked if they didn't have some solid evidence to back that up.
> Careful here: are you _really_ suggesting that Twitter would do a full rewrite
> without making sure that it would increase throughput first?
No. I say this Scala vs. Ruby/Python/PHP rant sounds farfetched and unfounded.The Ruby community was formed without being forced into it necessarily. Academics did not force people into Ruby. Businesses did not force people into Ruby. Even Ruby on Rails was created because DHH was not forced to use PHP and instead tried to make things work in this new called Ruby.
Scala has its followers but Academics push it and business types can push it as well even though many business types still prefer Java and C#. Also, Scala is being primarily used for server-side stuff which is a very crowded market already and many developers are just a little bit too tired of having to interface with complex server-side stuff while trying to innovate on the client-side.
Thing is, as a guy who really digs Ruby, Scala does not worry me one bit. I could always try and use a hyper-advanced Scala implementation or application in the future given I can make choices at one point and then have to revisit said choices in the future given the changes brought by new developments.
Let me tell you a little story. When C# was being first introduced in its very early versions, I was very much playing Ultima Online on pirate servers. A new pirate server was being coded in C# and it was becoming rather popular quite fast and the single developer (or was it?) was having quite a lot of fun with it. Nobody told him to use C# for that kind of thing I am sure, it was just him putting his passion forward with the means he had at the time. C# has grown since then, and many pros and hobbyists use it to create all kinds of little programs on Windows.
Scala? Scala has an uphill battle, and many other languages have had their own uphill battles throughout the years. It's tough.
Some day you will realize that programming languages are tools for getting work done, not religions.