Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Hi it seems that my servers couldn't handle the traffic during peak hours and Apache seems to just crash.

Here's some info on the server:

  • Xeon 5110 @ 1.6ghz
  • 4Gb Ram

  • Windows 2003 Server

  • Apache 2.2.11 for Windows
  • mod_fcgid (from apachelounge.com)
  • PHP 5.2 with eAccelerator installed
  • It's also running MySQL 5.0

It's also running PHP apps like Mediawiki, Joomla, Wordpress and Drupal and we're getting about 18k daily hits.

Here are some important configs from httpd.conf:

# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15

##
## Server-Pool Size Regulation (MPM specific)
## 

# WinNT MPM
# ThreadsPerChild: constant number of worker threads in the server process
# MaxRequestsPerChild: maximum  number of requests a server process serves MaxClients 125
#<ifModule mpm_common>
#MaxClients 140
#</IfModule>

<IfModule mpm_winnt.c>
ThreadsPerChild 250
MaxRequestsPerChild  0
</IfModule>
### END

Here are the configs for eAccelerator from php.ini:

[eAccelerator]
extension="eaccelerator.dll"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="C:\Temp\eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
accelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.keys = "shm"
eaccelerator.sessions = "shm"
eaccelerator.content = "shm"
eaccelerator.debug="0"

I know that it's very wrong to run Apache on a Windows machine but I have to bear with this for the time being (not my call unfortunately).

Is there something wrong with my configs? Is there a solution so that the servers can handle the load? Any help would be appreciated. Thanks in advance!

share|improve this question
    
Can you be more specific ? Crash means that the application stopped running and exited with an error code. Do you mean that from the clients perspective, apache stopped processing requests at a rate that was sufficient to meet demand ? –  Dave Cheney Jun 23 '09 at 1:47
    
Windows displays a program crashed dialog. Sometimes it stops all the processing requests sometimes it runs normally as if it it didn't crash(still showing the program crashed dialog box) –  alimango Jun 23 '09 at 3:01

5 Answers 5

up vote 2 down vote accepted

Apache isn't your problem; it'll handle large loads without any tweaking. It's your apps (and probably your database). Not much you can do about poor code in pre-packaged PHP applications, but it's rare that much work goes into the database tuning and schemas. I'd be looking there first and foremost (log and optimise slow queries, tune database memory usage for workload and available memory, etc).

share|improve this answer
    
I checked the processes and there's a tens of php-cgi.exe's eating up the memory and cpu. Is it mostly the database or my apache/php configs that's the culprit? –  alimango Jun 23 '09 at 1:30
1  
If the php-cgi processes are actively using all the CPU, then it's the PHP code (not the config) that's doing the damage. –  womble Jun 23 '09 at 2:00
    
true, but that doesn't mean that you should attempt to tune the code --- especially if it's third-party code like a web framework or CMS. Often, tuning apache, caching the responses at http level, adding mysql caching etc. are better solutions. –  Lee B Jan 17 '10 at 11:59
    
If your third party CMS is that crap, the chances are that it won't respond particularly well to HTTP caching, and caching MySQL responses or tuning Apache won't work WHEN THE PHP-CGI PROCESSES ARE USING ALL THE CPU. –  womble Jan 17 '10 at 18:25

Under windows you best bet is to use IIS and fastCGI. This allows you to recycle the CGI process and not have gobs of them running. This is what might be killing performance. The IIS team has a guide to installing fastCGI

share|improve this answer
    
Is there a way for Apache to make the CGI proccesses recyclable? –  alimango Jun 23 '09 at 2:08
    
FastCGI is already being used. –  womble Jun 23 '09 at 2:49
    
I'm not an apache expert but probably not. The fastcgi ISAPI filter was designed with zends help to originally eliminiate this problem with PHP under windows. I'm pretty sure the fastCGI I've referenced isn't being used (unless microsoft bought apache when I wsan't looking) –  Jim B Jun 23 '09 at 3:13
    
Certainly, if using IIS, FastCGI is the best option for performance with PHP, but I wouldn't assume that IIS is the best server at all. It's probably better tuned for windows, but there are many factors that make apache a better choice for PHP users, including htaccess support, community support, common use of the stack, etc. –  Lee B Jan 17 '10 at 11:57
    
I think without a doubt IIS is the best server for running PHP applications compared with just about any other web server platform. Performance vs same hardware running redhat linux with apache is almost doubled in some cases. HTaccess is an idea that's been baked into windows for a while now (however unlinke apache IIS doesn't say NOT to use htaccess whenever possible- see the latest htacccess utorial on the apache website fore reference). The php community is the same php community whether it's windows or linux. I'm not sure what you mean by common use of the stack? –  Jim B Jan 17 '10 at 16:42

For Windows, why don't you take a packaged tool like WAMP?

WampServer 2.0h [04/16/09]
Includes : Apache 2.2.11, MySQL 5.1.33, PHP 5.2.9-2

You can change the versions and run multiple instances of any of these too.
Though, I have not tried that myself.

Besides, there is also a Portable edition.


This could be your stop-gap solution while you get around a Unix setup.

share|improve this answer

You really need to find out which part of the system is the bottleneck here. Try splitting the services off onto different pieces of hardware, or at least insert some profiling into the apps that are slow.

At a random guess though, check your database is using indexes correctly - enable slow query logging, and see how many slow queries you're getting. It generally shouldn't be too many; too many slow queries can cause Apache to stall while waiting for the PHP processes to finish.

share|improve this answer

Tune the maximum number of fastcgi processes in apache. Sounds like it's using too much memory (max processes * php memory limit), and dying as it swaps endlessly. Don't confuse the number of apache processes/threads with the number of fastcgi/php processes.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.