[Turn]nginx+fastcgi+c/c++ to build a high-performance web framework

Source: Internet
Author: User
Tags server port

from:http://blog.csdn.net/marising/article/details/3932938

1.nginx1.1. Installation
    1. Nginx wiki http://wiki.codemongers.com/NginxChs download nginx 0.6.26 (Download the latest version)
    2. Tar zxvf nginx-0.6.26.tar.gz
    3. ./configure, note similar to the checking for * * * ... not found item, may be dependent package not, you need to install a dependent package
    4. Missing Pcre,sudo apt-get install Pcre installation. Or go: http://www.pcre.org/
    5. If Openssl,sudo apt-get install Libssl-dev is missing, or go to: http://www.openssl.org
    6. If zlib is missing, you can apt-get install ZLIB1G, or http://www.zlib.net/
    7. Configuration please referto: Http://wiki.codemongers.com/NginxChsInstall can choose to install the module
    8. Make & make Install
    9. Installed by default under/usr/local/nginx
1.2. Management
  1. Execution Options
    -C </path/to/config> Specify a configuration file for Nginx instead of the default.
    -T does not run, but only tests the configuration file. Nginx will check the correctness of the configuration file syntax and try to open the file referenced in the configuration file.
    -V Displays the version of Nginx.
    -V Displays the Nginx version, compiler version, and configuration parameters.
  2. Check the configuration file
    $ sudo nginx-t2008/03/12 19:15:11 info 12384#0:the configuration file/usr/local/nginx/conf/nginx.conf syntax is ok2008/ 03/12 19:15:11 Info 12384#0:the configuration file/usr/local/nginx/conf/nginx.conf was tested successfully
  3. Start
    /usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf
  4. View Nginx Main process number
    "Nginx:master Process"
    "Grep"
    | Awk-f ' {print $}
    26010
  5. Reload the configuration file
    $sudo Kill-hup 26010

    Through the system's signal control Nginx
    You can use the signaling systems to control the main process. By default, Nginx writes the PID of its main process to the/usr/local/nginx/logs/nginx.pid file. Change the location of the file by passing parameters to the./configure or by using the PID directive. The
    main process can handle the following signals:

    command description remarks
    term, INT quick close  
    quit gracefully close &N BSP;
    hup overloaded configuration start new with new configuration Work process     gracefully close old worker process
    USR1 Reopen day Log file &NBSP;
    USR2 Smooth upgrade executable program &NBSP;
    winch Calmly close the worker process &NBSP;
  6. Default directory
    Home directory:/usr/local/nginx/
    Configuration directory:/usr/local/nginx/conf/
    Root directory:/usr/local/nginx/html/
    Executable file path:/usr/local/nginx/sbin/
2.fastcgi2.1. Installing the LIGHTTPD spawn-fastcgi

Download http://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz

./configure    make    CP./src/spawn-fcgi/usr/local/nginx/sbin/
2.2. Installing the FASTCGI Library

Download http://www.fastcgi.com/dist/fcgi.tar.gz

./configure make make    install
2.3.Hello World
 #include <iostream> #include <fcgi_stdio.h> 
using namespace std;
int Main () {
/* 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 */return 0;


}

Post-compilation for Fastcgisameple

2.4. Start spawn-cgi
/usr/local/nginx/sbin/spawn-fcgi-a 127.0.0.1-p 9000-c 25-u www-f/usr/local/nginx/fcgi/factcgisample
2.5. Modify Nginx configuration file

Vi/usr/local/nginx/conf/nginx.conf

Location ~/.cgi$



Fastcgi_index index.cgi;
Fastcgi_param Script_filename/scripts$fastcgi_script_name;
Include Fastcgi_params;
}

Don't forget to reload the configuration file

$sudo Kill-hup 26010

Open the browser and enter http://localhost/1.cgi to display

Process

id:25473
3.webbench Pressure test Tool

Download:http://home.tiscali.cz:8080/~cz210552/distfiles/webbench-1.5.tar.gz

Installation:

Tar zxvf webbench-1.5.tar.gzcd webbench-1.5


Make && make install

Use:

Webbench-c 500-t http://127.0.0.1/test.jpg

500 is the number of concurrent connections, 30 is the time unit is the second

With the results of the AB test, on my virtual machine, it looks like a good performance.

(Apache Bench is a toolkit that comes with Apache)

Ab-n 10000-c http://127.0.0.1/1.cgi
This is apachebench, Version 2.3 < $Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus technology LTD, http://www.zeustech.net/
Licensed to the Apache software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (Be patient)
Completed requests
Completed requests
Completed requests
Completed 4000 requests
Completed requests
Completed 6000 requests
Completed 7000 Requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server software:nginx/0.7.38
Server hostname:127.0.0.1
Server port:80

Document Path:/1.cgi
Document length:143 bytes

Concurrency level:100
Time taken for tests:3.982 seconds
Complete requests:10000
Failed requests:8399
(connect:0, receive:0, length:8399, exceptions:0)
Write errors:0
Total transferred:2658399 bytes
HTML transferred:1438399 bytes
Requests per second:2511.06 [#/sec] (mean)
Time per request:39.824 [MS] (mean)
Time per request:0.398 [MS] (mean, across all concurrent requests)
Transfer rate:651.89 [Kbytes/sec] Received

Connection Times (MS)
Min MEAN[+/-SD] Median max
Connect:0 1 4.6 0 51
PROCESSING:22 39 6.8 36 93
Waiting:4 39 6.8 36 93
Total:24 39 8.2 36 97

Percentage of the requests served within a certain time (MS)
50% 36
66% 39
75% 41
80% 42
90% 48
95% 54
98% 70
99% 84
100% (Longest request)

4.Nginx Module

Module List
Http://wiki.codemongers.com/NginxModules

FASTCGI Module Source: nginx/src/http/modules/ngx_http_fastcgi_module.c

[Turn]nginx+fastcgi+c/c++ to build a high-performance web framework

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.