How to Fix Slow Code in Ruby(engineering.shopify.com) |
How to Fix Slow Code in Ruby(engineering.shopify.com) |
In my experience, even in "slow" languages, that type of thing is the predominant source of major performance problems, and the supposedly "slow" language would be perfectly adequate if you an stop shooting yourself in the foot (and if you can't, a faster language will not help you).
I'm sure there are extremely high-performance or high-scale points where language choice starts to matter more, but I'm also not surprised if Shopify is correct not to think they're there yet.
The vast majority of overhead in the rails app I work on is poorly build data models and poorly written queries. It makes no sense to talk about marginal gains of a few percent or a few ms per request when there are DB queries that take multiple seconds to complete.
In our case, a large part of that is due to the decision that someone made 5 or 6 years ago to store large amounts of data as serialized ruby hashes in the DB, rather than JSON (unsure if postgres supported it at the time), or simply as separate tables.
None of the poor performance of our codebase is down to Ruby itself. Most of it is due to features and data models being implemented with no thought for performance, a lot of which wasn't an issue when first written but as we've grown have become a constant thorn in our side (e.g. retrieving a multiple-MB serialized hash from the DB just to grab 3 values, then doing this 10 times in a request)
So yes, a language that's both faster and has less overhead in its ORM / DataMapper library definitely will help you.
In an unusual situation it is possible in PG to have a very large pg catalog if you have thousands of tables and schemas which is resolved at run-time because Rails resolves models and types through db introspection, and the types specicially are only loaded during runtime. But that would be very unusual. I'm working on solving this in Rails because this unusual sittuation is affecting us.
"The default behavior is slow!"
"Don't use the default behavior?"
The Ruby phosphophy seems to be lots of magic (in a good way) and in exchange you accept that details get lost behind the scenes and that it's only fast enough, but not truly fast.
Switching to a language that values speed with tools that have a different phosphophy can then make such a bug much more visible, due to the lack of behind the scenes magic.
There are two other alternative interpretations that I think are untrue however:
* "languages that value speed give you tools that expose more of the details and thus help you avoid adding defects in the first place" which I disagree with because (1) the average programmer will not understand what most low-level options actually do and (2) exposing more options is like trying to program with ones and zeros - at some point low-level abstractions don't scale well in a constantly evolving project
* "languages that value speed generally have fewer abstractions and thus make it easier to find bugs because there is less abstraction" which I think is untrue in projects of meaningful size. Macros are very common to find in languages like C and arguably as complex as metaprogramming in Ruby. Additionally Java is considered a relatively fast language and Java projects often have lots of abstraction
There's a myriad of tools out there for profiling, some language specific, some not. Learn at least one of them well, how to read flamegraphs and how to benchmark properly (warmup code, synthetic vs real traffic, etc). There's definitely a jump between making guesses and hoping you improve performance vs truly understanding what your code is doing.
From what I understand, it's the fastest VM out there at the moment for Ruby.
And yes, it's from Oracle but they have GPL'd the code [2]
[2] https://www.graalvm.org/docs/faq/
Edit: looks like TruffleRuby is built onto of Graal.
Not sure when they clarified the licensing around GraalVM, but it's what kept me away from it since it's inception. Looks like the single executable binary is under the Oracle license side of the equation.
Meanwhile Ruby 2.6.5 chugs along and finishes the whole suite in 8 minutes. Never hitting any unreasonable amounts of memory.
Also our C extension emulation layer used to be extraordinarily slow while we made it work correctly, and it's still rather slow.
It's a challenge but we're working on it.
But TruffleRuby is the only alternative Ruby implementation to even run major applications that I've tried at Shopify.
def benchmark_time(repetitions = 100, &block) require 'benchmark' Benchmark.bm{ |b| b.report{ repetitions.times(&block) } } end
Ruby used to be able to say we sacrifice performance for developer productivity.
I don’t think this is any longer true, there’s plenty of languages out there that developers can be just as productive with, while producing wildly more performant code.
It fundamentally has to be slower. Ruby is the most dynamic of the dynamic programming languages. And the community has embraced metaprogramming, making it every more dynamic. Especially on webservers, you'll be executing hundreds, sometimes thousands, more lines of code than other servers, especially in a mature system.
Is it "slow" enough to matter? Probably not until you get to a medium scale. Everywhere I've worked, we've had to on average double the hardware specs for Ruby servers to make them as performant as other dynamic language applications we run. Not the most expensive thing in the grand scheme of things, but there are entire cottage industries of magically tuning Ruby and Rails that you don't have to worry about with other systems until much larger scales.
Shopify's investing in TruffleRuby as well as MRI - they employ me to work on it. We have it able to run one major app, but still working on making it as fast as we'd like.
Includes some rare, bonus ruby implementations too <3
It's that easy :)
I've lately been writing several Rust tools and mini apps and have admitted to myself that even if a language stack clicks with you almost perfectly, you should still reach out to other tools when appropriate.
Even us the senior devs forget that, and it pays to get reminded of it every now and then.
It's quite amazing the lengths the companies will go to just to avoid changing their status quo. But for them it makes sense.
---
EDIT: Downvoters, calm down. Ruby on Rails is objectively quite a slow framework and this is proven in many public benchmarks (Techempower included). And Ruby isn't the fastest among the dynamic languages either.
Less cargo culting and more facts, please.
Then people go on all sorts of crazy journeys to justify their investments in pain and burned money.
Even though I get downvoted at places in this thread (and upvoted generously on others), I will never tell to people "you should always just rewrite to Elixir". Meh. If your app works fine, have it be in COBOL or PL/1 if that helps you do your job better.
But as you said, when your app/hosting starts struggling you should start rethinking your choices if all the lower-hanging fruit has been already collected.
Also the Ruby/RoR community and culture is better than most other languages/framework. I think culture is a totally valid performance reason to pick a language. Sure there are faster languages and there are jerks everywhere but on average it seems RoR devs are on average nicer and more collaborative people relative to peers.
There is a just a mindset for wanting to write in a language optimized for developer happiness that dovetails with wanting to be happy and work happily with other people. Ya sure those C++ guys can write more performant code but I know who I want to work next to 8 hrs a day. And who I will be more productive working with.
Also I don't think there are plenty of languages that are Ruby/RoR peers. Django doesn't come close. JS ecosystem is a dumpster fire. Some functional and JVM languages maybe but they often come with a corporate culture that kills their benefits. Kotlin would be my bet I guess?
Also if scale is your issue and rails isn't cutting it then you need to go to a proven language with a proven and hirable developer base. That rules out a lot of new and promising languages. Sure they might be just as productive languages but they are resource constrained at the people level. It is really hard to hire Elixir/Phoenix devs etc. You need a talent pool of thousands. Also you need to KNOW the language will be there with a community in 10 years and that it has a history of evolving without screwing over the community. I guess Twitter going to Scala would be an example of this, from my understanding it doesn't solve all their problems.
Total aside: plenty of language need massive tuning to work at scale but it seems like Ruby is unfairly singled out if someone does "exotic" tuning of it but if someone tunes a JVM language or invent their own it is supported.
I don't think this is true at all. Where was Rails 10 years ago? It was pretty bad compared to today's Rails. If the Rails 2 and Rails 3 rewrites never happened then RoR likely would've been superseded by something else and be "dead" today. The point is that Stripe, Github, etc were all early adopters of Ruby and accepted that risk
> You need a talent pool of thousands
I also don't think this is true. You need to hire the right people and you need for them to stick around. And you need to be in the right line of business obviously. Again most of the companies you listed were small/passionate/scrappy for a long time
This has not been my experience.
It has been “do it THIS way in ruby” even though either way is perfectly valid (eg list of Literal strings / symbols vs %i or %w.
Lots of bike shedding type discussions on which way is better and unsurprisingly no consistency across the codebase.
There’s also a lot of hidden things you can only learn from years of usage and no clear documentation of when / where features came and went.
All in all every Ruby dev I’ve worked with across 4 companies have all had the same sort of elitist / pretentious attitude compared to Python, Go or Java devs. Ruby has only been second to Scala and Rust devs (so far).
There aren't that plenty really. Golang has nothing like Rails, neither does Node. You can say Django / Laravel but then it's the same performance issues. Or maybe you're talking good old enterprise software like Spring / Asp. I don't think Ruby/Rails should feel inferior to any of those names for web development.
The problem I have with JS (both for server side and client side) is that there's usually several different packages/libraries/frameworks to achieve the same goal, and often one gets deprecated in favour of another, requiring constant updates and changes to the development and build environment. JS development is all about the flavour of the week. For example gulp/grunt/webpack, or NPM/bower/yarn. This is compounded by the lack of a standard library.
Every company has its own particular build system (and configuration of that system), libraries they use, style guide, and file/folder layout. It's also very easy to abuse scoping and class mutability, with only style guides and eslint to save you. It can be a lot of work keeping a larger and older project up to date.
But I think writing new features, or rewriting some critical paths of the codebase in a new language could make sense.
It's atleast a valid question.
They are clearly already spending a lot of resources optimizing Ruby code to match their demands.
My question is at what point does continuing with Ruby become trying to force a round peg into a square hole?
I don't see why that would be the case. In fact, the performance improvements during the 2.x era seem to indicate the contrary: that Ruby can be faster.
Well, the extensive use of “method_missing” appears to be staggeringly difficult to optimize short of a tracing jit and it’s also the core idiom of many popular frameworks. Of course it can be faster—if you remove the slow, unique features you can optimize it like any other language.
That's an interesting note. They have a $90b market cap, trading at ~53 times sales. It's one of the more extreme valuations I've seen in the last 25 years, including the dotcom bubble (and that's saying something with how overvalued everything cloud-related is today).
As one comparison for the absurdity, Yahoo during most of the height of the dotcom bubble, was trading for 30-50 times sales, growing sales faster than Shopify, and they were solidly profitable (Shopify has never earned a consequential profit in its history). That's how bad Shopify's present valuation is, to get good comps you have to reach into the dotcom bubble.
The market thinks they're Amazon-like. The problem is they've never demonstrated any great margins in their platform (despite 14 years and counting) and Amazon's big lift-off in their stock occurred solely due to the ability of AWS to generate immense operating income. Without AWS, Amazon eventually gets the sad multiples of a Target or Walmart on their retail business.
This is an obviously mistaken valuation riding one of the most overvalued markets in US history, one that will most likely brutalize investors that get in late. It's a classic example of how very inefficient and irrational the stock market can be in the shorter term. And no, that doesn't mean an investor should be the fool to step in front of the irrationality train and short it either (everyone here probably has heard the Keynes line about the market remaining irrational longer than you can remain solvent).
It'll take at least 10-15 years at a minimum for Shopify to grow into its present valuation, in the best case scenario, if everything goes perfectly and they some day find some margin in their business. If they eventually manage an enormous $2 billion profit ($1.7b in sales today ttm), they'll still have a 45 PE ratio at today's valuation. That's a prime market example of insanity.
eBay has a vastly superior business (in all regards, including its quasi-monopoly positioning and the tremendous profitability of ebay's platform), trading for a huge discount to Shopify, on the basis of the market's mistaken extrapolation about Shopify's future. If they're lucky, they'll one day be the size of eBay with a fraction of the profit margin (and of course eBay has a mere $29b market cap, 12x op income multiple; compression is a killer). I mention eBay (beyond obvious reasons), because Shopify is likely doing nothing more than pulling future returns forward to an extreme, as eBay once did (leading to a decade of stagnation in the stock).
Also, I'll take "double the hardware specs" if it means I'm actually able to focus on what I'm building and not dicking around with devops or rebuilding all of stuff Rails metaprograms for me by hand.
If there was a framework for being as productive as Rails at half the cost then it would be flourishing. There isn't and as a result Rails isn't going anywhere any time soon.
Try 7x to 11x. That's the amount of reduced RAM usage -- and the amount of increased accommodated users -- on identical hosting by the two apps I rewrote from Rails to Phoenix.
> If there was a framework for being as productive as Rails at half the cost then it would be flourishing.
Bold of you to assume technical merit is the only factor. Historically this has almost never been true. There are a number of web frameworks that perform much better than Rails and are quite easy to work with.
Cargo culting is a powerful force. Corporate inertia -- even more.
Phew, I'm glad GitHub and Shopify's scale is still small.
I mean, every programmer who funnels through university understands map reduce, and that helps on multi-core threading up to system job running.
But there is a limit, usually in the persistence and caching layers. What you'll find is that those "large scale deployments" are going to have a -lot- of internal cache systems and I can pretty much guarantee that the services running those caches and persistence will not be written in ruby.
You can make anything* scale, but how many CPU cycles you need to burn to get the functionality you want is a matter for the finance department.
If you're running in a lossy business, you can bet that those CPU cycles will begin to cost more than developer velocity is worth, because servers are an eternal and ongoing cost.
On the flip side if you make more money than the infra+devs cost, then nobody is going to hound you for wasting 2x 3x the cost. Because "it's the cost of doing business" is easier to justify when you're cash positive.
Phew, good thing they can afford to burn a lot of cash for hosting.
additionally: > Sinatra + Sequel is already very competitive in web performance with Go > Between Ruby 1.8 and 2.5, performance has improved around 13x in tight loops[2]. The Rails performance issue has been massively overblown since 1.9 was released.
A lot of the time, that "competitive with X" in web frameworks is because the scripting language has a web server coded in something other than the scripting language. I don't know about that exact stack, but I know that's the case for Node, for instance. The web server is written in C. So when you benchmark a "tight loop" in those languages, you are running 99% C and 1% your scripting language.
Now, that is not a bad thing. It is a valid result, in the sense that it is a good thing for environments to have fast web servers, and nobody cares what the implementation language is... with perhaps the sole exception of this case, where we're trying to compare the performance of scripting languages by their web server implementation. You can't claim "Scripting Language X is fast because it has a fast webserver!" when the webserver isn't written in Scripting Language X.
(A moment's perusal didn't show me what this particular web server is implemented in. If someone can link me to that web server and show it's implemented in Ruby, I'll be happy to eat my words here. But if the performance is comparable to Go, that's enough evidence it isn't written in Ruby to satisfy me until more evidence comes in. If Ruby isn't a slow language, you've defined "slow language" to the point that no language is slow. There isn't much competition in the "slower than Ruby" field; Perl 6 is pretty much the only entrant I know of. There's a number of languages as slow as Ruby, it is not uniquely slow, but there's almost nothing slower.)
Phoenix is written in Elixir -- another dynamic language.
I am willing to argue with facts but you just added another non-factual opinion to the pile.
...Oh, and a Mario game implementation says nothing about the typical production uses of a language and its stack.
That, plus the fact that most Ruby users don't go for Sinatra and Sequel.
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
And I am pretty sure backwards compatibility will continue dragging JS down for quite a long time still as well.
If it doesn't bring you that, then we have a problem!
No & No.
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
For example, most Ruby found in the wild follows some variation found in the style guide: https://github.com/rubocop-hq/ruby-style-guide (same with Scala: https://docs.scala-lang.org/style/ and Rust: https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide...) and their communities generally care enough to try to enforce it. Most languages have an universally agreeable style guide these days.
I personally find the first set of languages to be more consistent syntactically (typically because they're simpler languages that have auto-formaters) but the latter set of languages are extremely consistent in patterns/ideologies. It seems like you care more about the former and didn't care to learn about the latter (which I'll admit, does present a higher learning curve and tends to be acquired through experience with the community than through a doc).
Also, "perfectly valid" doesn't mean "good", or "best practice", most style rules tend to reason beyond just looking pretty. String literals are slower and use more memory than symbols, and they're harder to grep for (either visually or with grep) in the codebase. More importantly, it's a lot clearer in code what a symbol's intent is, it's an immutable internal identifier, whereas strings should be used for storing data. Strings are mutable, which can be a source of bugs, a fairly trivial example would a developer making a typo and writing `str += 'label'` instead of `str = 'label', using symbols would raise an exception. Same for using %i or %w for arrays of integer or words, it ensures that the contents of the array are of a consistent type (at least at that point). Personally I don't think it should be a strict rule (I've turned the lint rule off on our codebase), but I do use them where appropriate, in particular when defining a constant as an array as it makes it clear to others reading the code what its intent is.
The only real complaint I have about Ruby style is that there's a million ways to work with enumerables, often with subtle differences in behaviour. For example, extracting a value or default from a hash is commonly done with `hash[:val] || 'default'` or `hash.fetch(:val, 'default')`, if the the key exists in the hash, but with a falsey value (nil or false), it will return 'default', but the second will return the falsey value. This can be good or bad depending on your specific use case, but I've come across unexpected behaviour from both versions.
I definitely agree with you about hidden features though. I've spent hours this week reading through different gems' source code because the documentation was lacking, at least it's generally readable code. It's frustratingly common when reading gem docs for me to find `#method(opts={})` as the method signature, with no additional explanation as to what parameters it takes.
I much prefer Ruby having a prescriptive style guide that the majority of developers use, I can look at the source code for any gem or app and immediately be familiar with how it looks, it's a lot less overhead when starting on new codebases. Compare this to C, where there's half a dozen different conventions on where to put your curly braces, or JS, where there's arguments as to whether lines should end with a semicolon.
You're right that a lot of ruby developers are pretentious, especially compared to Java or C# developers. Most Ruby developers are programming/technology enthusiasts, they have a passion and interest in what they do, I spend a fair amount of my spare time programming, or reading about programming. This is especially true for experienced developers (before bootcamps were all teaching Rails), they learned Ruby in their own time, not at university.
On the other hand, a lot of Java/C#/Python devs do it as a job and nothing else, which there's absolutely nothing wrong with, everyone has different hobbies and interests. One of my coworkers was previously a Java developer, and he has no particular interest at all in programming, he would probably be just as happy as an accountant, he spends his spare time painting or with his family.
https://github.com/TechEmpower/FrameworkBenchmarks/blob/mast...
PostgreSQL is obviously not written in ruby, but the other components are very much "ruby code". There appears to be c/Java extension for ssl and parsing http, though - but AFAIK the main server is ruby.
https://github.com/puma/puma/tree/master/ext/puma_http11
Tangential, but you might enjoy:
https://deno.land/v1#http-server-performance
> A hello-world Deno HTTP server does about 25k requests per second with a max latency of 1.3 milliseconds. A comparable Node program does 34k requests per second with a rather erratic max latency between 2 and 300 milliseconds.
> Deno's HTTP server is implemented in TypeScript on top of native TCP sockets. Node's HTTP server is written in C and exposed as high-level bindings to JavaScript. We have resisted the urge to add native HTTP server bindings to Deno, because we want to optimize the TCP socket layer, and more generally the op interface.
There was even one report of it being faster than C/C++.
(My guess is that the C/C++ code was doing a lot of string copies and/or scanning for a null terminator. The MoarVM backend doesn't generally do either of those things.)
> They are clearly already spending a lot of resources optimizing Ruby code to match their demands.
I think the work on Graal is a VERY long term investment. They can grow to become a 200B company even if none of that work succeeds. Also, I think it's just one guy Shopify is hiring to do that but I may be wrong, so definitely not a showstopper for Shopify :)
http://esr.ibiblio.org/?p=8161
Basically, what he found is that for programs that work with large graphs of objects (as opposed to arrays of numbers, which are the domain of numpy and friends), Python isn't all that fast. I don't know how it compares to Ruby though.
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
>...a web startup like ours doesn’t need any outside money to succeed. I know this because we haven’t taken a single dime from investors. We bootstrapped the company on a few thousand dollars and became profitable the day we opened to the public and started charging for subscriptions.
Tom Preston-Werner in 2008. I guess the thing is not how much the hosting costs in absolute terms but how much it costs relative to what customers are prepared to pay for the service.
My point is, yes, you are right -- but there's a lot of conservatism involved once the business gets to a certain size. Nobody cares about improving anything from then on (which usually leads to the now-giant to start steadily losing relevance; GitHub is quite far from that but we all remember Microsoft, right?).
I'm not interested in arguing with someone who doesn't respect others opinions, nor did I make baseless claims: I cited resources.
> ...Oh, and a Mario game implementation says nothing about the typical production uses of a language and its stack.
It's true, the mario runthrough was in pure ruby and not rails, and that rails has a slower performance vs. Ruby + Sinatra.
Performance metrics are not opinions.
So which ecosystem is more productive then? What you just described is horrible for a company like Shopify; they aren't a 3 men team working in a garage. And even for a small team, why would you wanna chase a crazy ecosystem like that instead of focusing on your actual product?
I've discovering this the hard way as I slowly upgrade our front end from AngularJS 1.4, no transpiler, gulp, and bower. Almost much nothing has been upgraded in 5 years, which is like 50 javascript years.
JS is not a great language to use if you're an independent beginner, you either have to follow a tutorial blindly to get a boilerplate setup and hope that in the 6 months since it was written nothing has changed in the libraries used and the tutorial is out of date, or you can spend hours learning how to structure a JS app.
I feel like I'm being harsh on JS. Ruby/Rails is an incredibly productive ecosystem for a beginner, but has the same problems with maintainability and upgrading if you neglect it too.
Any framework isn't productive when you're in greater technical debt than the Weimar Republic, and it's easy to write bad code in any language if you're lacking experience. Upgrading dependencies in any ecosystem is difficult if you don't touch your gemfile or package.json in half a decade. I've had the same problems upgrading our Rails app as our AngularJS app, I'm just much more qualified to handle them.
There were also no experienced Ruby/Rails or JS/AngularJS developers at my work until I joined (and there's still no experienced JS devs), and we've always been pushed to ship features, not improve performance or keep our dependencies up to date, so I've had limited opportunities to work on fixing technical debt. Not entirely sure why you'd create a product with two frameworks none of your employees have any experience in. On the plus side, with all this spare time I've had during lockdown, I've managed to make good headway in resolving a lot of that debt, beats spending my days watching Netflix or playing video games.
Still, I regularly chat with Rails devs and to have a MacBook Pro 2018 return responses in 150+ ms is alarming. But you might be right that it could be a N+1 query problem.
Even without those though, I've still seen Rails apps perform quite horribly. So 50/50 from me, you might be correct but I wouldn't entirely discount the option that Rails is still quite suboptimal in terms of performance, compared to many other frameworks.
Because a lot of web developers these days build applications and ORM's are great but make certain patterns convenient so it's really easy to code yourself into places that don't scale. Then people reach for various caching solutions rather than taking a step back and looking at what's actually executing.
I've seen just about every bad pattern you can imagine and it's not usually obvious because the code looks simple enough. Like that permission check in your controller is actually serializing 1000 ids and querying against them, or that .first doesn't have an index so you're sorting the whole table, and much worse than that.
The Heroku dynos I've tested with some years ago performed quite horribly. Only a proper Xeon server was able to achieve sub-100ms responses.
But hey, if Ruby improved in the meantime, cool.
I've always thought of it as the platform you use for running toy apps with maybe a couple of dozen users at most and a low load. It's incredibly quick and easy to get a Rails app running on Heroku, a couple of hours at most. But you pay (in dollars and performance) for this.
(Then again, they have them with Phoenix as well but to a lesser extent.)
I am glad to see that there are much more reasonable Rails devs out there compared to some rather toxic individuals around in HN at least!
A lot of tech can be fine-tuned to be very performant. My point was (still is) that there exist technologies today that allow you to delay your scaling decisions much further in future, compared to what a stock Rails app (without any performance tuning) will.
The implication is, of course, that there isn’t a good one. This isn’t ruby the language’s fault, it’s just weird that after like 15 years being the go-to tool for VCs there’s no substantial investment in the core infrastructure.
We just gotta wait for banking software to be written in it, I guess, so there’s a vested interest in it over the long term.
Edit: I’d like to further note that other languages use similar features (string-keyed functions) but they aren’t typically put into high performance code/are seen as a hack around formally definitions (possible exception: common lisp, although I would expect a macro). This is inherently a readability improvement over manually defining the methods you use.
I hope that Shopify will start to invest more into R&D for CRuby as well now as well as having Chris there working on TruffleRuby.
I'm not sure what you're trying to say with the last part because Ruby works quite differently to Lua or Self here and Self has been "fast" for 30+ years anyway.
And at some point you might as well use Crystal if you're going to do that, while keeping a Ruby-like syntax.
Edit: getting downvoted by people that don't work at Shopify.
So what? What's wrong with using software like redis for cache, for a very small (but important) part of your business? I bet java apps use redis as well, and redis isn't written in java. So?
Erlang/Elixir have built-in caches that respond in the matter of 30-150 nanoseconds.
Why would you need an external service for that? It's adding complexity -- and likely hosting costs.
Isn't it self-evident to you that adding Redis as a caching layer to your stack is a bandaid to a deeper problem?
We're also dependent on mysql, are you gonna implement that in Elixir as well? Redis is a great piece of software, and it's a real SHARED cache, so it could work for sessions or other small state management you sometimes want to remember for example. What you described won't work for that.
What's the name of the concept and where in the typical stack does it fit? Is this https://blog.appsignal.com/2019/11/12/caching-with-elixir-an... or something else? Care to share a few link to docs/articles? Thanks.
It’s not a “problem”, but if you’re going to talk about large companies scaling something you need to understand that they’re likely scaling it in spite of limitations.
Largely, some systems don’t scale too well (latency on network accessible cache, throughput in persistence layers such as databases) so a lot of application layers will lean on those things heavily and they are exclusively written in relatively “faster” languages.
I wish this were true. There is a high degree of variability between skillsets from different American universities, even in my state of Washington.
Other than that, I agree whole heartedly.
You're quite right: people using it as a mere cache don't get most of its benefits.
That sounds pretty dogmatic itself. You don't have to like dynamic languages - but that doesn't mean they are deeply flawed. The same could be said for statically typed languages with a different set of values.
To do some things but not others?
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
Question: (a) do you believe we'll ever get to a day when TruffleRuby/Graal will be able to 100% run Ruby on Rails and (b) how much faster over MRI do you believe it could achieve?
For parts of the Ruby ecosystem running production workloads, such as the Liquid template engine, I see 6x performance today. I think that's a realistic goal in time.
Any rough estimates on when the masses will be able to run RoR on TruffleRuby?
(Just order of magnitude timing ... e.g. late 2020, mid 2021, etc.)
I'm aiming for around 6-10x for real production code.
> Does it ever seen like a lot more trouble to try to optimize ruby instead of just writing slow parts in a different language?
I'm pretty philosophical about this.
People want to write and run Ruby code. I trust they've got their own good reason for that. Taking that as a given, I want to let them run it as fast as they can, with the best tooling I can give them. Instead of 'you shouldn't do that' I want to have the attitude of 'ok we'll see what we can do'.
I do personally really like Ruby and I reach for it pretty much whenever I start a new project.
Sessions work quite fine in Elixir's local cache as well. :)
This seems to suggest otherwise https://hex.pm/packages/redix, Why is the redis client is so popular in Elixir world? For such a small community 3+ million downloads is huge.
It's no accident that there's even a library that emulates OOP patterns in Elixir.
Hi,
I'm the Manager of the Ruby and Rails Foundations team at Shopify.
We are investing a lot on R&D for CRuby as well.
We have 6 people working full time on Ruby implementations, both CRuby and TruffleRuby. Not only Chris Seaton is here, but we have two CRuby Core members as part of the team, Aaron Patterson being one of them.
Surely this would reflect in benchmarks? Perhaps there is an even slower aspect of the language manifesting in JRuby....
> I'm not sure what you're trying to say with the last part because Ruby works quite differently to Lua or Self here and Self has been "fast" for 30+ years anyway.
Is this supposed to reflect in Ruby’s favor? Self was built to be performative in spite of its novel features—the slow aspects of the language were never encouraged to take a central role. A better equivalent might be applescript or bash or a language that emphasizes some particular quality of expressiveness.
Did you mean messages? They're certainly a central part of Self.
The Node time is at 2.6x the LuaJIT time, which I'd still consider in the same ballpark compared to eg the factor of 31x achieved by Python3.
[1] https://github.com/wasm3/wasm3/blob/master/docs/Performance....
> There are a number of web frameworks that perform much better than Rails
If you're measuring hardware loads and busting out your stopwatch to measure response times, then sure.
Bottom line is, there are plenty of good reasons to choose Rails over Phoenix. If you want to label choosing a well-backed framework with an incredibly mature ecosystem "cargo culting" then by all means.
Have fun writing Ecto queries by hand, wiring up document storage on your own, trying to find a standout auth library of choice like devise, finding a library that makes managing database views less of a pain, wiring up end-to-end system testing.
I'll be over here running rails new, wiring up sidekiq to ActiveJob, and building shit with ease.
I thought we all learned popularity does not correlate with quality. It correlates pretty closely with corporate inertia and perceived lower risk of developer churn though. Businesses love tech stack for which there are bigger pools of programmers. Says nothing of the quality of the stacks.
> If you're measuring hardware loads and busting out your stopwatch to measure response times, then sure.
Needlessly snarky. Response times matter in a lot of businesses. Count yourself lucky that it hasn't been an important metric in your work.
> Have fun writing Ecto queries by hand
I do have fun writing those. Most times the code in my functions ends up more readable than the equivalent Rails code I wrote years ago. There are some exceptions where you have to dig deeper. Haven't seen a framework -- Rails included -- that lets you handle all complex cases with zero deeper digging needed. At one point you do have to understand SQL and query optimizations, no ways around it.
> wiring up document storage on your own
What for?
> trying to find a standout auth library of choice like devise
It's called Pow and works very well. Additionally, Elixir's maintainers themselves are authoring such a library at the moment.
> finding a library that makes managing database views less of a pain
We can argue if this is a good thing until the Sun explodes. It really depends on the business. I have consulted for businesses where it was very important and true enough, using a library that's well-tuned for classic web apps (like Ecto and ActiveRecord) isn't the best idea there.
> wiring up end-to-end system testing
For 3.5 years with Elixir this is the first time I hear that this is a problem. Any data to back this up?
> I'll be over here running rails new, wiring up sidekiq to ActiveJob, and building shit with ease.
More power to you. Rails is excellent for an MVP or a prototype and this is well-known. It's what comes after is what has burned me out of it. Its maintenance burden is much higher than many others, including PHP's Laravel.
My point is that it doesn't come with Phoenix out of the box (unless something has changed?), and that difference in philosophy is the core of what I'm getting at. With rails new I'm getting an end-to-end test suite and chrome driver installation for free.
Phoenix also has no plans of implementing something similar to ActiveStorage do they? How about ActiveJob now that elixir developers have rediscovered how great a queueing system is with the adoption of Oban?. Will Phoenix ever make a move to include something like ActionText?
They won't even consider adding basic things for developer productivity like undoing a generator.
https://github.com/phoenixframework/phoenix/issues/2607 https://github.com/phoenixframework/phoenix/issues/1597
The Rails team is much quicker and happier to extract something out of the companies supporting it (Basecamp, GitHub, Shopify, etc) and include it directly in the framework, whereas the Phoenix team seems much less willing to take a "batteries" included approach.
There's a balance of making something easy to use and making something "technically superior". The Rails team seems to care much more deeply about what the framework feels like to use, and the Phoenix team cares more about building something that is "dogmatically perfect" (which you're correlating with quality).
What's easier for someone to learn?
rails g model article title body user:references
mix phx.gen.html Content Article articles title body
I understand what they're going for here, but I'm not sure the tradeoff is worth it. If Phoenix wants to increase their adoption, then I think they need to accept that things like this matter.
$ rails c
Loading production environment (Rails 5.2.0)
[1] pry(main)> s = Subscriber.find_by_email('xyz@abc.com')
=> #<Subscriber:0x000055dbb64c3bb8
id: 12913,
email: "xyz@abc.com",
state: "active",
expires_on: Fri, 15 May 2020 14:10:19 UTC +00:00,
...
[2] pry(main)> s.expires_on += 2.months
=> Wed, 15 Jul 2020 14:10:19 UTC +00:00
[3] pry(main)> s.save!
=> true
It is done now! Good luck! Bye! - end of call.Cargo culting? From whom? I don't give a sh*.
What you describe is not exclusive to Rails.
There are libraries that combine Erlang/Elixir's caching mechanisms in an attempt to achieve the best performance for most scenarios[1] as well.
Technically, ETS is not perfect because it copies data from its mutable cache to the process that requests it. But it's still orders of magnitude faster than outsourcing that to Redis.
I read in http://erlang.org/doc/man/ets.html that "Each table is created by a process. When the process terminates, the table is automatically destroyed. Every table has access rights set at creation."
-> So, caching is local to each worker node/process? Do nodes/processes communicate between them to synchronize their respective caches, or is it local by design?
If local by design, that wouldn't exactly cover the use case of "Redis in front of an army of $other_language workers", correct? And I guess it's accepted as costing slightly more cache misses, but with the benefit of more decentralization / node independence / resiliency, right?
> If local by design, that wouldn't exactly cover the use case of "Redis in front of an army of $other_language workers", correct? And I guess it's accepted as costing slightly more cache misses, but with the benefit of more decentralization / node independence / resiliency, right?
Yes and yes.
Erlang/Elixir don't strive to make distributed caches. I wrote apps that have been scaled to 5 separate servers and each server has their own local cache (running inside the Erlang BEAM VM). Takes a little more time to warm the caches up on restarts but it has never been an issue so far.
The ETS tables ownership is trivial to hand out to another process if the owner dies (look for the "heir" option in ETS docs) but libraries like Cachex (linked at the bottom) and Ane (linked in my previous comment) wrap the ownership worries away from you.
What's left for you is just an uber-performant cache.
Do take a look at Cachex. It's hassle-free and just works.
If people have Sinatra apps or similar they could also try those now.
I'm in the GraalVM Slack - https://www.graalvm.org/community/ - ask me for help.
Don't want to speculate more than that.
> "Erlang/Elixir don't strive to make distributed caches. I've wrote apps that have been scaled to 5 separate servers and each server has their own cache. Takes a little more to warm the caches up on restarts but it has never been an issue so far."
Yeah that's what I figured, makes total sense. Got into exactly the same thinking designing a circuit breaker at work. Better to let individual nodes do their own circuit breaking rather than introduce state, the complexity savings largely exceed the small cost of a little extra time needed to circuit break.
I simply felt compelled to point out that Rails is not at all as unique as many of its long-time users believe.
(In that case, let's replace Laravel with Phoenix.)
It's gonna be tough for them really, even if it's a great framework (I have no idea). Elixir didn't take off like Golang or other languages from the last decade. It seems to have quite the learning curve, so for beginners any of ruby / php or even .net / java will make much more sense. For seniors...idk. Not everyone like functional programming. I do hear praise for the language I can't deny it and what seems like a tiny but vibrant community, but the numbers are just not there. I hope Elixir can maintain it's niche and not outright die just because I know some people rely on it for their pay check but honestly I'm not sure if we'll still have these discussions 5 years from now.
Fringe tech is usually a secret weapon in consulting, or, more rarely (but still happening quite a bit), in a full-time job.
Apples to oranges.
Erlang existed for 30 years and has been used by its small-ish but also very vibrant community, with great success.
So you know, very popular or not, us the people who use it successfully commercially will keep doing so.
But as I have said in the past, if Rust (or OCaml, or any statically strongly typed language that compiles to native code) gains all the guarantees of the BEAM VM then I'll abandon Elixir the next day.
You put a lot of weight on built-in features of frameworks in your reply. This is not an objective truth and even DHH himself admitted as much -- including in his article "Rails is Omakase" which I very much enjoyed (because he says that the Rails team picks what they deem the best ingredients and if you disagree then you are not the target audience).
You find value in "officially vetted" libraries, I find value in being assemble to assemble my chair the way I want it to, with parts I built or bought myself.
Neither practice is superior per se. Let's both admit that.
> They won't even consider adding basic things for developer productivity like undoing a generator.
Honest question: how many tech stacks even allow for that? Does Ruby have bytecode instrumentation on the level of, say, the JVM? (Java's instrumentation has unlocked it some quite impressive code generation and runtime code analysis abilities.)
Generating boilerplate is pretty easy. But how many tools out there can scan your code and tell you "this looks like Devise's boilerplate with exceptions in files A and B on lines 123 to 150 and 201 to 217"?
If Rails can do that I'd be very impressed. It couldn't, as far as I was aware, about 4 years ago.
> There's a balance of making something easy to use and making something "technically superior".
I never said this was important to me. I value Elixir's hassle-free parallelism and concurrency (which is more than what can be said about 99% of the tech out there where those things are always an afterthought). And Elixir is still pretty easy to use. I don't see why both things have to be presented as opponents? Seems like a false dichotomy.
> The Rails team seems to care much more deeply about what the framework feels like to use
You have spoken to the authors and they have told you this, in these exact words?
> ...and the Phoenix team cares more about building something that is "dogmatically perfect" (which you're correlating with quality)
And you have spoken with the Phoenix team. And they told you this. Exactly this?
No. They don't do that. They don't want to steer developers in the direction they might deem the best (they said as much on ElixirForum). They give you freedom to choose. And the community has provided alternative approaches for a number of the classic building blocks of a web app. That's all there is to it and I am not sure how you managed to so grossly misrepesent it. :(
I also never said anything about dogmatically perfect being important (much less correlated to quality!). You are projecting and we are talking past each other which doesn't help the discussion at all. If I cared about purity or similar concepts in the "dogmatically perfect" lane I'd go for Haskell or even Idris. Elixir -- and thus Phoenix -- are very far from "pure", "dogmatically perfect" or any such other academic ideals.
Really not sure where you got that from?
> What's easier for someone to learn?
This is extremely subjective and varies from person to person. Are you claiming that Rails' way is factually superior to learn? To me both are quite straightforward and both require you to have learned some concepts beforehand. And both aren't exactly English with which you command the machine, no?
> If Phoenix wants to increase their adoption, then I think they need to accept that things like this matter.
Ever since I dropped off the mainstream tech train and started working on the sidelines I've noticed something extremely curious which is happening very consistently: the people who work with mainstream tech always assume that the smaller community wants more adoption.
There have been a number of discussions on ElixirForum about this and various important figures of the maintainers' teams have openly said that they aren't aiming to make the language and its stack more popular; they want to make useful tech. One example is the recent Phoenix 1.5.0 release which now comes integrated with LiveView. A lot of people apparently don't want to deal with JS because at least 50% of the new posts on the forum since the announcement have asked exclusively about LiveView.
So again, the maintainers aim to make useful tech, not to trend on Twitter, dev.to, StackOverflow, or anywhere else really.
---
This became rather long. I apologise for that but still wanted to address several misconceptions that seem to have arisen in this discussion.
We all wanna get paid in the end of the day. Lots of Rails devs got spooked that 5 years from now their knowledge will go to shit. A lot of them still feel insecure about the state of Ruby, even with 90B companies like Shopify using it, because they read a blog about how a startup no one heard of migrated from Rails to Elixir. You don't seem to care about any of that and that's great. But let's face it, a lot of the back and forth "what's better tech" wars and shitting on each other's stacks is simply trying (maybe subconsciously) to gain more adoption and to validate our choices in life, and feel good about what we do by feeling superior to others. Just like a religion really or any other form of community. These aren't really academic discussion on what's "better" in my view.
Even though you and me keep exchanging jabs here I'd like this to stop.
I don't intend to "shit" on anyone's tech choice. What I did and still do intend is to help somebody, here and there, to love their job. I've met a lot of miserable Java and Ruby on Rails devs.
For the sake of the civil discussion we both should stop assuming stuff.
I am grown up enough to not care about validation (and I think everybody shouldn't care about it either but it's not the world we live in, sadly). It's mostly about finding something that clicks better with your brain and gives you a peace of mind while working.
Rails didn't give me that. It gave me anxiety. I had to always be on watch what is shifting beneath my feet. A [mostly] FP tech stack gives you back the control to shoot your own foot as opposed to a library that's a dependency of the dependency of the library you need doing it. Okay? :)
> We all wanna get paid in the end of the day.
Well, exactly. But I also want to be happy while receiving a paycheck.
There's nothing wrong with wanting to pick the parts yourself. But that comes at a cost and that was my original point that you responded to. Rails makes these decisions for you.
Elixir and Phoenix have taken a different approach, and there's nothing wrong with that. But let's not pretend that Phoenix is "as productive" as Rails. It isn't by choice. I disagree with that choice, but it's not my choice to make.
> Generating boilerplate is pretty easy. But how many tools out there can scan your code and tell you "this looks like Devise's boilerplate with exceptions in files A and B on lines 123 to 150 and 201 to 217"?
Rails can reverse just about every generator that it ships with. I'm guessing it's more difficult in Phoenix because the generators append stuff into contexts instead of generating new files maybe?
> and the Phoenix team cares more about building something that is "dogmatically perfect" (which you're correlating with quality)
>> And you have spoken with the Phoenix team. And they told you this. Exactly this? No. They don't do that.
>> There have been a number of discussions on ElixirForum about this and various important figures of the maintainers' teams have openly said that they aren't aiming to make the language and its stack more popular; they want to make useful tech
What? I feel like you're in agreement and disagreeing with me simultaneously here?
> Are you claiming that Rails' way is factually superior to learn?
No, I'm claiming that Rails is easier to learn and use because of the philosophy of its creators and maintainers. ActiveRecord is easier to use than Ecto. Reversible generators is an easier interface than "just undo it with git". Running a rails command for installing ActiveStorage is easier than building it yourself. ActiveJob is easier than wiring up Oban (not much easier, but still). Getting an end-to-end test framework out of the box is easier than hunting down elixir libraries and trying to bring them to the party.
Rails cares deeply about the developer experience. I think Phoenix does as well, but they focus on different things (LiveView).