I was working on my project Kwaab and suddenly because of massive traffic (1500-2000 hits per second), the site starts slowing down. Page load time was increased to 10 seconds and sometimes even more than that. We tried to increase the server, still no significant improvements. Here are some things we have already done:
- Landing Page is cached
- 6GB of RAM and only 800MB is used
- CPU utilization is less than 40%
- User uploaded images are already coming from Amazon s3
- Use cache control and expiry headers
- Compress images using smusher
- Compress js and CSS and lot more basic things we should do.
But still, the site is super damn slow, because the issue was loading time for assets. As my assets were coming from Linode itself and due to high traffic of the website, the client was waiting for assets for like 5 seconds just for the logo, etc., and that was slowing my site. I got a life saver i.e. asset_sync a gem to deploy your assets on Amazon bucket :)
- Install the gem: If you want, you can put it within your :assets group in your Gemfile.
- Create a file asset_sync.yml in your config directory or check out the inbuilt generator i.e
which will generate a file in app/config/asset_sync.yml. Now I have this asset_sync.yml file, but you can configure it as per the docs of the gems.
- Place these lines of code in your production/staging environment file:
- Down the above code. Place these lines of code which will tell rails to get the assets from here.
- Also make sure your production/staging environment files have:
- config.assets.digest is set to true.
- config.assets.enabled is set to true.
That’s it. Now just deploy your Rails application and all the assets will be pushed to the respective bucket on Amazon :) and it solved my server issue to with a considerable amount. We made some more tweaks. I will post them soon.