Monday, October 18, 2010

Rooted in the free soil-FastCGI


Linux as a representative of free software, to bring the IT industry, infinite space for development. Linux, transparency, both to the developer or the application of staff have a full room, in order to Linux operating systems and platforms, more features are being constantly developed. Like Server Push, FastCGI, EPERL, PHP3, and many new features, such freedom is in the soil of Linux to the full development.
The performance of a website, mainly in the following areas: system response time, processing time, user waiting time and system output load, considering the economic factors but also with technology costs. To improve the performance of the site, without changing the hardware and network architecture based on the technical content of the concentrate so good procedure. At present, Server Push (push technology) and FastCGI two new technologies do not increase in the cost basis can make your site the best performance. This article details FastCGI technology.

What is FastCGI

To show that if you want to use FastCGI, you should Linux-operating system services build FastCGI Apache module, you can go to www.fastcgi.com to download the latest module, download the module will be compiled detailed description .

Over the years, CGI has become a server-side application development, the de facto standard, although the emergence of ASP technology to enable server-side application development easier, but ASP still limitations to the current Unix / Linux as the operating system and use Apache to serve The server refused to process the vast majority of its door, CGI is still singing the server-side application development in the main event. Over time, many of the server under the heavy burden of CGI is now insufficient.

Let us see how the CGI work in it: when the client requests the server CGI application, a process server to handle user requests, after the end of the process. When the load is very low, CGI can work well, but the site of a large variety of different types of requests occur at any time, in the client request load is high, the server process setup and initialization time used a web site performance bottlenecks. In particular, such as application and database connection, initialize longer used.

When the FastCGI technical stand out often, this problem has been well resolved. FastCGI is active at a request from the server to provide services. FastCGI is a server running a "campaign of procedures" to handle server requests the application program's. FastCGI is always active, this is of benefit, it does not start in dealing with requests O'clock Xin Jin Cheng, and on the initial application of overhead. server-side can use PERL, C, C + + or JAVA and other languages to write one based FastCGI application to constantly deal with server application request. particularly for Server Push this connection, the server Otherwise intermittent response to user requests, we must continue to allow the server application is running to support the application request.

The advantages of FastCGI


We know, CGI can not be used as cache memory, because it run once for each request an application, and quit after the completion of the task. The FastCGI can be effectively used as cache memory to greatly improve its performance to process the request. Separate FastCGI applications and CGI than, perhaps not a good use of cache, and once FastCGI is designed to be multi-threaded, it can handle multiple requests to run concurrent application process, so that the process of multiple threads can share memory and access the same cache.

Another major advantage of FastCGI is that it can use a distributed network system to complete large-scale systems integration. A website to complete the user's interaction requirements, at least with e-mail, BBS and chat rooms these three functions, taking into account data security and database capacity and other factors, very few sites have all the data on the same host on. We all know that, because the process of environmental reasons, the server can call the machine CGI application, which hosts the distributed system to bring more limitations. The FastCGI applications do not get the CGI environment from a process variable, but in the FastCGI application and the server to create a "full duplex" connection, transmission of environmental information, STDIN, STDOUT and STDERR. So that we can place the FastCGI application in another host, using TCP / IP protocol and the main server remote connections. In the main server FastCGI application can request the same as the local machine to respond. The advantages are:

1. Can expand the size of network system

2. Can reduce the load on the same server

3. More servers can share the same FastCGI application.

How to write FastCGI applications

Let us first look at how the running FastCGI:

As you can see, like, FastCGI in dealing with a request to continue to run, so that the new request comes immediately to process the request. So FastCGI programs typically include the initialization code and packaging process of the main section of the response cycle, of course, after initialization, the main program loop to run continuously waiting for the arrival of the request. Only in the FastCGI application is withdrawn when the cycle until the end of the system.

Another advantage of FastCGI is shifted from the CGI FastCGI is simple, let's look at a traditional CGI:

Example 1: NUMBER.CGI

#! / Usr / bin / perl

# Variables

my $ End = 10;

my $ i;

# Content Header

print "Content-type: text / html; CHARSET = gb2312n";

# Main loop

for ($ i = 0; $ i <$ End; $ i + +)

(Print "$ i
;)

exit 0;

The CGI in the browser page on each line from 1 to 10 of a digital display.

Let us look at how to use FastCGI to write this program:

Example 2: NUMBER.FCGI

#! / Usr / bin / perl

# In order to use FastCGI package, need to add the following statement:

Use FCGI;

# Initialize the initialization section of the same section and CGI.

# Variables

my $ End = 10;

my $ i;

while (FCGIaccpet ()> = 0) (

# Content Header

print "Content-Type: multipart / x-mixed-replace; boundary = BOUNDARYnn";

# Because each request must have the appropriate Content-Type header in response, so we put it as a response to the main loop code.

# Main loop

for ($ i = 0; $ i <$ End; $ i + +)

(Print "$ i
;)

)

exit 0;

Because FastCGI and server applications, like running, so only the end of the signal received when the FastCGI only exit, otherwise it has been run.

Although the shift from the CGI FastCGI is very easy, but in practical examples of we have to note, if the original could cause the CGI program in the main code does not loop running code, you must modify it, that is Some variables, re-initialize the array. FastCGI application must ensure that in dealing with any request, any existing state can impact on subsequent requests. In addition, the programmers writing CGI programs, the modular design allows the main program running on those who do not frequently use the function modules relative "independence", and only when needed to be transferred to run, so you can speed up the main program operation. but turned FastCGI application process to be considered as a paragraph in the completion of related functions, in order to reduce the process to run when the number generated, and procedures between the various functional blocks can fully shared cache.






Recommended links:



For You Games Sports



AVI to MPEG4



Storage Search Or Lookup Tools



can you do a reverse unlisted phone number search



Ten Controversial figure in 2007



MPEG TO 3GP



"Nobunaga's Ambition 13 Heaven," the enemy in depth and around point reinforcements, waste Chaim



Baidu Xing, Tencent death?



Enjoys a bandwidth 10M 20M 20M exclusive exclusive special PRICE



Why Not Read The Disk Drive?



Approach New And Successful



XviD To MP4



How to promote sales will not die



IDS RULES to establish (1)



Manufacturing integration trend manufacturing And EMS has Approaching



No comments:

Post a Comment