0

I am setting up a single Debian server serving Magento with Mysql. High load is expected (millions of hits per day). I've been reading various people's comments and found so many different setups but I am not sure what to do if I want to. Load balancing between several servers would of course be nice but I have only one server. So how about this?

Varnish in front of nginx and apache, where nginx does only static data and apache dynamic.

Or would be a better idea to put varnish in front of apache only? So nginx is in front and having static data directly served by nginx and dynamic apache pages via varnish?

öde
  • 167
  • 4
  • I agree with all the others, and I suggest you start with nginx for both dynamic and static content. – 3molo Mar 05 '12 at 09:54

3 Answers3

5

I can't think of any reason (other than deliberately bad configuration) that would make your proposed setup A. better than or worse than your proposed setup B.

Do you have a specific problem that you are hoping to solve by putting Varnish in front of Apache? Or Varnish in front of nginx?

If you don't, you are falling prey to Cargo Cult System Administration:

"This guy is successful and he uses Varnish in front of nginx and Apache, so if I use Varnish in front of nginx and Apache I will be successful too."

Traffic rarely arrives so fast that you don't have time to plan what to do with it. Do you have a plan that will drive this much traffic (say, Stephen Fry has promised he'll tweet about your site as soon as it's up.) or are you just very optimistic? If not, just get the thing online and working. Premature optimization is the root of all evil. You will have plenty of time to optimise the site once you know what your traffic looks like and where your bottlenecks are.

Simpler is usually better. If you can ditch one or two of the three different pieces of web serving software you have mentioned you will probably find the CPU usage and memory usage on the server are significantly lowered. Maybe CPU and memory usage are your bottlenecks.

Some things that will probably make a difference to how much traffic you can handle as you grow are

  1. Watch your MySQL slow logs and tune the queries and indexes until the slow queries go away.
  2. Making sure you set your caching headers properly.

tl;dr

Don't worry about traffic until you've got some.

Ladadadada
  • 26,337
  • 7
  • 59
  • 90
  • Thanks for your comments! Well, I recently launched another website which was running smoothtly on a server until the website was mentioned all over the net at places like reddit.com and all of a sudden the server (LAMP) practically crashed with a server load reaching 30-40-50 and the server had to be rebooted. This is a similar site and I want to avoid this happening again. I sort of "know" the site will cause very heavy load, not just temporarily but for a long time. I heard it's good to use a cache like Varnish so I thought I'd try that, in combination with nginx for static stuff. – öde Mar 05 '12 at 16:47
  • 1
    +1 for cargo cult ..... amazing LOL – The Unix Janitor Mar 08 '12 at 23:52
2

First of all, I totally agree with Ladadadada answer, that...

  • Premature optimization is the root of all evil
  • Simpler is usually better, mostly

You shouldn't optimize, because you could get more traffic. Optimize, when you need to optimize, i.e. when you experience traffic peaks right now OR when you definitley know, that there will be huge traffic peaks (e.g. out of marketing actions).

Most important: analyse your system! Do benchmarks before (and of course after) your optimizations. You must know, what exactly is your bottleneck and what to optimize.

And now, the Magento specific part... :)

Although if I stick to Ladadadada's opinion, that you shouldn't follow just a(nother) Cargo Cult I recommend to install Varnish.

Why? Because a standard Magento installation isn't really fast without optimization. Okay,.. it tend to be f**king slow.

What to do, to speed up Magento:

  • Install APC cache
  • Use Memcached as fast Magento backend
  • Put your Magento cache files onto a RAM disk (tmpfs)
  • Put Varnish in front of your webserver software (Apache or nginx, doesn't really matter as long as you use Varnish) to cache static content and complete pages (like the Fullpage Cache of Magento Enterprise)

In order to use Varnish in a efficient way, you have to adapt Magento, so that complete pages can be cached and dynamic parts (e.g. cart widget) will be loaded additionally by the client's browser (using JavaScript).

There is also a module available for that: http://www.magentocommerce.com/magento-connect/pagecache-powered-by-varnish.html

However, I also recommend you to add at least 2 more servers to your system, if you planning to increase your traffic dramatically.

Using only one server is,... well - the perfect SPOF (Single Point of Failure) I can think of. :) Using multiple servers isn't only about loadbalancing and scaling. It's about high availlability. What happens if your single server cannot handle the traffic/load anymore? Yes, it will go down, your shop is offline and the vast amount of new customers won't be able to see your nice products- in fact they will see some ugly error meessages. So basically,... you will be pretty screwed.

Before optimizing your single server for the best performance, you really should plan and setup a failover strategy.

Maybe only two servers? Each of them with a webapp stack and a database? Or three servers,... two webapp nodes and a dedicated database server? Best would be 4,... two webapp nodes and 2 database nodes.

Doesn't matter how exactly it will look like,... but you have to eliminate your single point of failure.

Wish you all the best,... (traffic) growing pains are the best pains. ;)

  • Hmm...while I appreciate your feedback, I don't quite agree with the mantra that "Premature optimization is the root of all evil". I can see why, but if I launch a website and it's starting to become busy, I don't want to risk taking if offline while installing proxies and caching and whatever else. But sure, I agree with the KISS principle. But to keep it simple can also mean to make sure the server has what it needs prior to launching the site, rather than causing interruptions on a live production website. – öde Mar 05 '12 at 16:51
  • Regarding your Magento tweaks, I agree. I already tried APC+Memcached+tmpfs on another server and it made the site much faster. (I also did stuff like mounting the disk with noatime and much more). So I also think Varnish would be a good idea. I didn't know about the pagecache module, so I appreciate you telling me!...and yes I know a single server is not ideal but to be precise there is one web server and one dedicated database server so it's not too bad. – öde Mar 05 '12 at 16:54
  • More servers = more complexity = more to go wrong. A highly available solution is not going to help in any other situation than hardware failure. Monit/checksrvd will take care of automatic software restarts. If you have extremely high load load, it would simply failover to the other machine. So your alternative is to have a loadbalanced, highly available 2 server set-up. But if the OP doesn't know the best way to order his web servers, they certainly couldn't effectively configure and support this. – Ben Lessani Mar 16 '12 at 21:47
  • @sonassi - Of course, you shouldn't just add two servers and install a passive/active solution, it's always the best way to have a loadbalanced solution. But if he cannot afford 4+ servers, it's better to have 2 servers in a active/passive setup than only one server. And servers doesn't go only down on high traffic. Think about just a simple hardware failure... And well,... sure more servers = more complexity, but at some point you need to scale in a horizontal way using more servers. but at this point you should earn enough money to hire at least one sysadmin. ;) – Martin Rothenberger Mar 18 '12 at 17:35
1

Well, I'm not sure how anyone is reliably advising you without knowing ...

  1. Is this going to be for 1 store, or multiple stores (reselling)?
  2. What is the full exact server specification?
  3. What are your targets for traffic (hits, pageviews, bandwidth commitment)?
  4. Do customers predominately search or browse categories?

The advice we give to our customers ...

If you need to re-sell hosting

Nginx > Apache > PHP-FPM

That keeps .htaccess support for your customers, security (chroot/multiple php.inis) from PHP-FPM and static file performance from Nginx.

If it is just for you

Pound > Varnish > Nginx > PHP-FPM

This gives you SSL unwrapping from Pound, static and dynamic (ESI) caching from Varnish, un-cached static content from Nginx and dynamic content from PHP-FPM

If you've got no real experience with Varnish

Apache > PHP-FPM

The truth is that you can do a lot more damage than good with Varnish if you do not set it up properly (cached private sessions, unwanted cookie un-setting). The same applies to Nginx.

Have a read of this http://www.sonassi.com/knowledge-base/magento-kb/mythbusting/why-shouldnt-i-use-nginx-for-magento/

Oh and avoid tmpfs for anything, it doesn't increase performance.

Read these for a bit more information ...

  1. http://magebase.com/magento-tutorials/magento-session-storage-which-to-choose-and-why/comment-page-1/#comment-1986

My final advice, consult a professional - its money well spent.

Ben Lessani
  • 5,244
  • 17
  • 37
  • "Oh and avoid tmpfs for anything, it doesn't increase performance. " Are you sure? I can provide you with benchmarks, where Magento gains 250% more performance just putting the cache files in a tmpfs. But this is a bit older, Magento 1.3. Nowadays Magento tries to put the cache content always in memcached, if available. And tmpfs is of course not faster than memcached. – Martin Rothenberger Mar 18 '12 at 17:39
  • @MartinRothenberger I'm 100% sure. All we do as a business (sonassihosting.com) is benchmark different SW/HW configurations for hosting Magento. `tmpfs` adds nothing at all. – Ben Lessani Mar 19 '12 at 14:22