Overcome the bottleneck of CGI
1.1 headache efficiency problem
1.2 Some solutions
1.3 Better Method - Fastcgi
2. Install fastcgi
2.1 Installing a FASTCGI module on an Apac
2.1.1 Standard installation (using APACI)
2.1.2 Installing mod_fastcgi into a DSO
2.2 Add to use mod_fastcgi related settings
2.3 Installing a Fastcgi Development Kit
2.4 Test Fastcgi
2.5 Installing the FCGI Module for Perl
3. Write a FASTCGI app
3.1 Programming Architecture
3.2 Introduced FCGI_STDIO.H header
3.3 Fastcgi processing cycle
3.4 Refining Libfcgi.A Function Library
3.5 Write awareness of a FastCGI program
4. How fast is fastcgi?
4.1 Ratio Tool - Apachebench
4.2 CGI vs. Fastcgi
4.3 find Memory Leak
5. Reference
About this document ...
-------------------------------------------------- ----------------------------
Overcome the bottleneck of CGI
1.1 headache efficiency problem
Worship CGI, the website no longer has only fixed graphics and text, and the website can make the website seem to be "live" by program dynamically generated web pages. Small from simple web counter, message, large to deal with multiple data search engines, can do an e-commerce, online order, etc. of the online real-time transaction. CGI is simple, open, cross-platform, independent features with program language, making it easy to write a website application.
However, as the website uses, these CGI programs from the original dynamic web page, suddenly become the number one killer of the website efficiency. Since CGI innate restrictions 1, suddenly pouring a large number of online requests (Request), often causes the website host instant resources to be occupied, as if "a machine", or the processing speed becomes very slow.
Another common restriction is the problem with the database connection. If the CGI program rear end requires an online to the database execution instruction, suddenly a large number of online requests may exceed the database system to allow the upper limit of the online (eg database system user) limits).
Therefore, for a developer who is mainly used to make dynamic websites using the CGI program, the CGI execution efficiency bottleneck has become a headache. Taking a stock market real-time website as an example, a daily online request is concentrated in the spike of the stock market, and is a great test of the website application.
1.2 Some solutions
There have been many programs that have been proposed to solve the bottleneck in CGI execution efficiency, and there is also a simple description in the article "Accelerating your website with fastcgi". Here only, the author is trying to apply for website applications for the real-time quotation of stock markets. Some methods have made personal experiences and opinions. With the author's case, the original CGI program is written in C, and the following methods are mainly used by other C-letter libraries.
NSAPI
Since the original website is on the UNIX system, the website server uses the network view Enterprise Server, so the earliest thing I want to use NSAPI to override the website application. There is a very detailed NSAPI manual on the website of the website, unfortunately there is no Chinese manual. It is the most troublesome to use NSAPI to change the website app. The most troublesome you have to compile all programs into a dynamic library (Share Library) for Enterprise Server to dynamically call these programs during Run-Time. Since the program written by Nsapi is called directly from the Web Server's execution space, the speed is the fastest, but the program must follow Enterprise Server's writing rules, and once the program has an error, Web Server will also be affected. ISAPI
Compared to NSAPI, the Microsoft NT IIS (Internet Information Server) platform is ISAPI. Similar to NSAPI, using ISAPI writes a website application, you must compile the application into a dynamic library, that is, DLL file. Its execution speed is also very fast, but to follow the write rules and data structures of ISAPI, the program will also affect the normal operation of IIS Server when the program is incorrect.
Looking at the two Solutions mainly based on Web Server API (in fact Apache also have corresponding Server APIs, just use people may be less), their execution speed is very fast, generate dynamic web pages than cgi is fast Multiplier. But on the perspective of the program developer, they have some shortcomings:
1. NSAPI and ISAPI are too high in Platform Dependency, that is, after using NSAPI or ISAPI, the application is fully limited to the website server platform used, and cannot transform the website server used. Unlike the CGI completely unscrupulous, you can do it on any website server (Netscape, Microsoft IIS, Apache, NCSA). Also as ISAPI is more limited to use on the Windows NT platform.
2. NSAPI and ISAPI only provide interface interfaces, that is, developers must develop in C language. Unlike the program language used by developers, in addition to C, there are Perl, TCL, etc. in addition to C.
3. Netscape Enterprise Server and Microsoft IIS processes the NSAPI and ISAPI programs in Multi-Threads, all executions share the same variable space, so it is especially careful in the processing of variable data to ensure The security of variable data in performed kettlement does not affect each other.
4. NSAPI and ISAPI applications are called directly on the execution of the server (the program is affected) if the program is dropped, and the entire website server will be affected. CGI When the server will respond to the information of the Internal Server Error, the server itself is not affected.
5. NSAPI and ISAPI applications must be executed by server calls, and debug is quite not easy.
1.3 Better Method - Fastcgi
If you are suffering from CGI efficiency, you don't want to be limited to NSAPI and ISAPI, and there is no big silver to buy expensive Application Server. I suggest you try to look at Fastcgi.
Unlike NSAPI and ISAPI and other web server languages (such as ASP, PHP3, MOD_PERL), Fastcgi is more similar to CGI, which is just a sizes of a website application design, so it is not subject to any website server platform, operating system platform, and Development of language restrictions, but it can greatly improve the problem of poor CGI efficiency. Fastcgi features as follows: 1. Fastcgi is like a long-lived type CGI, which can always be executed, as long as activation, do not spend time every time (this is the most illness of CGI Fork-and-execute mode).
2. FastCGI can be used on any platform, Netscape Enterprise and IIS have a Fastcgi module available, Apache, and servers that use Apache derived by Apache, there are mod_fastcgi available.
3. Fastcgi supports C / C , Perl, TCL, Java, Python and other programming languages.
4. Fastcgi app is also compatible with CGI. That is, FASTCGI applications can also be performed as a CGI.
5. Existing CGI programs is very simple to rewrite into fastcgi, and minimally add three-line program code.
6. Fastcgi's method is similar to CGI, as long as the environment variables and parameters required to bring the program, you can execute or detect in the command column mode.
7. Fastcgi application is similar to CGI, in addition to several principles should pay special attention, fastcgi's writing method is almost the same as CGI, compared to learning Web Server API, fastcgi is simple.
8. Fastcgi DISTCGI DISTRIBUTING, that is, the FastCGI program can execute on a host other than the web server and accept requests from other website servers.
Whether it is easy to try after seeing Fastcgi. The next chapter will show how to install Fastcgi on the Apache server.
-------------------------------------------------- ----------------------------
2. Install fastcgi
To use FastCGi, you must have a environment that can be performed by the FastCGI program, as well as the development environment of writing a FastCGI program. The following is a Fastcgi execution platform as Apache Web Server, briefly describes how to use FastCGi in Apacci.
Due to the free, open, cross-platform features, many system or distribution kits are available in many APCE servers, if you use the pre-compiled Apaci program, please find it in line with it. The installation path of the system setting rule. The following list is listed below, and the following examples will be based on Apaci internal value, other systems please refer to:
System execution file path setting file path
Apacali-Detained / USR / local / apache / bin / usr / local / apache / etc
FreeBSD / USR / LOCAL / SBIN / USR / LOCAL / ETC / APACHE
Red Hat Linux / USR / SBIN / USR / ETC
2.1 Installing a FASTCGI module on an Apac
Install MOD_FASTCGI This module allows your Apac to support the FastCGI protocol. MOD_FASTCGI now is now version 2.2.2, this version is mainly used in Apache version 1.3. If your Apache is also 1.2, please use the mod_fastcgi version 2.0.18. The following settings are demonstrated in Apache 1.3.6 and Mod_FAST 2.2.2. 2.1.1 Standard installation (using APACI)
1. First download Apache_1.3.6.tar.gz and mod_fastcgi_2.2.2.tar.gz, unwind:
$ gunzip -c apache_1.3.6.tar.gz | tar xvf -
$ gunzip -c mod_fastcgi_2.2.2.tar.gz | tar xvf -
2. Copy the original code of mod_fastcg to Apache:
$ cp -rp mode_fastcgi_2.2.2 apache_1.3.6 / src / modules / fastcgi
3. Set Apache Add MOD_FASTCGI module:
$ cd apache_1.3.6
$ ./configure /
-activate-module = src / modules / fastcgi / libfastcgi.a /
-ENABLE-MODULE = INFO -ENABLE-Shared = INFO /
[more apaci options]
4. Compilation and installation
$ Make
$ make Install
5. Look at whether the compiled executive file contains the mod_fastcgi module:
$ / usr / local / apache / sbin / httpd -l
Compiled-in modules:
http_core.c
...
MOD_FASTCGI.C
...
2.1.2 Installing mod_fastcgi into a DSO
Suppose you have installed the Apache version 1.3 version on your system, and your platform supports DSO (Dynamic Shared Object) to dynamically join the module, then you can install mod_fastcgi into a DSO module via APXS (Apache Extension Tool).
1. Download MOD_FASTCGI_2.2.2.tar.gz and unwave:
$ gunzip -c mod_fastcgi_2.2.2.tar.gz | tar xvf -
2. Compile MOD_FASTCGI module into DSO:
$ CD MOD_FASTCGI_2.2.2
$ / usr / local / apache / sbin / apxs -o mod_fastcgi.so -c * .c
3. Installation
$ / usr / local / apache / sbin / apxs -i -a -n fastcgi mod_fastcgi.so
2.2 Add to use mod_fastcgi related settings
In order to distinguish the Apache to process some online requests belong to fastcgi, we must add the Apache's settings in the setting files of Apache.
1. The Mod_FastCGI module registers a FastCGI-Script processing type (Handler Type) to Apache, and we can set all the programs that are FCG and FPL (for perl) that are in line with the FastCGI protocol:
AddHandler Fastcgi-script .fcg .fpl
2. Next we define the / usr / local / www / fcgi-bin for this directory to store the already written Fastcgi program:
Scriptalias / fcgi-bin / / usr / local / www / fcgi-bin / 3. Check that the setting file is correct:
$ / usr / local / apache / sbin / apachectl configtest
Syntax OK
4. Re-activate the Apaci server, let the new settings take effect:
$ / usr / local / apache / sbin / apachectl graceful
/ usr / local / apache / bin / apachectl graceful: httpd gracefully restarted
The original httpd.conf, srm.conf, access.conf, and access.conf, after Apache 1.3.4. So if you are using the apache after the 1.3.4 version, please modify the httpd.conf3 file directly. If it is 1.3.3, I suggest that the mod_fastcgi module is added to the SRM.CONF. The actual setting file path and setting file file name may vary depending on each person's environment, please adjust according to your own environment.
2.3 Installing a Fastcgi Development Kit
1. Download fcgi-devkit-2.1.tar.gz and unwave:
$ gunzip -c fcgi-devkit-2.1.tar.gz | tar xvf -
2. Compile
$ CD FCGI-Devkit-2.1
$ ./configure
$ Make
3. Install the header file (library) to the system:
$ cp-rp include / usr / local / include / fastcgi
$ cPibfcgi / libfcgi.a / usr / local / lib
2.4 Test Fastcgi
With a simple Fastcgi sample program in the Fcgi-Devkit kit - Echo.c, we use it to do the test system to be installed correctly. Directly copy the echo.fcg that has been compiled into the preset placement Fastcgi program:
$ CD FcGi-Devkit-2.1 / Example
$ cp echo.fcg / usr / local / www / fcgi-bin
Now, use the browser to connect to http: //localhost/fcgi-bin/echo.fcg to see if you see the following results, you have told:
Fastcgiecho
RequestNumber1, ProcessID: 1013
NodatafromstandardInput.
RequestenVironment:
FCGI_Role = Responder
Document_root = / usr / local / apache / htdocs
HTTP_ACCEPT = TEXT / HTML, TEXT / Plain, Application / AppleFile, Application / X-Metamai
L-PATCH, Sun-Deskset-Message, Mail-file, default, postscript-file, audio-file,
X-Sun-attachment, Text / Enriched, Text / Richtext, Application / Andrew-INSET, X-BE2
, Application / PostScript, Message / External-Body, Message / Partial, Application / P
GP, Application / PGP, Video / MPEG, VIDEO / *, Image / *, AUDIO / *, AUDIO / MOD, TEXT / SGM
L, VIDEO / MPEG, Image / JPEG, Image / TIFF, Image / X-RGB, Image / PNG, Image / X-Xbitmap,
Image / x-xbm, image / gif, application / postscript, * / *; q = 0.01 http_accept_encoding = Gzip, Compress
HTTP_ACCEPT_LANGUAGE = EN
Http_host = localhost
Http_negotiate = trans
HTTP_USER_AGENT = Lynx / 2.8.1pre.9libwww-fm / 2.14
Path = / usr / local / bin: / bot: / usr / bin: / usr / x11r6 / bin: / usr / sbin: / OPT / KDE / BIN: / HOME / M
YHSU / bin: / usr / x11r6 / bin: / usr / sbin: / usr / x11r6 / bin: / usr / sbin: / opt / kd
E / BIN
REMOTE_ADDR = 127.0.0.1
REMOTE_PORT = 1024
Script_filename = / usr / local / www / fcgi-bin / echo.fcg
Server_admin=myhsu@localhost.localdomain
Server_name = localhost.localdomain
Server_port = 80
Server_signature =
Apache / 1.3.6serveratlocalhost.localdomainport80
Server_software = apache / 1.3.6 (unix) mod_fastcgi / 2.2.2
Unique_id = n1ptln8aaeaaapddrkgateway_interface = cgi / 1.1
Server_Protocol = http / 1.0Request_method = getQuery_String =
REQUEST_URI = / fcgi-bin / echo.fcgscript_name = / fcgi-bin / echo.fcg
InitialeNVironment:
Note that two variables of the request number and process ID displayed in the above program. When we continue to reload this program, the Request Number will always be accumulated and the value of the Process ID will not change. This means that this procedure has been performed after the first activation, and the variable space referred to in each online request is the same (so Request Number will continue to add).
To this end, we have successfully established a website executive platform for the development of the FastCGi application and execute the FastCGi application.
2.5 Installing the FCGI Module for Perl
If you want to use Perl to write FastCGi's programs, you must install the FCGI.pm module, the installation method is as follows:
1. Download fcgi-0.45.tar.gz and unwinder
$ Gunzip -c fcgi-0.45.tar.gz | TAR XVF -
2. Compilation and installation
$ perl makefile.pl
$ Make
$ make Install
3. Test
$ CP ECHO.FPL / USR / local / www / fcgi-bin
$ lynx http://localhost/fcgi-bin/echo.fpl
If you are going well, you should see the following results:
Fastcgi echo (perl)
REQUEST NUMBER 1
No Data from Standard INPUT.
Request environment:
Document_root = / usr / local / apache / htdocs
FCGI_Role = Responder
Gateway_Interface = CGI / 1.1HTTP_ACCEPT = TEXT / HTML, TEXT / Plain, Application / AppleFile, Application / X-Metamai
L-PATCH, Sun-Deskset-Message, Mail-file, default, postscript-file, audio-file,
X-Sun-attachment, Text / Enriched, Text / Richtext, Application / Andrew-INSET, X-BE2
, Application / PostScript, Message / External-Body, Message / Partial, Application / P
GP, Application / PGP, Video / MPEG, VIDEO / *, Image / *, AUDIO / *, AUDIO / MOD, TEXT / SGM
L, VIDEO / MPEG, Image / JPEG, Image / TIFF, Image / X-RGB, Image / PNG, Image / X-Xbitmap,
Image / x-xbm, image / gif, application / postscript, * / *; q=0.01
HTTP_ACCEPT_ENCODING = Gzip, Compress
HTTP_ACCEPT_LANGUAGE = EN
Http_host = localhost
Http_negotiate = trans
HTTP_USER_AGENT = Lynx / 2.8.1pre.9 Libwww-fm / 2.14
Path = / usr / local / bin: / bot: / usr / bin: / usr / x11r6 / bin: / usr / sbin: / OPT / KDE / BIN: / HOME / M
YHSU / bin: / usr / x11r6 / bin: / usr / sbin: / usr / x11r6 / bin: / usr / sbin: / opt / kd
E / BIN
Query_string =
REMOTE_ADDR = 127.0.0.1
REMOTE_PORT = 1427
Request_method = Get
REQUEST_URI = / fcgi-bin / echo.fpl
Script_filename = / usr / local / www / fcgi-bin / echo.fpl
Script_name = / fcgi-bin / echo.fpl
Server_admin=myhsu@localhost.localdomain
Server_name = localhost.localdomain
Server_port = 80
Server_Protocol = HTTP / 1.0
Server_signature =
Apache / 1.3.6 Server At Localhost.localdomain Port 80
Server_software = apache / 1.3.6 (unix) mod_fastcgi / 2.2.2
UNIQUE_ID = N1VIBX8AAAAAAAAQNKKO
More on Its Way ... Wait a Few Seconds
Initial environment:
Similarly, if you continue to connect http: //localhost/fcgi-bin/echo.fpl, it can be seen that the Request Number is increasing, indicating that echo.fpl has been activated and continuously executed.
At this point, a website server for executing a Fastcgi program and the development environment of writing a Fastcgi program have been completed, and then only wait for the new program to put it up.
-------------------------------------------------- -------------------------- 3. Write a FastCGi app
Writing a new FastCGI app, or rewrite the old CGI program into a FastCGI application is very simple, just use the FCGi_stdio library attached to FcGi-Devkit.
Basically, the FCGI_STDIO library has been designed to make developers write FastCGI applications just like writing a general CGI program, while doing programs and CGI's largest compatibility, and enjoy the advantages brought by FastCGi. Another benefit of using the FCGI_STDIO library is that the compiled executive can be performed simultaneously in CGI and Fastcgi.
3.1 Programming Architecture
For the CGI program, its lifetime is starting from a online request to the end of the online. The Fastcgi program is like a CGI program that is more than "longer", and its life is different online requests, and can start from the web server to the web server to stop.
Due to the characteristics of the FastCGI program, it and the main difference between the general CGI program are to distinguish the partialization of the initialization and the part of the online request. The architecture of the program is as follows:
Initialization Code
START of Response Loop
Body of Response loop
End of response loop
The part of the Initialization Code will only be executed once when the FastCGI program is activated, and the segment of the program initialized is like memory configuration, the connection and database online, etc. can be written here.
The program between the START OF RESPONSE LOOP to End Of RESPONSE LOOP will execute each time a online request, this program is really handling things to do every online request. For example, accept the parameters entered by the user, take out data from the database, execute the calculation action, and the result is given to the user.
A simple Fastcgi program is as follows (tiny-fcgi.c)
#include "fcgi_stdio.h"
#include
Void main (void)
{
/ * Initialization Code * /
INT count = 0;
/ * START of Response loop * /
While (fcgi_accept ()> = 0) {
/ * Body of response loop * /
Printf ("Content-Type: Text / HTML / R / N"
"/ r / n"
""
"
Fastcgi Hello! (C, fcgi_stdio library) "
"Request Number% D Running on Host
% s "
"Process ID:% D / N",
count, GetENV ("Server_name"), getPid ());
}
/ * End of response loop * /
}
3.2 Introduced FCGI_STDIO.H header
When you start writing a new FastCGi application, you must introduce the header file of fcgi_stdio.h:
#include `` fcgi_stdio.h ''
If you want to rewrite the old CGI program into a fastcgi program, please replace some parts that have been introduced to stdio.h:
#ifndef fastcgi
# include # else
#include `` fcgi_stdio.h ''
#ENDIF
The above way is to use C's pre-compiler to process, if the parameters of -dfastcgi are added at compile time, the FCGi_stdio.h is introduced, and no. Suppose we put the fcgi_stdio.h header file in the / usr / local / incrude / fastcgi directory, in order to introduce FcGi_stdio.h headers when compiling, join -i / usr / local / include / fastcgi parameters .
$ cc -i / usr / local / incrude / fastcgi -c program.c
note
If your program uses other libraries, be sure to check if these libraries are used to use stdio.h, if any, must be changed to FCGi_stdio.h. For example, if your program uses the GD library 4 to generate GIF graphics, remember to introduce some of the STDIO.H in GD.H to fcgi_stdio.h, otherwise it will happen when the IO is encountered. Error (CORE DUMP).
3.3 Fastcgi processing cycle
In the FastCGI program, the program is responsible for handling the online request, and must be packed with a while, using the FCGI_ACCEPT () library in the FCGI_STDIO library to determine if there is a new online request.
After the Fastcgi program is activated, the initialization action, such as variable declaration, memory configuration, or connect with the database. The program will be paused when executing to fcgi_accept (), etc. When an online request occurs, fcgi_accept () will return a value greater than zero, and the program immediately enters the main body of the loop, which may be the execution of SQL instructions, operations, and generate HTML output . After processing, go back to the beginning of the FCGI_ACCEPT () loop, and wait for the next online request.
It can be seen that after the FastCGI is activated, the steps of the original CGI program are omitted in the original CGI program, and the time required for each online request is almost equal to the time required for the FCGI_ACCEPT (). If you use the program code when the online request is properly extracted from the fcgi_accept (), only some of the different results are generated each time, the program handles the time of the online request, the efficiency of the entire website is also It can greatly improve.
After understanding the basic architecture of the FastCGI program, you can discover a general CGI program, just get a Fastcgi program as long as you join the FCGI_Accept () while loop.
3.4 Refining Libfcgi.A Function Library
The Fastcgi program should be used to refine to the libfcgi.a library to correctly generate the execution file, assume that the location of libfcgi.a is in / usr / local / lib directory, we are compiling (time-finishing) to join -L / parameters of USR / local / lib -lfcgi.
$ cc -o program.fcg program.o -l / usr / local / lib -lfcgi
3.5 Write awareness of a FastCGI program
Since the FastCGI program is resident in memory after being activated, the Running Process for each FastCGI is the same, and the number of variables that is requested to share is the same, and some choice of FastCGI programs should pay special attention to some. Precautions.
1. Remember, for each FastCGI program, only the program in the FCGI_ACCEPT () loop is the main body that is really handling each online request, assuming that the environment variable related to the CGI is read in the program, or the user The information entered through the form (FORM) must be processed within the FCGI_ACCEPT () loop. 2. For each online request, the variables will be changed, don't forget to initialize the variable before processing the new online request (unless there is special purpose) to avoid the mutual impact of variables between different online requests.
3. Configuration in the FCGI_ACCEPT () loop forgets the release (free). In a general CGI program, Memory Leak is not too big, because each of the online requests are processed, all used memory is also released with the end of the CGI program. However, the FastCGI program will always stay in memory. If there is an additional memory in FCGI_ACCEPT (), there is no release before the end of the loop, then eat some system memory every time the online request is taken, run more. The system resources are probably consumed. The problem of Memory Leak is the most common mistake of FastCGi, and it is particularly careful.
4. FastCGI program and the subroutine they want to reference to the STDIO.H function, remember to change to FCGI_STDIO.H. Otherwise, the case where the program will happen when the action is encountered by IO.
5. Use the fcgi_finish () in the FCGI_ACCEPT () cycle to replace the exit (). When an error occurs in the original CGI program, you may call the exit () in the exit () in the CGI stroke, and the FastCGI program can also be used because the mod_fastcgi module is an unexpected end of the FastCGI program, which is automatically activated to activate another FastCGI stroke. However, a better practice is to call FcGi_finish () in fcgi_stdio.h, and call the fcgi_finish () in the FCGI_Finish (), will jump out the current program is in the calculation of the loop, and return to FCGI_ACCEPT () Wait a next online request. This can save some website servers to activate the burden on the new FastCGi trip.
-------------------------------------------------- ----------------------------
4. How fast is fastcgi?
After watching the Apaci module installed in Fastcgi, and after the boring program design, let's take a look at some data that can be exciting, and the Bench Mark is always the favorite icon_smile.gif of the computer player.
4.1 Ratio Tool - Apachebench
Among the Apache servers, there is a tool called AB (Apachebench). Apachebench is mainly used to test the Apache server execution efficiency, and we use apachebench as CGI VS. Fastcgi's evaluation tool.
ApacheBench can simulate a continuous online request for a particular URL, and can also simulate the same online request, so use ApacheBench to help us simulate the like or on the line during website development, using the simulation Data is based on the basis for adjusting the server settings or programs. The usage of Apachebench is as follows:
Usage: / usr / local / apache / bin / ab [options] [http://] hostname [: port] / path
Options are:
-n Requests Number of Requests to Perform
-c Concurrency Number of Multiple Requests To Make-T Timelimit Seconds To Max. Wait for Responses
-p Postfile File Containg Data To Post
-T Content-Type Content-Type Header for Posting
-V Verbosity How much trouplanooting info to print
-w Print Out Results in HTML Tables
-x Attributes String to Insert As Table Attributes, INSERT ASTRIBUTES
-y attributes string to insert as tr attributes
-z attributes string to insert as td or th Attributes
-V print version Number and exit
-k Use http keypalive feature
-h Display usage information (this message)
Suppose we have to test the ECHO.FCG, simulate the online request of 1000 times, and there are 20 parallel CONCURRENT online requests, as long as the command is executed
$ AB-N 1000 -C 20 http://localhost/fcgi-bin/echo.fcg
A little time, apachebench will show the results.
This is apachebench, version 1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-1999 The apache group, http://www.apache.org/
Benchmarking Localhost (Be Patient) ... Server Software: Apache / 1.3.6
Server Hostname: Localhost
Server Port: 80
Document path: /fcgi-bin/echo.fcg
Document Length: 995 Bytes
Concurrency Level: 20
Time Taken for Tests: 6.859 Seconds
Complete Requests: 1000
Failed Requests: 0
Total Transferred: 1142000 BYTES
Html Transferred: 995000 BYTES
Requests per second: 145.79
Transfer Rate: 166.50 kb / s received
CONNNECTION TIMES (MS)
MIN AVG MAX
CNECT: 0 4 61
Processing: 62 128 771
Total: 62 132 832
The above results pointed out that in the case of a concurrency level, complete a 1000-time online request, a total of 6.859 seconds, so this program can be processed per second (Requests Per Second) 145.79 online requests.
In the next evaluation test, we use the number of online requests that can be processed by each second to be based on the basis for efficiency.
4.2 CGI vs. Fastcgi
The FastCGI program compiled with the fcgi_stdio.h library is also compatible with the CGI mode, so we only need to copy the FCGI-Devkit-2.1 kit to the / cgi-bin directory, and put the file The name is changed to ECHO.CGI, which can be performed in CGI mode and FASTCGI mode, respectively, and compare. First, Http: //localhost/cgi-bin/echp: //localhost/cgi-bin/echp: //localhost/fcgi-bin/echp: //localhost/fcgi-bin/echo.fcg, executed, respectively, 10, 100, 1000, 10,000 online requests , The result of the average-processed request per second is:
Online number 10 100 1000 10000
CGI 52.63 53.08 52.24 51.49
Fastcgi (Static Mode) 204.08 224.22 146.78 207.14
Next, the tests per second result is: the Requests Per Second result is:
CONCURRENCY Number 10 100 1000 10000
10 CGI 38.31 46.55 53.61 55.09
10 Fastcgi 185.19 208.33 162.63 177.14
50 CGI 27.25 33.16 50.72 53.99
50 Fastcgi 92.59 176.37 196.58 196.88
100 CGI 17.92 24.84 48.14 52.84
100 Fastcgi 86.21 187.27 195.54 193.17
From the above data, it is performed using FASTCGI mode for the same branch (echo.c), and the speed is increased by 3-4 times. It can be seen that Fastcgi has considerable benefits on the performance improvement of the website program, especially when the usage is large, and its benefits are more obvious.
The above test conditions are not very rigorous, mainly for you to understand the use of Fastcgi for a summary comparison of the performance and speed, also provides a basis for website developers.
In fact, the initialization action is complex, for example, to establish an online connection, or configure memory, and make variable initialization, using FastCGI can add more than the original CGI, faster. For a system with a number of databases that can be connected to a database, use fastcgi as an Application Server. Don't worry about the CGI once, exceeding the number of online users (Fastcgi can set a few runs).
4.3 find Memory Leak
To make good use of Apachebench tools, you can also help the website program developers find Memory Leak bugs hidden in the fastcgi program.
Each FastCGI program should be the same after processing a online request. We use Apachebench to send out hundreds or thousands of online requests to simulate the situation of the line, if the memory occupied by the program The more and more and not reduced, indicating that the program has a problem with Memory Leak.
Although the FastCGI program is concerned, when it constantly eats system resources to the data, it will automatically exit (Core Dump or exit), release the resource occupied and reactivate, but this will affect the system of other functions. Working properly, so you must be very careful.
-------------------------------------------------- -------------------------- 5. Reference
If you want to learn more about fastcgi, you can find all relevant information on the home page of FastCGi, including FastCGi development specifications, software download, description file, etc. Fastcgi Home's URL is http://www.fastcgi.com/
Fastcgi also has a mail discussion area (Mailing List), you can send email to
Fastcgi-developers-Request@idle.com
Fill in Subscribe at the main point of the email. But before you ask, please see the documentation or installation file, or you can find the problem in the file discussion area (Mail Archive) to find a question, and someone has answered, so as not to waste repetitive network resources. . If you find a mod_fastcgi module or an error or serious problem of FCGi-Devkit development suite, Fastcgi's development team will help you find a way to solve.
Fastcgi has many different usage, as well as special applications, you want you to go to explore. I hope this article can help friends using Fastcgi to install FastCGi-related modules and programs smoothly, allowing your website to advance.
Excerpt from: http://linuxfab.cx