Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Ask Slashdot: Optimizing Apache/MySQL for a Production Environment

Posted by Cliff on Sun Aug 29, 1999 08:30 AM
from the tweak-it-till-it-bleeds dept.
treilly asks: "In the coming weeks, the startup company I work for will be rolling out a couple of Linux boxes as production webservers running Apache and MySQL. Management was quick to realize the benefits of Linux, but I was recently asked: "Now that we're rolling out these servers, how do we optimize out of the box RedHat 6.0 machines as high performance web and database servers in a hosting environment"?
This discussion has been archived. No new comments can be posted.
Display Options Threshold:
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
(1) | 2
  • Optimisation of Apache/db by Anonymous Coward (Score:1) Sunday August 29 1999, @03:42AM
  • Watch mysqld's nice level. by Anonymous Coward (Score:1) Sunday August 29 1999, @04:54AM
  • A favor please. by Anonymous Coward (Score:1) Sunday August 29 1999, @04:59AM
  • Performace tuning by Anonymous Coward (Score:1) Sunday August 29 1999, @06:26AM
  • by Anonymous Coward on Sunday August 29 1999, @04:32AM (#1718673)
    At the Apache.org web site there is a guide to optimize Apache's performance.

    Also Dan Kegel wrote an interesting web page in response to the whole Mindcraft NT/IIS vs. Apache/Linux fiasco and on that page are several detailed measures to improve Apache's performance under Linux:

    Dan Kegel's Mindcraft Redux page [kegel.com]
    Apache Week 'zine [apacheweek.com]

    ...as for my own personal experience w/ Apache I learned that when compile Apache, remove any Apache modules you won't be needing saves plenty of RAM, and in the httpd.conf file you want to set StartServers, MaxClients, and MaxRequestsPerChild so that Apache does not spawn new children too often -- the trick is before you start Apache look at "top" count the number of processes, now start Apache under normal traffic conditions, look at number of processes you're running now to see how many http children are running -- whatever that number is add 10, and that should be your StartServers setting. The MaxRequestsPerChild default is 30 but I like to crank it up to 300 or more so that http children are not being killed and recreated too often (the reason for that setting was to avoid possible memory leaks from sucking up all your RAM which hasn't been a problem with the httpd's I've worked with)

  • by Anonymous Coward on Sunday August 29 1999, @03:51AM (#1718674)
    Basically, I just winged it. My site started out with maybe ten thousand hits per day, but quickly (over the course of two years) ramped up to about 5 million hits a day. I just hacked together some Perl scripts, and when I need to make changes, I just try 'em out on the production server. Who needs beta testing? If there are performance problems, I just buy faster hardware. If there are stability problems, people are understanding, after all, I *am* using Linux.

    Sincerely,

    Rob Malda
  • Re:General purpose advice by Tom Rothamel (Score:2) Sunday August 29 1999, @05:22AM
  • Re:MySQL vs PostgreSQL by Ranger Rick (Score:2) Sunday August 29 1999, @03:27PM
  • fhttpd by Alex Belits (Score:1) Sunday August 29 1999, @05:49AM
  • Clarification of LIKE vs. == by rodent (Score:2) Sunday August 29 1999, @11:03AM
  • by rodent (550) on Sunday August 29 1999, @05:03AM (#1718679)
    Personally, I designed and currently admin a site that gets about 1 mil hits/day. Over a weeks time it averages about 50 queries/second with peaks at 500 queries/sec. The setup is dual p2/400's with 512 megs ECC (soon to be a gig) and the db's on a lvd scsi drive. The db's run a total of 2 gigs. There's typically 50 apache processes running at a time.

    As for optimization, definately check your queries and always use keyed fields and == queries. Doing like queries will kill your performance to being unusable on decently large tables (>100k records). Definately read the MySQL docs concerning RAM usage and the various switches to optimize it's RAM usage. That is extremely important.

    As for Apache, don't use .htaccess at all costs and only compile in required modules. Also check the tuning FAQ mentioned above.

  • Idiot of the year award by Eric Green (Score:2) Sunday August 29 1999, @07:22AM
  • Re:Optimizations by Rasmus (Score:1) Sunday August 29 1999, @06:31PM
  • Perfomance tuning and Availability by tuttle (Score:1) Sunday August 29 1999, @06:56AM
  • You could start it out as a module by Mike Greaves (Score:1) Sunday August 29 1999, @03:43PM
  • Re:Software RAID? by tzanger (Score:1) Tuesday August 31 1999, @03:18AM
  • Re:Einstein of the year award by jd (Score:1) Sunday August 29 1999, @05:54AM
  • Tuning webservers (Score:3)

    by jd (1658) <imipak@ya[ ].com ['hoo' in gap]> on Sunday August 29 1999, @05:18AM (#1718686) Homepage Journal
    Here's my quick list of things I do, when tuning the webservers I've set up in the past. Note: I offer NO guarantees to the usefulness of this information. For all I know, it'll turn your pet hamster into a frog.

    0) If you have LOTS of RAM, compile Apache, MySQL and optionally Squid with EGCS+PGCC at -O6. The extra speed helps.

    1) Guesstimate the number of simultaneous connections I'm likely to have.

    2) Guesstimate how much of the data is going to be dynamic, and how much static.

    3) IF (static > dynamic) THEN install Squid and configure it as an accelerator on the same machine. Give most of the memory over to Squid, and configure a minimal number of httpd servers. You'll only need them for accesses of new data, or data that's expired from the cache.

    4) IF (static 5) If you've plenty of spare memory, after all of this, compile the kernel with EGCS+PGCC at -O6, but check it's reliability. It's not really designed for such heavy optimisation, but if it works ok, the speed will come in handy.

    NOTE: Ramping up the compiler optimiser flag to -O6 does improve performance, but it also costs memory. If you've the RAM to spare, it is sometimes worth it.

  • Re:Here's how I handle several million hits per da by dclatfel (Score:1) Sunday August 29 1999, @04:33AM
  • To all you bitter schmucks with nothing else to do by dclatfel (Score:2) Sunday August 29 1999, @05:14PM
  • Re:Performance tips for Apache... by Oestergaard (Score:1) Sunday August 29 1999, @06:39AM
  • Re:Software RAID? by Oestergaard (Score:1) Sunday August 29 1999, @08:32AM
  • Re:Idiot of the year award by drewpt (Score:1) Sunday August 29 1999, @07:27AM
  • Production environment by ajv (Score:1) Sunday August 29 1999, @07:08PM
  • Re:RAM & RAID 1+0 is your friend. by tcjordan (Score:1) Wednesday September 01 1999, @05:48AM
  • Re:All the money in the world by tcjordan (Score:1) Wednesday September 01 1999, @10:25AM
  • Re:3 words... by tcjordan (Score:1) Thursday September 02 1999, @01:39PM
  • Re:Software RAID? by James Manning (Score:1) Sunday August 29 1999, @08:33AM
  • Re:Depending on if your site is read-only or not by James Manning (Score:1) Sunday August 29 1999, @08:40AM
  • Re:RAM & RAID 1+0 is your friend. by James Manning (Score:1) Sunday August 29 1999, @09:41AM
  • Re:RAID! by James Manning (Score:2) Sunday August 29 1999, @05:01AM
  • All the money in the world by Sixty4Bit (Score:1) Sunday August 29 1999, @10:07AM
  • a couple ideas (Score:3)

    by felix (7014) on Sunday August 29 1999, @05:54AM (#1718701) Homepage Journal
    So some of the best things you can do have already been mentioned - split out your database from your front end webservers, let the backend have it's own machine and run raid 0+1 on the db server. The frontends won't need the raid since they'll be serving a lot of the static stuff out of cache.

    Some other ideas, are to split image serving onto it's own apache, not necessarily it's own box. This apache can be completely pared down to absolute minimum modules, since all it will be doing is serving up static images. It also let's cache be used efficiently, since mostly the common images will be stored. As opposed to common images contending with common text files for cache space if images and content are served from the same apache.

    Also, what are you using in apache to create dynamic pages and connect to the db? Use long running processes where possible, which means pick mod_perl, php, fastCGI, servlets, etc... over plain cgi scripts. This will save you lots of cycles and also let you have persistent db connections. Always a very good thing.

    Taking the splitting out of machines to the next level, you could also try splitting all of your dynamic content to it's own machine, mod_proxied through your front end apache's. This makes the front ends very small since they barely need any modules installed at all. It also gets some extra performance out of your dynamic content apaches. Of course you're running a lot of boxes now. :)

    Read this [apache.org] if you're running mod_perl. And read this [mysql.org] to optimize your db.

  • Linux and Databases by doomy (Score:2) Sunday August 29 1999, @06:26AM
  • Re:RAM & RAID 1+0 is your friend. by gampid (Score:2) Sunday August 29 1999, @08:35AM
  • Re:mulitprocessor hardware? by kuro5hin (Score:1) Sunday August 29 1999, @10:06AM
  • Re:MySQL, ?? by kuro5hin (Score:2) Sunday August 29 1999, @10:18AM
  • Logo is, Cobol is, JavaScript is - HTML is NOT by rod (Score:1) Sunday August 29 1999, @06:35PM
  • HTML is N O T a programming language by rod (Score:1) Sunday August 29 1999, @06:44PM
  • Re:Flamebait? by orabidoo (Score:2) Monday August 30 1999, @05:18AM
  • Does it have to be Apache? by Rozzin (Score:1) Sunday August 29 1999, @06:08AM
  • MySQL, ?? by warmi (Score:1) Sunday August 29 1999, @07:48AM
  • Re:Performance tips for Apache... by fdicostanzo (Score:2) Sunday August 29 1999, @05:33AM
  • General purpose advice by sammy baby (Score:1) Sunday August 29 1999, @04:09AM
  • Re:General purpose advice by sammy baby (Score:1) Sunday August 29 1999, @06:20AM
  • Re:Major Performance Boost by kinkie (Score:1) Sunday August 29 1999, @06:55AM
  • mSQL vs. mySQL by grossdog (Score:1) Sunday August 29 1999, @04:06PM
  • Re:Idiot of the year award by GnuGrendel (Score:1) Sunday August 29 1999, @12:09PM
  • by wintahmoot (17043) on Sunday August 29 1999, @05:39AM (#1718718) Homepage
    I haven't read all of the previous comment, so it may well be that this has been posted before.

    Okay, this is how I generally do it. First of all, I suppose that you're using Perl, so these tips are for a Perl/Apache/MySql environment.

    1) Use mod_perl so that your script doesn't neet a whole perl compiler for each separate instance in memory. The performance boost is just incredible...

    2) Use Apache::DBI. It will prevent your script from connecting and disconnecting your DB each time it's called and rather use a persistent database connection. Great for performance.

    There are some other tweaks that you can do. If you're interested, just let me know [mailto]...

    Wintermute
  • by rde (17364) on Sunday August 29 1999, @03:34AM (#1718719)
    There are ready-made solutions out there such as E-smith [e-smith.net]; you can download a cd image (or even buy the cd), and it'll install the system with extras built in; it's designed to be an 'out-of-the-box' sorta thing.
  • Oh wow!! Rob actually posted! by Corndog (Score:1) Sunday August 29 1999, @03:07PM
  • Does Squid need 2 be on the same server as Apache? by cpeterso (Score:1) Monday August 30 1999, @11:58AM
  • Why Raid 5 and MySQL? by cpeterso (Score:1) Monday August 30 1999, @12:07PM
  • A separate server for the database? by RyanGWU82 (Score:1) Sunday August 29 1999, @06:48AM
  • Re:3 words... by platinum (Score:1) Sunday August 29 1999, @01:44PM
  • Re:Optimizations by platinum (Score:1) Sunday August 29 1999, @04:56PM
  • Re:Optimizations by platinum (Score:1) Sunday August 29 1999, @05:00PM
  • Re:What's that? by platinum (Score:1) Sunday August 29 1999, @05:15PM
  • Re:Optimizations by platinum (Score:1) Sunday August 29 1999, @07:27PM
  • Optimizations (Score:4)

    by platinum (20276) on Sunday August 29 1999, @06:33AM (#1718729) Homepage
    First of all: IMO, if you have to ask how to optimize your company's equipment in a forum such as this, you need some real help (perhaps of the mental variety). There are a plethora of web sites on optimizing systems. OTOH, I might as well share our experiences.

    Our company uses Apache, MySQL, and PHP extensively (and exclusively). You can't beat the price/performance ($0.00 / excellent == great value). Thorough our research, we settled with the following combination:
    • Web Server: FreeBSD 3.2-STABLE with Apache 1.3.9 / PHP 3.0.9 on a PII-400 w/128 Meg RAM, IBM 4.55G U2W Drive. Due to FreeBSD's proven track record for Web/Network performance, stability, and security (e.g. Yahoo [yahoo.com], wcarchive [cdrom.com], and others), it's a natural.
    • SQL Server: Linux 2.2.x with MySQL 3.22.25 on a PII-400 w/256 Meg RAM, IBM 4.55G U2W System Drive and a Mylex AcceleRAID 250 w/4 IBM 4.55G U2W Drives in a RAID-5 configuration. Linux was the obvious choice when considering MySQL performance and driver availability wrt RAID controllers.
    Optimization suggestions:
    • Apache: Ensure you have adequate spare servers to handle the connections (StartServers, MaxSpareServers, MaxClients, and MaxRequestsPerClient in the config); nothing sucks more than clients not being able to connect. Also, if you are using embedded script of some sort (PHP, Perl, etc.), use modules compiled into Apache (mod_perl, etc.); this should significantly increase speed and decrease the overhead of reloading the module for each access.
    • MySQL: Tweak the applicable setting as appropriate. We increased (usually doubled in most cases) the following: Join Buffer, Key Buffer, Max Connections, Max Join Size, Max Sort Length, Sort Buffer, and Sort Buffer). If possible, depending on the amount of data, get as much memory in the system as possible. If the OS can maintain frequently used data cached, disk access won't be required which significantly increases the speed of queries, etc. In addition, get rid of that pre-compiled MySQL and compile it yourself. If possible, optimize using egcs/pgcc for your platform. Also, compile mysqld statically; this will increase it's memory overhead a bit but can increase it's speed by 5 - 10% by not using shared libraries.
    • Storage: For optimum speed, use SCSI (of course). For our data, we require RAID 5 for redundancy. If that is not required, RAID 0 (striping) can be used for increased speed. The optimal way is to use hardware RAID (external RAID or RAID controller). Luckily, Linux has drivers for quite a few different RAID controllers that are available for a reasonable price.
    • Linux: Beware of Redhat's security problems, disable all unnecessary services, et. al. Seek out security-oriented and Linux performance-tuning sites for more suggestions.
    • General: Don't skimp on hardware. A cheap component, be it a drive, network card, motherboard, or whatever, if it fails, will cause unrecoverable downtime. We decided on Intel NL440BX boards (serial console/BIOS support is nice), PII-400's, and IBM SCSI drives in both boxes. If one box were to have a catastrophic failure, the other is able to perform both webserver and SQL server functions if necessary. We can also simply replace a failed component with one pulled from a similarly-configured non-production (test) box, or just swap boxes altogether.
    Both Apache [apache.org] and MySQL [mysql.com] have good sections on performance tuning. Do not be afraid to RTFM.

    Any questions/comments can be directed to me. Flames directed to /dev/null.
  • Re:Optimisation of Apache/db by angelo (Score:1) Monday August 30 1999, @03:46AM
  • Re:Optimisation of Apache/db by Cowards Anonymous (Score:1) Sunday August 29 1999, @07:13AM
  • RAID! by amon (Score:1) Sunday August 29 1999, @04:18AM
  • Re:RAID! by Sxooter (Score:1) Sunday August 29 1999, @06:11PM
  • Re:You could start it out as a module by fornix (Score:1) Sunday August 29 1999, @05:05PM
  • Testing, testing, testing by ingenthr (Score:1) Sunday August 29 1999, @05:00AM
  • Re:Flamebait? by yomahz (Score:1) Sunday August 29 1999, @09:41AM
  • Re:Optimizations by catenos (Score:1) Sunday August 29 1999, @04:43PM
  • Performance tips for Apache... by mgreenwood (Score:2) Sunday August 29 1999, @03:52AM
  • Re:All the money in the world by coyote-san (Score:2) Sunday August 29 1999, @12:56PM
  • MySQL vs PostgreSQL by Hotboxer (Score:1) Sunday August 29 1999, @02:29PM
  • Re:Flamebait? by pdstrnad (Score:1) Saturday September 04 1999, @02:31AM
  • Re:Tuning webservers by asianflu (Score:1) Sunday August 29 1999, @05:12PM
  • Well, here's what I know (for what it's worth) by jguthrie (Score:2) Sunday August 29 1999, @04:39AM
  • Re:Einstein of the year award by mochaone (Score:1) Sunday August 29 1999, @06:02AM
  • Re:3 words... by PrinceOfChaos (Score:1) Sunday August 29 1999, @12:58PM
  • Performance with Servlets by pbryant (Score:1) Sunday August 29 1999, @10:53AM
  • Don't Be Cynical, it's very plausable. by guiGuy (Score:1) Sunday August 29 1999, @03:29PM
  • Re:Tuning webservers by Joe Schmo (Score:1) Sunday August 29 1999, @08:28AM
  • HTML as a programming language by The Moniker (Score:1) Sunday August 29 1999, @11:01PM
  • Re:Diff. boxes... by nissimK (Score:1) Sunday August 29 1999, @07:21AM
  • Hotmail working on Solaris by tai (Score:1) Saturday September 04 1999, @04:39AM
  • what about Eddie? by nanner (Score:1) Sunday August 29 1999, @06:24AM
  • 60 replies beneath your current threshold.
(1) | 2