7 ms·
> If the application can’t saturate the CPU, there’s a fundamental problem. It’s a shame because it makes adding more servers less efficient. Money is being was
by Hendrikto 3y ago
> If the application can’t saturate the CPU, there’s a fundamental problem. It’s a shame because it makes adding more servers less efficient. Money is being wasted on hosting costs, and this should be a priority to address.
Talking about efficiency being a priority, but using RoR. I guess that is one way of saturating the CPU.
- stouset 3y agoIf your application can’t saturate the CPU, Rails probably isn’t your bottleneck.
- resonious 3y ago[flagged]
- block_dagger 3y agoThe author means efficiency in terms of the software that is running, not efficiency in terms of all possible optimizations such as switching to a different lang.
- irjustin 3y agoWhile you missed the point of the saturation comment, this is why we love AWS Lambda over ECS+Fargate. Rails has really poor startup time due to loading all codepaths. We switched to Django and it runs beautifuly on AWS Lambda where our CI is more expensive than actual server costs. We're a b2b application so traffic is quite low so we REALLY don't saturate the CPU in a normal Fargate setup.
- cocoflunchy 3y agoI'm surprised to see a mention of Django when talking about fast startup times! This is one of my main issues with Django at the moment. How big is your project? Our ~500k lines app takes multiple seconds to start, which is why I'm not really investigating a lambda-style setup... Do you have specific strategies to make startup fast?
- irjustin 3y agoApologies on the lay reply. Your app is significantly bigger than ours, so grain of salt. We play very close attention to what's loaded on startup. There are two key tricks. 1. Heavy libraries/packages load at runtime and are only in the "background job" codepath. def my_heavy_func(): from heavy_library import sum_heavy_function sum_heavy_function() vs the import at top of file. 2. Limit which apps are loaded via `INSTALLED_APPS`, again no heavy packages. Lambda is SUPER nice for us. The bottleneck becomes the DB. Webserver can basically never go down on its own as you can create 1000x by default. Best of Luck!
- eek2121 3y agoI have never seen Ruby on Rails be a bottleneck, and I have been using it since version 2. Most bottlenecks are either that database choices or poor code/design choices by developers. That is especially true today.
- ndriscoll 3y agoDoesn't rails not have multithreading? How do you gather requests to batch your database calls? A coworker made similar claims to me about Laravel, but the framework really encourages you to do half a dozen database queries in even a pretty minimal request, and for example implemented bulk inserts as a for loop that did single inserts. If you didn't know better with an access pattern like that, you might think the database is the bottleneck long before it actually should be. Is Rails different? My sense was they are very similar.
- _chap 3y agoRails supports multiple threads: https://guides.rubyonrails.org/threading_and_code_execution.html https://guides.rubyonrails.org/threading_and_code_execution.... Rails has some tooling to help with query bloat: https://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations https://guides.rubyonrails.org/active_record_querying.html#e...
- ndriscoll 3y agoInteresting. My understanding is that part of why mastodon is so slow/resource hungry is that it serializes background tasks to redis for a sidecar process to pick up, and that that's the normal way to do things. If rails has a concurrent runtime, why don't they just run background work directly?
- jmuguy 3y agoRails isn't super opinionated about database writes, its mostly left up to developers to discover that for relational DBs you do not want to be doing a bunch of small writes all at once. That said it specifically has tools to address this that started appearing a few years ago https://github.com/rails/rails/pull/35077 https://github.com/rails/rails/pull/35077 The way my team handles it is to stick Kafka in between whats generating the records (for us, a bunch of web scraping workers) and and a consumer that pulls off the Kafka queue and runs an insert when its internal buffer reaches around 50k rows. Rails is also looking to add some more direct background type work with https://github.com/basecamp/solid_queue https://github.com/basecamp/solid_queue but this is still very new - most larger Rails shops are going to be running a second system and a gem called Sidekiq that pulls jobs out of Redis. In terms of read queries, again I think that comes down to the individual team realizing (hopefully very early in their careers) that's something that needs to be considered. Rails isn't going to stop you from doing N+1 type mistakes or hammering your DB with 30 separate queries for each page load. But it has plenty of tools and documentation on how to do that better.