views:

659

answers:

3

There's alot of information out there on setting up LAMP stacks on a single box, or perhaps moving MySQL onto it's own box, but growing beyond that doesn't seem to be very well documented.

My current web environment is having capacity issues, and so I'm looking for best-practices regarding configuration tuning, determining bottlenecks, security, etc.

I presently host around 400 sites, with a fair need for redundany and security, and so I've grown beyond the single-box solution - but am not at the level of a full ISP or dedicated web-hosting company.

Can anyone point me in the direction of some good expertise on setting up a great apache web-farm with a view to security and future expansion?

My web environment consists of 2 redundant MySQL servers, 2 redundant web-content servers, 2 load balancing front-end apache servers that mount the content via nfs and share apache config and sessions directories between them, and a single "developer's" server which also mounts the web-content via nfs, and contains all the developer accounts.

I'm pretty happy with alot of this setup, but it seems to be choking on the load prematurely.

Thanks!!

--UPDATE--

Turns out the "choking on the load" is related to mod_log_sql, which I use to send my apache logs to a mysql database. By re-configuring the webservers to write their sql statements to a disk file, and then creating a separate process to submit those to the database it allows the webservers to free up their threads much quicker, and handle a much greater load.

+2  A: 

The schoolbook way of doing it would be to identify the bottlenecks with real empirical data.

Is it the database, apache, network, cpu, memory,io? Do you need more ram, sharding(+), is the DiskIO, the NFS network load, cpu for doing full table scans?

When you find out where the problem is you might run into the problem that its not enough to scale the infrastructure, because of the way the code works, and you end up with the need to either just create more instances of you current setup or make the code different.

svrist
More links: http://www.slideshare.net/Jakobo/scaling-lamp-stacks/
svrist
http://www.scribd.com/doc/272292/How-Digg-com-uses-the-LAMP-stack-to-scale-upward
svrist
+2  A: 

You need to be able to identify bottlenecks and test improvements.

To identify bottlenecks, you need to use your system's reporting tools. Some examples:

  • MySQL has a slow query log.
  • Linux provides stats like load average, iostat, vmstat, netstat, etc.
  • Apache has the access log and the server-status page.
  • Programming languages have profilers, like Pear Benchmark.

Use these tools to identifyy the slowest/biggest offenders and concentrate on them. Try an improvement and measure to see if it actually improves performance.

This becomes a never ending loop for two reasons: there's always something in a complex system that can be faster and as your system grows, different functions will start slowing down.

Based on the description of your system, my first hunch would be disk io and network io on the NFS servers, then I'd look at MySQL query times. I'd also check the performance of the shared sessions.

Gary Richardson
A: 

I would also recommend as a first step in terms of scalability, off-load your content to a CDN like Edgecast. Use your current two content servers as additional web servers.

Gary