Re: Caching (was Re: choosing the right platform) - Mailing list pgsql-performance

From David McKain
Subject Re: Caching (was Re: choosing the right platform)
Date
Msg-id 20030410103435.B16757@ph.ed.ac.uk
Whole thread Raw
In response to Caching (was Re: choosing the right platform)  ("Matthew Nuzum" <cobalt@bearfruit.org>)
Responses Re: Caching (was Re: choosing the right platform)
List pgsql-performance
On Wed, Apr 09, 2003 at 09:16:36PM -0400, Matthew Nuzum wrote:
> Thanks for all the feedback, this is very informative.
>
> Here are some of the performance suggestions I've heard, please, if I
> mis-understood, could you help me get clarity?
> * It's better to run fewer apache children and turn off persistent
> connections (I had suggested 200 children per server, someone else suggested
> 40)

Hi Matthew,

I'm coming in a bit late and slightly OT here, but one common Apache
solution you might want to look at is a "reverse proxy" configuration.
This works very well if there's a good proportion of static vs dynamic
content on your site - if your pages contain a lot of graphics then this
may well be the case.

To do this, you compile 2 Apache servers listening on different ports on
the same machine (or you can have them on different machines too).

Server 1 (we'll call the "front server") is just a vanilla Apache
listening on Port 80, compiled with mod_rewrite and mod_proxy but
nothing else.

Server 2 ("back server" or "heavy server") has mod_php and anything else
you need which is quite bulky (e.g. XML processing stuff, mod_perl ...)
It can listen on Port 8080 or something. Your persistent DB connections
come from Server 2.

All web requests come in to Server 1 in the normal way and Server 1
deals with static content as before. By setting up Apache rewrite rules
on Server 1, requests for *.php and other dynamic stuff can be forwarded
to Server 2 for processing. Server 2 returns its response back through
Server 1 and the end-user is oblivious to what's going on. (Server 2
and/or your firewall can be configured to allow connections only from
Server 1 too.)

It's a bit of effort to set up and does require a wee bit more
maintenance than a single server but it comes with a few nice
advantages:

* You can have a lower MaxClients setting on server 2 and hence less
  persistent DB connections and less memory used by heavy Apache modules
  and PostgreSQL instances.

* Server 1 is nice and light - no DB, low memory use (much of which is
  probably shared) - so you can set its MaxClients much higher.

* The overall impact of each dynamic page is lower as all of the
  images and stylesheets it references can be quickly dealt with by
  Server 1, rather than wasting an unnecessary wodge of memory and
  persistent DB connection.

I used this recently for transforming XML web pages into HTML using XSLT
and mod_perl on a slightly old and underpowered Solaris server and it
worked really well. Of course, YMMV!

There are lots of tutorials on setting this up on the web - the mod_perl
guide has some very handy stuff in it which ought to apply reasonably
well to PHP too:

http://perl.apache.org/docs/1.0/guide/scenario.html

Hope that might help,
David.


pgsql-performance by date:

Previous
From: Ron Johnson
Date:
Subject: Re: Caching (was Re: choosing the right platform)
Next
From: Shridhar Daithankar
Date:
Subject: Re: Caching (was Re: choosing the right platform)