News for hackers. Stuff that matters.
Re:How to Fix Slow Code in Ruby by stevebmark on Thursday May 14, 2020 @01:50PM (#23182886)
Benchmarks are subjective, but all benchmarks show Ruby as slower than compared dynamic languages. The relative speed difference is different per benchmark, but across the board Ruby is slower.

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.

Re:How to Fix Slow Code in Ruby by mindfulmore on Thursday May 14, 2020 @02:04PM (#23183091)
The article doesn't even discuss benchmarking Ruby against other languages, so I'm not really sure what you're on about. Couldn't resist taking a performance jab at Rails?

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.

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @04:39PM (#23185100)
> 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.

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.

Re:How to Fix Slow Code in Ruby by mindfulmore on Thursday May 14, 2020 @05:08PM (#23185466)
And yet Phoenix hasn't stolen a significant amount of market share from Rails.

> 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.

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @05:15PM (#23185577)
> And yet Phoenix hasn't stolen a significant amount of market share from Rails.

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.

Re:How to Fix Slow Code in Ruby by mindfulmore on Thursday May 14, 2020 @05:45PM (#23185933)
> For 3.5 years with Elixir this is the first time I hear that this is a problem. Any data to back this up?

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.

Re:How to Fix Slow Code in Ruby by joelbluminator on Thursday May 14, 2020 @06:48PM (#23186536)
> If Phoenix wants to increase their adoption, then I think they need to accept that things like this matter.

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.

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @06:52PM (#23186578)
Popular tech pays the bills of many people.

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.

Re:How to Fix Slow Code in Ruby by joelbluminator on Thursday May 14, 2020 @07:30PM (#23186975)
The people who flocked to Elixir thought it was gonna be the new Node / Rails. They're now finding out it's definitely not gonna be either of those things. It remains to be seen if they love it enough to stick around, or will we see a silent churn to the new hotness or even back to Ruby.
Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @08:06PM (#23187321)
Another gross generalization.
Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @06:41PM (#23186467)
> My point is that it doesn't come with Phoenix out of the box (unless something has changed?)

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.

Re:How to Fix Slow Code in Ruby by joelbluminator on Thursday May 14, 2020 @08:15PM (#23187399)
> the people who work with mainstream tech always assume that the smaller community wants more adoption

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.

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @08:21PM (#23187451)
But I am not here to argue what most do. The discussion here, at least from my part, was to encourage someone to give an alternative tech a try. I did, I kept paying my bills with Rails but got intrigued, became better and better with Elixir, rewrote some stuff in it, demonstrated actual hosting savings (and reports being generated in 7 minutes as opposed to 3 hours with the Rails code) and the rest is history.

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.

Re:How to Fix Slow Code in Ruby by mindfulmore on Thursday May 14, 2020 @09:36PM (#23187870)
> Neither practice is superior per se. Let's both admit that.

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).

Re:How to Fix Slow Code in Ruby by cutler on Thursday May 14, 2020 @08:02PM (#23187279)
Can you elaborate how Rails maitenance is "much higher" than with Laravel given that Laravel is PHP's version of Rails?
Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @08:13PM (#23187380)
This is what I have been told by a former Rails dev who is now doing Laravel. He said that Rails has much more automatically injected code that behaves in a way you can't anticipate intuitively (and many libraries encourage and extend that behaviour). As a former Rails dev myself I agree with that part.
Re:How to Fix Slow Code in Ruby by cutler on Thursday May 14, 2020 @08:35PM (#23187528)
But isn't this exactly what Symfony users accuse Laravel of - too much magic? Laravel's facades are as magical as anything in Rails and Laravel does a lot of code injection. It takes more than one man's opinion to establish a truth.
Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @08:38PM (#23187546)
In that case I have been misled by that acquaintance of mine and I apologise for unintentionally spreading misinformation.

(In that case, let's replace Laravel with Phoenix.)

[dead]
Re:How to Fix Slow Code in Ruby by cutler on Thursday May 14, 2020 @08:04PM (#23187304)
Another point worth mentioning is that Elixir is only optimised for lightweight processes. If you have to do any heavy lifting you're better off with Go or a JVM language, not Elixir. Forget math with Elixir too - it doesn't even have an arrary/vector data structure of its own. Instead it relies on Erlang's hacky implementation.
Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @08:12PM (#23187373)
Which is exactly what many Elixir advocates say.

Contrary to what you and others try and insinuate, we are very aware that the language is not a universal tech.

So yet again, you guys are smacking at a strawman that's very easy to beat. It's quite tiring to argue with stuff that I never said (and most of Elixir's community haven't said it either). But I think I'll give up for now. :)

Re:How to Fix Slow Code in Ruby by cutler on Thursday May 14, 2020 @08:31PM (#23187515)
That's not been my experience. Whenever I have mentioned the lack of arrays/vectors in the past I have been inundated with Elixir devotees asking me why I need them when Elixir has maps with numeric keys at which point I just throw up my hands in despair.
Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @08:34PM (#23187521)
Not denying it. Every community has bad apples.

It's not charitable to make assumptions for the entire community -- or the tech stack itself -- based on them however.

Seems like you've been chatting with the wrong people. A lot of the ElixirForum regulars -- me included -- are very practical and realistic folk who use several languages all the time.

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @06:44PM (#23186499)
This is putting words in the mouths of other people and is close to a flame bait. (Not to mention your gross generalization of the members of a not-small community.)

1. The Elixir community doesn't seem to aim for popularity (at least several important maintainers have said so on ElixirForum).

2. The tech is useful, scales very well and helps with the hosting costs by using less resources. That's an objective fact, proven in many blog posts where people sat down and measured.

3. Concurrency and parallelism are extremely important and will get more and more important as our CPUs can't get faster single-core performance and are just getting more cores.

It's OK if you don't care about any of those things. Really. I personally never got offended if something I like is disliked by others (as we should all).

But making a strawman and then crushing it is not a productive way to discuss either.

Re:How to Fix Slow Code in Ruby by joelbluminator on Thursday May 14, 2020 @07:40PM (#23187105)
> The Elixir community doesn't seem to aim for popularity (at least several important maintainers have said so on ElixirForum).

Wow, then why does every Rails thread has an Elixir guy trying to tell us what an inferior software we're running? For the sake of humanity?

> and will get more and more important as our CPUs can't get faster single-core performance and are just getting more cores.

I don't think it will become more important in web dev world than it is now. We're here churning out back office CRUD apps like crazy, I don't know what you're doing. For a small team trying to get something up and running this really doesn't matter and that's what Rails is optimised for. If scale ever matters, if you scale that big, you probably already have the resources to deal with it. For the few startups that have huge scale + have very scarce resources and Elixir works well for them - great! I have no issues with that at all.

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @08:09PM (#23187356)
> Wow, then why does every Rails thread has an Elixir guy trying to tell us what an inferior software we're running? For the sake of humanity?

If you prefer that melodramatic phrase. I've been a Rails dev for 6 years and I know that many current Rails devs don't dare try something else -- call it a survivorship bias, fear to abandon what pays the bills now, habits, and most of the time you won't be wrong.

Every now and then I speak with some of them and we exchange ideas.

And you should stop stereotyping, it's juvenile and definitely has no place in HN.

Re:How to Fix Slow Code in Ruby by joelbluminator on Thursday May 14, 2020 @08:49PM (#23187611)
> I know that many current Rails devs don't dare try something else

OK, and I'm the one generalising yes? Clearly you have zero bias towards the Rails devs.

How about simply becoming really good in a skill instead of jumping stacks every 5 years? To REALLY become good in Rails, to the point where you can write gems for activerecord for example that do something cool with arel, or follow the work Tenderlove is doing easily, this type of good takes effort. and time. Some people don't care at all and will happily switch and rebuild that expertise (or will never become experts in anything). That's totally fine. I value expertise, and won't make the switch for something that on the surface doesn't look like will benefit me at all (again, concurrency as it is in Rails is just fine for my career path and I think most Rails devs are on the same boat).

Re:How to Fix Slow Code in Ruby by joelbluminator on Thursday May 14, 2020 @07:44PM (#23187138)
> is close to a flame bait. (Not to mention your gross generalization of the members of a not-small community.)

You're the one who chose to use the term cargo cult a few comments above

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @08:10PM (#23187359)
Well, I've been to Rails meetups. I can bet a few bucks that you haven't been to Elixir ones.
Re:How to Fix Slow Code in Ruby by joelbluminator on Thursday May 14, 2020 @08:58PM (#23187659)
No I haven't. I'm not on a constant chase to find the better tech. I wanna write good code and come back in the end of the day to eat dinner with my wife. Even if Elixir is objectively better for web development than Rails (which I highly doubt), I wouldn't necessarily want to invest the effort in learning it. What's so interesting in learning 10 different ways of writing yet another CRUD app? Some people get a kick out of it. These people don't have kids lol.
Re:How to Fix Slow Code in Ruby by imhoguy on Thursday May 14, 2020 @05:05PM (#23185435)
When my small SaaS customer calls and asks for an extra extension at current hard times, then all I need is to open up Rails production console (pry) and live type in an ad-hoc code with auto-completion aid:

    $ rails c
    Loading production environment (Rails 5.2.0)
    [1] pry(main)> s = Subscriber.find_by_email('[email protected]')
    => #<Subscriber:0x000055dbb64c3bb8
     id: 12913,
     email: "[email protected]",
     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*.

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @05:08PM (#23185472)
I can do the same with Elixir's Phoenix, with exactly 3 lines in a production console like in your example.

What you describe is not exclusive to Rails.

Re:How to Fix Slow Code in Ruby by imhoguy on Thursday May 14, 2020 @05:20PM (#23185634)
Yeah, maybe I should rewrite one day, but customers wouldn't care much and I am content wit Ruby.
Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @05:28PM (#23185748)
That's fair. Nobody is making you do it. Use what feels right to you.

I simply felt compelled to point out that Rails is not at all as unique as many of its long-time users believe.

Re:How to Fix Slow Code in Ruby by FanaHOVA on Thursday May 14, 2020 @02:00PM (#23183039)
> Is it "slow" enough to matter? Probably not until you get to a medium scale.

Phew, I'm glad GitHub and Shopify's scale is still small.

Re:How to Fix Slow Code in Ruby by dijit on Thursday May 14, 2020 @02:18PM (#23183278)
Pedantry aside, we've reached a point in our industry where we can do a lot with horizontal scalability.

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.

Re:How to Fix Slow Code in Ruby by joelbluminator on Thursday May 14, 2020 @03:05PM (#23183919)
> services running those caches and persistence will not be written in ruby

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?

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @04:32PM (#23185018)
Is this an honest question? I honestly can't tell and I am not saying it to show disrespect -- just wondering if you are sarcastic.

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?

Re:How to Fix Slow Code in Ruby by antirez on Friday May 15, 2020 @04:54AM (#23190198)
Local caches and local node caches are both very useful. (That's why Redis 6 introduces this https://redis.io/topics/client-side-caching), but anyway from what I saw in the past, the major speedup of using Redis in such a context is that you want to use a shared very fast view that is global in nature. A simple to understand, but good example, is the leaderboard problem in multiplayer games that have million of users (Facebook games and such). Even if you have a local cache, and even if you have an additional store where you record the high score of each user, you need a global and very fast to update view of all the sorted scores, to tell the user its rank, users nearby, the rank of their friends. There are a number of problems like that that require to use different data structures and a global view. The problem is that using Redis with the Memcached mindset, will always severely limit the potential benefits.
Re:How to Fix Slow Code in Ruby by pdimitar on Friday May 15, 2020 @05:25AM (#23190354)
Yes. Redis has very valid use cases.

You're quite right: people using it as a mere cache don't get most of its benefits.

Re:How to Fix Slow Code in Ruby by joelbluminator on Thursday May 14, 2020 @06:24PM (#23186298)
> Why would you need an external service for that? It's adding complexity -- and likely hosting costs.

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.

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @06:45PM (#23186507)
Both are not equal at all. Redis you can definitely do without. A database you can't skip in most apps.

Sessions work quite fine in Elixir's local cache as well. :)

Re:How to Fix Slow Code in Ruby by joelbluminator on Thursday May 14, 2020 @07:25PM (#23186905)
> Redis you can definitely do without.

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.

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @08:06PM (#23187318)
Hint: it's most likely habit.

It's no accident that there's even a library that emulates OOP patterns in Elixir.

Re:How to Fix Slow Code in Ruby by ronjouch on Thursday May 14, 2020 @04:57PM (#23185334)
Interesting but not surprising; I'm being regularly pleasantly surprised by the Erlang/Elixir ecosystem :) . Can you precise what you're talking about when you say "Erlang/Elixir have built-in caches" ?

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.

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @05:07PM (#23185450)
Yes, ETS is the usual go-to but there's also `:persistent_term`[0] for very rare (or never) changing caches.

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.

[0] http://erlang.org/doc/man/persistent_term.html

[1] https://github.com/gyson/ane

Re:How to Fix Slow Code in Ruby by ronjouch on Thursday May 14, 2020 @05:17PM (#23185598)
Thanks!

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?

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @05:25PM (#23185718)
Oops, I forgot to include the most important link[0].

> 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.

[0] https://github.com/whitfin/cachex

Re:How to Fix Slow Code in Ruby by ronjouch on Thursday May 14, 2020 @05:33PM (#23185799)
Thanks again for the extra info and links :)

> "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.

Re:How to Fix Slow Code in Ruby by dijit on Friday May 15, 2020 @11:09AM (#23193033)
My point is that for all the talk of how performance doesn’t matter and that we can scale ruby, the real heavy lifting is not handled by ruby.

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.

Re:How to Fix Slow Code in Ruby by throwawaylabor on Thursday May 14, 2020 @03:12PM (#23184010)
> I mean, every programmer who funnels through university understands map reduce, and that helps on multi-core threading up to system job running

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.

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @04:29PM (#23184967)
> Phew, I'm glad GitHub and Shopify's scale is still small.

Phew, good thing they can afford to burn a lot of cash for hosting.

Re:How to Fix Slow Code in Ruby by tim333 on Friday May 15, 2020 @09:54AM (#23192174)
I guess that's so though it's interesting in the early days Github didn't:

>...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.

Re:How to Fix Slow Code in Ruby by pdimitar on Friday May 15, 2020 @10:47AM (#23192791)
Once a business grows to certain size and beyond the shareholders don't want to hear anything about tech rewrites. They are happy the product is working, they are not alarmed by slow response times (which GitHub has plenty of on my gigabit connection that streams 4k@30fps without any lag) unless there's a big customer churn, and hosting costs, even if big-ish, to them are just the cost of doing business.

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?).

Re:How to Fix Slow Code in Ruby by todotask on Thursday May 14, 2020 @02:14PM (#23183239)
I recall Shopify hired a dev who works on a project, FaastRuby, written in Crystal language for their web app.
Re:How to Fix Slow Code in Ruby by ryansouza on Thursday May 14, 2020 @02:09PM (#23183168)
I guarantee the tradeoffs matter to them
Re:How to Fix Slow Code in Ruby by sosodev on Thursday May 14, 2020 @02:18PM (#23183275)
I’ve seen videos on Twitter of the Shopify CEO saying that Ruby’s performance literally doesn’t matter to them. That it’s easy enough to scale it horizontally and the benefits outweigh the cost.
Re:How to Fix Slow Code in Ruby by joshmn on Thursday May 14, 2020 @02:36PM (#23183516)
Probably helps that Tobias also codes, not to mention contributed to Rails quite a bit.
Re:How to Fix Slow Code in Ruby by Thaxll on Thursday May 14, 2020 @03:26PM (#23184181)
Shopify is actually replacing slow ruby code with Go. And yes they ACK that Ruby is too slow. Also Shopify is a big monolith so it does not help.
Re:How to Fix Slow Code in Ruby by ch4s3 on Thursday May 14, 2020 @03:42PM (#23184365)
A monolith doesn't necessarily mean slower, even with Ruby. There are lots of opportunities to run less code on each request, do some work with the db, and to split off measure bottlenecks into services in a faster language. It's often good to build things quickly, find fit, and then carefully measure before you introduce calls over the network.
Re:How to Fix Slow Code in Ruby by Thaxll on Thursday May 14, 2020 @04:16PM (#23184826)
A monolith is a problem which they are also breaking down, when you want to make something faster it's easier to target the service that does it vs the giant app.

Edit: getting downvoted by people that don't work at Shopify.

Re:How to Fix Slow Code in Ruby by byroot on Thursday May 21, 2020 @11:47AM (#23259861)
I work at Shopify. I can confirm that what you are saying is totally false.
Re:How to Fix Slow Code in Ruby by tekstar on Thursday May 14, 2020 @04:42PM (#23185143)
Lol none of these statements are true
Re:How to Fix Slow Code in Ruby by meesterdude on Thursday May 14, 2020 @02:27PM (#23183379)
Stop painting ruby as slow. In benchmarks i've seen it's handily beat out PHP, which still runs much of the web. the ruby 3x3 goal, of getting running super mario at 60FPS, was if i recall correctly, already reached (or close to it) in ruby 2.6. https://developers.redhat.com/blog/2018/03/22/ruby-3x3-perfo...

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.

https://news.ycombinator.com/item?id=17220967

Re:How to Fix Slow Code in Ruby by jerf on Thursday May 14, 2020 @04:21PM (#23184869)
"Sinatra + Sequel is already very competitive in web performance with Go"

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.)

Re:How to Fix Slow Code in Ruby by e12e on Thursday May 14, 2020 @05:19PM (#23185627)
Ed: regarding the benchmark, as best I can tell, the top listing for ruby runs under puma:

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.

Re:How to Fix Slow Code in Ruby by lizmat on Friday May 15, 2020 @07:49AM (#23191059)
Please note that Perl 6 has been renamed to Raku (https://raku.org using the #rakulang tag on social media). Also: not sure how long ago you tried using Perl 6 and found it slow. If your data is from the Parrot days, it is definitely out of date: the MoarVM backend is at least two orders of magnitude faster.
Re:How to Fix Slow Code in Ruby by b2gills on Monday May 18, 2020 @09:05PM (#23230246)
While Raku is generally slower than other languages, there are times when it is is faster than those same languages.

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.)

Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @04:45PM (#23185185)
Not sure how "overblown" the performance issue is. I rewrote two commercial Rails apps to Phoenix and had both versions of both apps run side by side for two months. The Phoenix apps consumed 7x-11x less RAM, accomodated 9x-10x more users on identical hosting instance, and had almost 10x quicker response time.

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.

Re:How to Fix Slow Code in Ruby by meesterdude on Friday May 15, 2020 @07:23AM (#23190891)
> I am willing to argue with facts but you just added another non-factual opinion to the pile.

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.

Re:How to Fix Slow Code in Ruby by pdimitar on Friday May 15, 2020 @11:20AM (#23193179)
> I'm not interested in arguing with someone who doesn't respect others opinions, nor did I make baseless claims: I cited resources.

Performance metrics are not opinions.

Re:How to Fix Slow Code in Ruby by wolco on Thursday May 14, 2020 @03:10PM (#23183983)
Re:How to Fix Slow Code in Ruby by meesterdude on Thursday May 14, 2020 @03:16PM (#23184060)
I've seen conflicting benchmarks on this showing different results - possibly has changed over time, or run different comparisons. What you linked seems current at least.
Re:How to Fix Slow Code in Ruby by cygx on Thursday May 14, 2020 @03:28PM (#23184206)
Also keep in mind that as far as performance of dynamic languages goes, all of the P* languages (Perl, Python, PHP, and... Ruby ;)) have been left in the dust by the front-runners (eg Node.js or LuaJIT). Perl used to be king a long time ago, eventually, PHP took pole position, and maybe now it's Ruby's time to shine. But being leader of that particular pack could mean you're nevertheless still 'slow' depending on context.
Re:How to Fix Slow Code in Ruby by VWWHFSfQ on Thursday May 14, 2020 @04:03PM (#23184645)
I wouldn't put node in with luajit. Luajit is about 4x faster than v8 JavaScript. So it's still in the slow category
Re:How to Fix Slow Code in Ruby by cygx on Thursday May 14, 2020 @04:20PM (#23184867)
Depends on the benchmark. Eg at the bottom of this page [1] can be found a simple fib(40) comparison of a few runtimes.

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....

Re:How to Fix Slow Code in Ruby by stevebmark on Thursday May 14, 2020 @05:48PM (#23185979)
No, both your post and this reply are dogmatic. As I said, Ruby is the slowest modern dynamic programming language (and it's much slower than Perl). I really wish the Ruby community would listen to valid criticism. All dynamic languages are deeply flawed in some way, especially Ruby, and most ecosystems are open to learning from others.
Re:How to Fix Slow Code in Ruby by meesterdude on Friday May 15, 2020 @07:16AM (#23190845)
> All dynamic languages are deeply flawed in some way, especially Ruby

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.

Re:How to Fix Slow Code in Ruby by igouy on Thursday May 14, 2020 @06:59PM (#23186636)
> …much slower than Perl

To do some things but not others?

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Re:How to Fix Slow Code in Ruby by saagarjha on Thursday May 14, 2020 @02:45PM (#23183641)
People used to think JavaScript was too dynamic to optimize, too. Then people poured time and effort into it and now good JavaScript virtual machines can hold their own against competing implementations for other languages.
Re:How to Fix Slow Code in Ruby by pdimitar on Thursday May 14, 2020 @04:40PM (#23185111)
...While still not being multicore. I feel that those efforts you mention don't go far enough.

And I am pretty sure backwards compatibility will continue dragging JS down for quite a long time still as well.

Re:How to Fix Slow Code in Ruby by igouy on Friday May 15, 2020 @11:27AM (#23193272)
Re:How to Fix Slow Code in Ruby by pjmlp on Friday May 15, 2020 @02:19AM (#23189462)
Surely they are, via workers and worklets.
Re:How to Fix Slow Code in Ruby by goatlover on Thursday May 14, 2020 @07:59PM (#23187257)
It's interesting because Lars Bak was optimizing Smalltalk and Self VMs in the 90s.
Re:How to Fix Slow Code in Ruby by gscho on Thursday May 14, 2020 @01:58PM (#23183007)
We can't forget to consider the cost of productivity gains and developer happiness from using ruby. It can significantly out weigh the cost of some additional hardware.

If it doesn't bring you that, then we have a problem!

Re:How to Fix Slow Code in Ruby by igouy on Thursday May 14, 2020 @07:36PM (#23187063)
> …but all benchmarks show Ruby as slower than compared dynamic languages. The relative speed difference is different per benchmark, but across the board Ruby is slower.

No & No.

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Re:How to Fix Slow Code in Ruby by barrkel on Thursday May 14, 2020 @04:20PM (#23184865)
In my simple relative comparisons of a couple of sample programs, I've found Ruby to be about as fast as, or faster than, Python, and slower than JS.
Re:How to Fix Slow Code in Ruby by cutler on Thursday May 14, 2020 @08:15PM (#23187394)
Ruby and Python, for a long time, have been almost identical in laguage benchmarks and Python's lack of speed hasn't stopped it being the most adopted language by some metrics. So this whole speed thing is a red herring.