oldmoe 🍉 Profile picture
Sep 4 7 tweets 2 min read Read on X
Every now and then someone from the Rails sphere would make a statement about performance (1/2 req/core/second as the norm 🤦) or (15K reqs from a mega machine) that would sound ridiculous to outsiders who start speaking about how slow Ruby is and delusional are Ruby devs

1/n
Ruby is not slow, in the sense that for building web apps it is in the same league as PHP, Python and similar interpreted languages.

You can build really fast web apps in Ruby, microsecond request latencies, and the toolbox has vast options to help you achieve that

2/n
But all that doesn't come close to what something as big as Rails is doing. Rails does A LOT of work per request, and that's an understatement. All the flexibility you get is due to that heavy lifting under the hood. Replicating all Rails will most likely yield similar perf

3/n
That's not entirely true though, because some parts in Rails were built with extreme flexibility in mind and as a result dog slow, ActionView for example supports bizarre options at the cost of being very expensive CPU wise

Rails sphere response is always it doesn't matter

4/n
But the reality is a bit more subtle, if your cost per req is lower than your revenue per req then all good, you can even invest in building jit engines to shrink the cost more.

If your app is high usage, low revenue per req, at one point it won't make economical sense

5/n
As a community, we can make the situation 10x better though, we can fix ActionView and similar bottlenecks

We can promote solutions like Phlex and use a much faster Rails today. Or someone can deliver an ERB style engine that's really fast and we can serve all tastes

6/n
We need to appreciate performance more, especially at the core of Rails, we need not settle for or advise others to settle for low performance for their Ruby/Rails applications.

7/7

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with oldmoe 🍉

oldmoe 🍉 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @oldmoe

Aug 30
Having worked with a lot of budding developers, I have found 3 learning assignments in particular to be eye opening, both for them and myself

When you are new, many things seem just too hard, but when you build even one of them, u gain knowledge & confidence to do a lot more

⬇️
1. Build a web server
An actual http 1.1 web server that responds to get, post, put & delete.

Then make it concurrent, threads, forking etc.

Then run rack apps (in the context of Ruby)

You will have a much deeper understanding of web development and web frameworks after.

⬇️
2. Build an on disk data structure
I opt for Skip Lists, building on in memory is trivial, building it on disk is much more involved

Build a kv store, implement get, set & delete, search by key & by value

You will have a lot of appreciation of databases afterwards

⬇️
Read 7 tweets
Aug 24
In 2014, I had two Ruby apps with over 1M MAUs combined, both were hosted on a single server that cost us ~$75.

It was composed of. Multiple Ruby processes running Sinatra, processing requests in fibers, and each process connects to a BerkeleyDB shard (with fixed hashing)

⬇️
Each BDB shard had data belonging to a set of users, shards can be combined or split, up to 256 of them. Each process had exclusive access to a single shard.

Since this was running web games, we had to have validation logic running on the server replicating the game logic

⬇️
We used background, stateless node.js processes for that purpose, the Ruby process would pickup a backend, send the game state to it for processing and get the results

By using Fibers we did all these requests concurrently and the node.js backend could scale as we needed

⬇️
Read 5 tweets
Aug 24
A typical Ruby/Rails web app performance is usually limited by one of the following (depending on usage patterns):

1. Compute
2. Memory
3. IO (network & disk)

The good thing is, you can ease these without having to touch your application code.

Read on ⬇️
1. Compute

It's everywhere, even db ops can be compute intensive. Though Ruby itself is usually the culprit, specially if there is a lot of logic or template/json rendering

Quick fixes:

- Enable Yjit
- Oj gem for JSON
- A fibered server like Falcon (less context switching)
2. Memory

Ruby is known for being memory hungry, your app processes can consume a lot of memory specially when you use many processes/threads

Quick fixes:
- Use Jemalloc
- A preforked server like Falcon
- A fibered server like Falcon (less memory fragmentation)
Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(