Skip to end of metadata
Go to start of metadata

When tuning Apache, remember to take into account the amount of RAM your SmartMachine contains, and the typical amount of RAM that all the processes on your SmartMachine consume.

The following table shows typical directives in /opt/local/etc/httpd/includes/mpm.conf for different sized SmartMachines to reduce the amount of RAM used on multiple requests:

Apache Directive 1/4GiB 1GiB 2GiB 4GiB
StartServers 2 8 16 32
MinSpareServers 1 4 8 16
MaxSpareServers 2 8 16 32
ServerLimit 8 64 128 256
MaxClients 8 64 128 256
MaxRequestsPerChild 0 0 0 0
ListenBacklog 1000 1000 1000 1000

If your site serves up a lot of static content, you may want to serve up that content from a separate light weight server such as Nginx or Lighttpd.

Always setup your databases on a separate SmartMachine. You can then setup the databases to connect to your Apache web servers through a private IP. 

When running PHP with Apache you would want to enable an opcode cache so that PHP opcodes are not recompiled on each page request.

View current Apache status

Apache is configured with a web based system status module that is very useful in getting the current status of your web server.

To enable mod_status you must SSH into your SmartMachine and become root:

1) Add these lines to the top of your Apache config file for the virtual server you want to monitor:


2) In the same config file add this location in the Virtual server after your cgi-bin declarations:


You should only enable this when you are troubleshooting your server as this makes your status available to all IP's.

You can limit who is allowed to view the status page by un-commenting the Deny rules and adding hosts to the Allow rule

3) Restart your Apache server:


4) To view status from a web browser:


To have the page refresh ever 5 seconds:


To view from the command line:

 
You can also use get a machine readable version of this page fro scripts by calling:
 

Apache Configuration for Maximum Open Files

Older versions of PHP have a known file descriptor bug. This has been fixed in Joyent's PHP 5.3.5 package.

Error on running out of file descriptors are recorded in your Apache error log. This normally is an issue with customer applications.

You can view what files are being used by Apache with the command:

How to check what you have set presently (as root or sudo)

Check to see if a project entry exists in /etc/project for httpd (as root or sudo)

If it does not exist (the command returns no result), then use projadd command to include an entry for apache

Number of Connections

By default Apache comes with 1024 possible open files for each worker. This translates into 1024 ports which means your total maximum connections.

To increase the port limit: 

  1. Run these commands:
  2. Then to make it reboot ready, run this command:
  3. Change the SMF start/exec property to run under the "httpd" project:
  4. Restart Apache:

Use Static IP in conf files

You will reduce memory usage of Apache clients by binding the Server and VirtualHosts to a specific IP. Another way of saying this is not to use wildcard IP's ( * ):

You will have to update your conf files if you change IP's on your SmartMachine.

You can do this by modifying the following files:

And change the existing entries to have the Apache server listen on the specific IP:

Uses less memory:

Uses more memory:

Also update your Virtualhost entries in:

Uses less memory:

Uses more memory:

Disabling mod_passenger

If you are not using Phusion Passenger (for Ruby on Rails apps), you can safely comment out the lines to load the dso under /opt/local/etc/httpd/includes/dso.conf:

and /opt/local/etc/httpd/httpd.conf that loads the module:

Helper Services

There are many services that you can run to assist you in debugging and increasing the performance of your web application:

Install your free version of New Relic

Install New Relic on your SmartMachine - it is free if you have a 1G or larger system and it provides so much information that we in Support can better assist you. Really, with the graphs and monitoring that they have allow you to quickly tell if it is code or database causing you issues.

http://newrelic.com/about/partners/joyent

Go there, set up your free account and install the client on your SmartMachines.

Enable caching

For PHP the Apache plugin APC can greatly reduce your apps load time by caching objects.

For database queries enabling MemCache can speed up database calls with caching.

Use a lightweight web server instead

Apache is great. However, it's full features may be more than what you need.  You can dramatically increase performance of your SmartMachine and reduce your memory foot print by using a lightweight web server.

For example, here is an external article on how to setup and configure Ngnix on a Joyent SmartMachine: http://ecarmi.org/writing/setup-nginx-joyent-solaris-smartmachine/

External Apache Tuning articles

http://emergent.urbanpug.com/?p=60

At a Glance

This page shows you some values you can use to tune Apache to use less RAM.

For more information, see Apache 2.2 Performance Tuning Guide

Labels:
tuning tuning Delete
maxclients maxclients Delete
files files Delete
max max Delete
ram ram Delete
memory memory Delete
apache apache Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Feb 24, 2011

    Anonymous

    The svccfg command gives 'Syntax error.'

    I think the correct command is:

    svccfg -s http:apache setprop start/project = astring: httpd

    1. Mar 03, 2011

      Thanks. Looks like the problem was that the string needed to be escaped. Updated now.

      1. Jan 09, 2012

        Anonymous

        I appreciate you tiakng to time to contribute That's very helpful.

      2. Mar 15, 2012

        Anonymous

        Why do you think I'm wrong? Just because it has lfaied on your system doesn't make me wrong. I test things carefully before putting them on my website or in my books, and I have been running PHP 5.2.0 with Apache 2.2.3 successfully for several months.I have no idea what you have done wrong, but suggest that you start again and use the . Before using it, you need to clean up your system by uninstalling Apache and removing the conf folder before reinstalling. Also remove PHP from the Windows path, and make sure that you don't have a copy of php.ini in the WINDOWS folder.

      3. Jun 08, 2012

        Anonymous

        If you read my original actirle and reply carefully, you will see that I always refer to the Windows version of PHP 5.2.0. php-5.2.0.tar.bz2 contains the uncompiled PHP source code. If you are installing PHP on Windows, you need to download the Windows binaries for PHP 5.2.0. There are two versions: a zip file, and the Windows installer. Instructions for using the zip file are in my books. Instructions for using the Windows installer are in .

  2. Mar 05, 2012

    Anonymous

    On my SmartMachine svc is called apache, not http:apache.  So the correct syntax is:

    svccfg -s apache setprop start/exec=astring: \"newtask -p httpd /opt/local/sbin/httpd -k start\"