What impact, if any, does having A LOT of gems have on the performance of your Rails app?
I would say the biggest impact is when your rails app starts up, as the gems are all loaded into memory. If you have lots of gems loaded, chances are you'll also have a lot of code loaded that your app doesn't use, so one way to cut down on the memory usage is to take advantage of copy-on-write support in the linux kernel. One way to do this is to use ree and unicorn, as github did
This is just an assumption though. You should always profile your app when dealing with timing and memory questions. It can make a really useful blog post.
no impact on performance. It's just a problem of memory. You memory can be very big with so much gem and if you really use it.
Related
I need to develop an e-commerce site for my client.
He wants it to be very fast (1.25 second or less for each page).
I've had my criterion - 3 seconds.
So 1.25 second is very challenging.
He showed me a website that loads very fast.
http://www.papayaclothing.com/shop/
It's impressive.
I will develop with Spree e-commerce solution (Ruby on Rails).
However, I don't think Ruby on Rails can perform that fast.
Any advice for me?
Thanks.
Sam
Because this is a vast subject, this answer is a community wiki, feel free to improve this answer
Website loading speed depends of many factor : language, framework, DB, CPU, RAM, caching, ...
By the way, the whole thing depends of the worse element. I don't think that Ruby or Rails are the limiting factors here.
To start you can see if Spree is a good framework. Here is a benchmark of Spree in different hosting and comparing to a pure Rails app : http://blog.endpoint.com/2011/05/spree-performance-benchmarking.html
As you can see, this go from 0.5s to 6s ! You can notice that Spree version inpacts a lot on performance. Unfortunately last versions are not on the benchmark... You should try to find an up to date benchmark. You can also notice that a raw rails app is, at first sight, faster.
Next you have to review your hardware : what is your server ? Dedicated or not ? How many CPU and RAM ? Can you increase ?
I think DB is also a thing to watch for a e-commerce case, because I can imagine you have a lot of products. So you can test different DB engines, and see in Spree community what is the recommended one.
Next you can interest you in caching : http://guides.rubyonrails.org/caching_with_rails.html
To go further you can try some memcached store for your putting your cache in RAM : http://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-memcachestore
Find slowest actions (New Relic is great and their RPM Lite is free though it only reports over last 30 min) and analyze to see if they are render-heavy or db-heavy. My guess would be that your case is db-heavy.
If that's the case, then optimize your queries with eager loading eliminating n+1 problems as well as making sure that only relevant data is returned, e.g. don't do User.all if you only need username and email.
Then you should cache whatever you can, e.g. where real-time data is not crucial.
For more info: http://asciicasts.com/episodes/202-active-record-queries-in-rails-3
and
http://synaptify.com/?p=106
You have a few options here, mentioned in the previous answers.
For client side performance improvements, I'd highly recommend WebPagetest, YSlow, and Yahoo's Best Practices for Speeding Up Your Web Site as good resources.
For strictly Rails performance, I'd suggest Rails' docs on caching (already suggested). I frequently use Rails low level caching. Full page caching can apply to some types of pages, but typically do not work for product pages if you have inventory that fluctuates a lot.
Spree has some performance issues because it is a generic ecommerce solution with many features that you may not use that add bloat. Make sure you have database indexes and consider pursuing profiling server processes to see what's run the most & takes the most time. It's highly probably that you will need to override some of Spree's functionality to speed things up.
Finally, Google considers 0.25 seconds to be the standard for a speedy website.
Is there a way to free up memory used by required gems? My Rails app grows in memory usage and I would like to use gems only when I need them and after that free them up, IF this is possible.
Thanks!
The whole purpose of a memory managed programming language (Ruby) is to avoid developers having to concern themselves with such issues.
If memory does become a sticking point, you'll need to profile the memory by using the following tools
ruby/ruby on rails memory leak detection
Although your control over memory is limited to ensuring memory leaks are avoided and the overall architecture is inline with best practices. An example is ImageMagick takes excessive memory, so rather than having images being converted by all rails mongrels/passengers, restricting the conversion to dedicated ruby services, so as to avoid a large memory footprint.
The Garbage Collector do it this best to you. There are no better solution. Check all part where you can have some memory leak and avoid it. Use less of gems too.
I made some searches on Google, and I read some posts, articles and benchmarks about Ruby on Rails being slow and I am planning to build one website that will have a good amount of users inserting data and there will be some applications to process this data (maybe in Ruby, you can help me choosing the language).
What is the real performance of Ruby on Rails with large traffic ?
Thank you !
You are asking a lot of questions, so I'll just try to answer you're first one. It is true that ruby, as a language, is slower compared to some others. This means that rails may not perform as well as some other frameworks. However, most websites will not receive the sort of traffic that poses a problem. The productivity gained by using rails most definitely outweighs the potential performance issues you may have later.
Dynamic web pages are slower than static, in general. Scale and performance are more about good design and caching than language choice.
I have to run a Web server with many services on an embedded server with limited RAM (1 GB, no swap). There will be a maximum of 100 users. I will have services such as a forum, little games (javascript or flash), etc.
My team knows Ruby on Rails very well, but I am a bit worried about Rails' memory usage. I really do not want to start a troll here, but I am wondering if there are any serious (i.e. documented) benchmarks comparing Rails, Django, CakePHP or any other PHP framework?
Could you please point to benchmarks or give me your opinion about Rails' memory usage? Please please please no troll.
In terms of memory usage it's generally going to be Python > Ruby > PHP, which of course leads to Django > Rails > CakePHP. Not just memory but that also tends to hold for raw performance. EDIT: Also worth noting that there are, of course, no absolutes here. There are plenty of usage scenarios in which Ruby will beat Python, hands down. I think we can all agree that Ruby and Python will always beat PHP, though :)
Here's a straight-forward 3-way benchmarking (with Symfony on the PHP side of things) that bears out the above: http://wiki.rubyonrails.com/rails/pages/Framework+Performance. Though of course it's easy to find stats to support your own viewpoint :)
That said, it's still very easy to make a crappy, slow, and inefficient Django application and a lean, fast, and efficient Rails application, or vice-versa. Skill, knowledge, and expertise with the system you are using will do far more for its memory and performance footprint than just the framework itself. Database optimizations, server choices and architectures (Apache vs. proxy setups using nginx/lighttpd, etc.), and fundamental design decisions are likely going to overwhelm the framework's inherent characteristics pretty quickly.
So I guess what I'm saying is if your team knows Rails, and your expertise lies in Rails, I would stick with Rails.
I just stumbled upon this benchmark which looks pretty good. It just gives data about Rails' memory usage (and performance) but it only partially answers the question because it does not compare Rails with other frameworks.
http://www.rubyenterpriseedition.com/comparisons.html
My own experience is that Rails memory usage can be high, especially on 64 bit machines (min. is around 95-100 MB with thin as web front-end). PHP tends to be used with different patterns so it is a bit difficult to compare directly.
Hypothetically, if I were to build the same app using a few popular/similar frameworks, say PHP(cakePHP|Zend), Django, and Rails, should the memory consumption of each be roughly the same?
Also, I'm sure many have evaluated or used each and would be interested in which you settled on and why?
Code with whatever framework you like best. Then pray your app is popular enough to cause memory problems. We should all be so lucky.
No, it will absolutely vary wildly from one framework to another.
That said, in most cases the memory footprint of the framework is not the determining factor in site performance nor in selection of a framework. It's usually more a matter of using the right tool for the job, since each framework has its own strengths and weaknesses.
It is hard to efficiently say, I would say that PHP frameworks will have mostly a similar footprint, which is typically less than other frameworks such as Rails and Django. But it depends what you include as rails, such as mongrel (rails server proxy). Overall it depends on your code as well however PHP will most of the time give an easier time on the server. (Without any language Bias, I use both PHP and Rails)
Just for getting some perspective let me report a real case memory consumption using a Smalltalk web framework AIDA/Web.
For running 40+ websites on a single Smalltalk image on a single server it currently consumes 330MB of memory.
The only one of those frameworks I have used is CakePHP. I found that it's not to bad footprint wise however it is a lot more heavy that normal PHP without using a framework obviously but can be a good trade off.
A good comparison of some of the most popular PHP frameworks can be found at http://www.avnetlabs.com/php/php-framework-comparison-benchmarks.
Memory is cheap these days. Go with what will make your development easiest (which is usually what your team knows best).
But... In my experience, Django isn't terribly memory hungry. I've run it on my shared host with less than 100 MB of RAM. But my experience is sheerly anecdotal. YMMV. If you go with Django, here are some tips to keep memory usage down.
EDIT: And don't go with zope if memory footprint is important to you.