[afnog] Scalable, Performance-Critical Web Application Architecture

Begumisa Gerald M beg_g at eahd.or.ug
Thu Sep 2 12:15:57 EAT 2004


Hi,

I have a quick question on the above subject: Supposing one wants to write
a scalable and performance critical web application and does not mind
using C (or C++) for this, what "style" / architecture would be best?
Below are a few proposed diagrams / architecture: (I'll also appreciate if
anyone would provide a few URLs - I've done quite some searching already).


A Single CGI program:
  =-=-=-=-=-=-=-=-=-=

+----------+  IP  +--------------+  ENV +--------------+ IP  +-------+
|          |----->|              |----->|              |---->|       |
| Browsers |  IP  | Apache HTTPd |  ENV | CGI in C/C++ | IP  | MySQL |
|          |<-----|              |<-----|              |<----|       |
+----------+      +--------------+      +--------------+     +-------+


	Key:
	===

	IP  = Internet Protocol (UDP/TCP)
	ENV = CGI Environment created by Apache to pass POST/GET etc...

In the above case, all the application functionality is in the CGI
program.  Each time there's a submission / request, this program is called
to serve the request and exits each time afterwards (possible overhead of
setting up and tearing down connections to the database, in addition to
initializing and cleaning up).


B Small, single CGI program + daemon:
  -=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=

+----------+ IP   +--------------+  ENV +--------------+
|          |----->|              |----->|              |
| Browsers | IP   | Apache HTTPd |  ENV | CGI in C/C++ |
|          |<-----|              |<-----|              |
+----------+      +--------------+      +--------------+
                                         ^            |
                                         |            |
                                         |UN/IP       |UN/IP
                                         |            |
                                         |            V
					+--------------+
					|              |
					|    Daemon    |
					|              |
					+--------------+
					  ^    ^    ^
                                          |    |    |
					  |TH  |TH  |TH
                                          |    |    |
					  V    V    V
					+--------------+
                                        |              |
                                        |    MySQL     |
					+--------------+

	Key:
	===

	IP 	- Internet Protocol (UDP/TCP)
	ENV 	- CGI Environment created by Apache to pass POST/GET etc...
	UP/IP 	- Either of a UNIX domain or TCP/IP Socket
	TH	- Thread maintaining a persistent connection to database

In this case, all the CGI program does is pass the necessary variables
(from POST or GET or other) to the already running daemon and waits for a
reply (which is probably a handle to an open html file to be returned to
the browser).  The daemon by default starts N threads (where N is
configurable) and thus opens N default connections to the MySQL database.

As load increases, more threads are created with a configurable timeout
value for which they will hang around the system or else they die.

If TCP/IP sockets are used instead of UNIX domain sockets, this means we
can have the daemon running on different machines.


C Many CGI Programs to do specific tasks
  =-==-=-==-=-=-=-=-=-==-==-=-=-=-=-=-==

This is pretty much the same as A except we have different programs to do
just one (or more things), not just one program that decides what is
needed and does it.


Personal opinion: B seems to be a better approach but I'd be really happy
to hear pros / cons or even completely different suggestions of
architecture or even programming language.


Cheers!
Gerald


More information about the afnog mailing list