Scaling a Rails app (Part 2 of 3) no comments
This the second part for a summary about solutions to help better computing of your rails app (1st part).
Application
To help your application to focus on replying fast to user, you can use a distributed queueing to give the job to other processes:
And second thing, you can cache things you don’t need to compute for each request, this can incredibly increase the response of your server, but need to modify your code and it s recommend for very big sites:
Back end
DB
For your database you can find some sql proxy, but I haven’t tried it yet. You have also the way to replicate your databse and serve data from several servers.
- sql relay
- use jruby with a jdbc pool connection and caching
Important things you have to check about your databse is if you have the right indexed fields. You should find some tools on mysql helping you to find where indexes missing. Check about cache too.
A last way is to serialize some of your data in a single object.
Mysql
Otherwise you can configure your mysql with some optimized configuration (mysql.ini):
- skip-name-resolve
- query_cache_size = 52428800;
- query_cache_type = 1
And in your ActiveRecord object you can use the * parameter.
Filesystem
Optimizing the filesystem, in other sense than choose a good OS, can been done with not overloading the management of files by using some *rules:
- max 10K files / subdir
- 16 top level / 256 sub / 10K per sub dir
- use a hasher to manage files
OS
As we have seen, file and memory management are keys of good performances. And these are managed by OS. The two best OSs mentionned are
- Sunsolaris
- FreeBSD (can be use for a all in one stack), avoid the version 5
And upcoming, last part of this article, some home made benchmarks for my own purpose.




