3

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

Sam Kong
  • 5,472
  • 8
  • 51
  • 87
  • 1
    Use faster servers, caching, etc? Why do you think Rails cannot be fast? – Dogbert Feb 03 '12 at 08:00
  • Network performance is very often a bottleneck, so you need to carefully optimize your resources and lazy-load stuff you don't really need. Tools like Audits panel in Chrome Developer Tools (or Safari Web Inspector), PageSpeed, YSlow will help you a lot with this task. – Alexander Pavlov Feb 03 '12 at 08:11

3 Answers3

9

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

Thomas Guillory
  • 5,719
  • 3
  • 24
  • 47
3

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

egres
  • 294
  • 1
  • 8
2

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.