← Back to Upcase

Scaling and Breaking the app


(Charlieanna) #1

Are their any tools for checking how my app would break if the users amounted to 100000 and also when each of them have logged in simulataneously?

I just need to understand how scaling works because I am often asked in interviews how well versed I am with handling scaling a website. I have a website plus an app for Android and iOS. One of the web apps does the work of sending push notifications to all the users who have currently signed up.


(Matthew Sumner) #2

When your scaling an application, your application code is not the only thing that could break under heavy load. Your application code might not be great but with decent hosting you may handle 100000 simultaneous users. If your running on your development machine using webrick your app will grind to a halt. In production you’ll be running with multiple spawned processes and if the load increases you can always dial up how many processes you spawn.

Usually the best course is to start out with your app out there in production and as it grows address these issues. Once you have enough users that you can afford some monitoring grab something like newrelic. This will show where bottlenecks in your app are using real user data. As it grows more you can then put more money into your hosting solution. I assume your not planning to go from 0 to 100000 users on day one so don’t worry about it. You could spend all your time optimizing your app only for it never to go above 50 users.

If you still need to do some load testing (i.e. you need statistics for your boss/investors) there is rails-perftest. I’ve never used it and it was included in rails 3 but pulled out in rails 4 but I’ve heard the documentation is very good. By the way if you get to the point where you need to fix your app to handle 100000 users then that’s a good problem to have.


(Charlieanna) #3

Thanks again…Ok but then also what are the different ways in which app an could be optimised so that it doesnt break? How do you even test with a load of 50 simultaneous users? One of the hardest things I find is testing. I have been trying so hard but testing seems so difficult to me. I guess this is one are where a mentor could help me.


(Joe Ferris) #4

This is a huge topic, but here are a few general pointers:

  • Make sure to use something like New Relic to monitor performance. This will help you see which parts of your application are getting slow as traffic increases, and can provide alerts when things start to go bad.
  • Use a hosting infrastructure that makes it easy to scale horizontally, like Heroku. As the number of concurrent users increases, you can add more dynos or servers to handle the extra load.
  • Use a fast, reliable database like Postgres and use the database layer to do the heavy lifting. Pushing as much filtering, sorting, and transformation into the database layer as possible is usually best. In general, databases are fast and Ruby is slow.
  • Use indexes to keep your queries running as quickly as possible.
  • Outsource as much as possible to third party services. Services like Heroku Postgres and Sendgrid can take the load off your application by having somebody else’s servers perform the slow parts. You don’t need to worry about scaling your email server if somebody else is delivering your email for you.

It’s difficult to give generic advice about optimization, because maybe optimizations will make one pattern of interaction faster but make another slower. For example, you can optimize your database to be as fast as possible for reading with heavy indexes and views, but this will make writing slower because each write needs to update all those indexes.

The best general practice is to obey common sense as you start, monitor as much as possible, and tune your application as traffic patterns reveal what the slowest interactions will be.