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

1.Nginx

1.1.安装

  1. Nginx 的中文维基 http://wiki.codemongers.com/NginxChs 下载 Nginx 0.6.26(开发版)(请下载最新版本)
  2. tar zxvf nginx-0.6.26.tar.gz
  3. ./configure,注意了类似checking for *** ... not found项,可能是依赖包没有,则需要安装依赖包
  4. 缺少PCRE,sudo apt-get install pcre安装。或者去:http://www.pcre.org/
  5. 如果缺少OpenSSL,sudo apt-get install libssl-dev,或者去:http://www.openssl.org
  6. 如果缺少zlib,可以apt-get install zlib1g,或者http://www.zlib.net/
  7. 配置请参考:http://wiki.codemongers.com/NginxChsInstall 可以选择安装模块
  8. make & make install
  9. 默认安装在/usr/local/nginx下

1.2.管理

  1. 执行选项
    -c </path/to/config> 为 Nginx 指定一个配置文件,来代替缺省的。
    -t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
    -v 显示 nginx 的版本。
    -V 显示 nginx 的版本,编译器版本和配置参数。
  2. 检查配置文件
    $ sudo nginx -t
    2008/03/12 19:15:11 info 12384#0: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    2008/03/12 19:15:11 info 12384#0: the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
  3. 启动
    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  4. 查看nginx主进程号
    $ ps -ef | grep "nginx: master process"
    | grep -v "grep"

    | awk -F ' ' '{print $2}

    26010
  5. 重新加载配置文件
    $sudo kill -HUP 26010

    通过系统的信号控制 Nginx
    可以使用信号系统来控制主进程。默认,nginx 将其主进程的 pid 写入到 /usr/local/nginx/logs/nginx.pid 文件中。通过传递参数给 ./configure 或使用 pid 指令,来改变该文件的位置。
    主进程可以处理以下的信号:

    命令 说明 备注
    TERM, INT 快速关闭  
    QUIT 从容关闭  
    HUP 重载配置 用新的配置开始新的工作进程    从容关闭旧的工作进程
    USR1 重新打开日志文件  
    USR2 平滑升级可执行程序  
    WINCH 从容关闭工作进程  
  6. 默认目录
    主目录:/usr/local/nginx/
    配置目录:/usr/local/nginx/conf/
    root目录:/usr/local/nginx/html/
    可执行文件路径:/usr/local/nginx/sbin/

2.FastCGI

2.1.安装lighttpd的spawn-fastcgi

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

./configure
make
cp ./src/spawn-fcgi /usr/local/nginx/sbin/

2.2.安装fastcgi库

下载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; }

编译后为FastCGISameple

2.4.启动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.修改Nginx配置文件

vi /usr/local/nginx/conf/nginx.conf

location ~ /.cgi$

{    
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
      include fastcgi_params;
}

别忘了,重新加载配置文件

$sudo kill -HUP 26010

打开浏览器,输入http://localhost/1.cgi ,就显示

FastCGI Hello! (C, fcgi_stdio library)Request number 1 running on host localhost Process

 ID: 25473

3.webbench压力测试工具

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

安装:

tar zxvf webbench-1.5.tar.gz
cd webbench-1.5 make && make install

使用:

webbench -c 500 -t 30 http://127.0.0.1/test.jpg

500是并发连接数,30是时间单位是秒

用ab测试的结果,在我的虚拟机上,看起来性能很不错

(Apache Bench是Apache自带的工具包)

ab -n 10000 -c 100 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 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 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%     97 (longest request)

4.Nginx模块

模块列表
http://wiki.codemongers.com/NginxModules

FastCGI模块源码:nginx/src/http/modules/ngx_http_fastcgi_module.c

[转]nginx+fastcgi+c/c++搭建高性能Web框架的更多相关文章

  1. Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布

       FastCGI编程包括四部分:初始化编码.接收请求循环.响应内容.响应结束循环. FCGX_Request request; FCGX_Init(); ); FCGX_InitRequest(& ...

  2. 【入门篇】Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布

    http://blog.csdn.net/allenlinrui/article/details/19419721 1.介绍     Nginx - 高性能web server,这个不用多说了,大家都 ...

  3. Nginx + FastCGI 程序(C/C++)搭建高性能web service的demo

    http://blog.csdn.net/chdhust/article/details/42645313 Nginx + FastCGI 程序(C/C++)搭建高性能web service的Demo ...

  4. 分享关于搭建高性能WEB服务器的一篇文章

    这篇文章主要介绍了Centos5.4+Nginx-0.8.50+UWSGI-0.9.6.2+Django-1.2.3搭建高性能WEB服务器的相关资料,需要的朋友可以参考下(http://m.0813s ...

  5. 尹吉峰:使用 OpenResty 搭建高性能 Web 应用

    2019 年 8 月 31 日,OpenResty 社区联合又拍云,举办 OpenResty × Open Talk 全国巡回沙龙·成都站,原贝壳找房基础架构部工程师尹吉峰在活动上做了<使用 O ...

  6. Netty高性能web框架

    框架背景: 前期为公司项目做全链路压测,发现公司跑到tomcat上的服务,即使是最简单的方法QPS也就到3000左右,后期查询发现可能和tomcat的业务逻辑有关. 因为以前在项目开发中用netty做 ...

  7. 彩虹女神跃长空,Go语言进阶之Go语言高性能Web框架Iris项目实战-项目入口与路由EP01

    书接上回,我们已经安装好Iris框架,并且构建好了Iris项目,同时配置了fresh自动监控项目的实时编译,万事俱备,只欠东风,彩虹女神蓄势待发.现在我们来看看Iris的基础功能,如何编写项目入口文件 ...

  8. python 高性能web框架 gunicorn+gevent

    参考链接: http://rfyiamcool.blog.51cto.com/1030776/1276364/ http://www.cnblogs.com/nanrou/p/7026789.html ...

  9. 用Python手把手教你搭建一个web框架-flask微框架!

    在之前的文章当中,小编已经教过大家怎么搭建一个Django框架,今天我们来探索另外的一种框架的搭建,这个框架就是web框架-flask微框架啦!首先我们带着以下的几个问题来阅读本文: 1.flask是 ...

随机推荐

  1. c中的函数

    一. 什么是函数 l 任何一个C语言程序都是由一个或者多个程序段(小程序)构成的,每个程序段都有自己的功能,我们一般称这些程序段为“函数”.所以,你可以说C语言程序是由函数构成的. l 比如你用C语言 ...

  2. iOS iOS9.0 的CoreLocation定位

    一.简介 iOS9.0如果当前处于前台授权状态,默认是不可以后台获取用户位置. 如果在前台授权下,让其能获取到后台定位,该怎么办 可以设置以下属性为YES,就可以继续获取后台位置,但是会出现蓝条 使用 ...

  3. iOS 远程推送通知

    1.什么是推送通知 在某些特殊情况下,应用程序被动收到的以不同种界面形式出现的提醒信息 推送通知的作用:可以让不在前台运行的app通知app发生了改变 iOS中得推送通知种类 远程推送通知(Remot ...

  4. IOS开发之小实例--使用UIImagePickerController创建一个简单的相机应用程序

    前言:本篇博文是本人阅读国外的IOS Programming Tutorial的一篇入门文章的学习过程总结,难度不大,因为是入门.主要是入门UIImagePickerController这个控制器,那 ...

  5. 在IDEA 上使用Git查看主干和分支等

    使用IDEA 查看提交历史时,IDEA默认显示的页面是你当前页面的提交历史: 然后,你点击左侧的 log 键,则可以显示整个团队每个人的提交记录: 在选中每一次的记录以后,会弹出每次提交的所有文件(对 ...

  6. WPF学习之路(十二)控件(HeaderedContent控件)

    GroupBox 用来组织多种控件的常见控件,因为是内容空间,只能直接包含一项,需要使用面板一类的中间空间. Header和Content可以是任意元素 <GroupBox> <Gr ...

  7. input的file 控件及美化

    在一些网站进行上传时,当单击了“浏览”按钮之后会弹出[选择文件]的对话框.想要实现这一功能,用input的file控件来实现就好啦~ <!doctype html> <html la ...

  8. LinkedHashMap及其源码分析

    以下内容基于jdk1.7.0_79源码: 什么是LinkedHashMap 继承自HashMap,一个有序的Map接口实现,这里的有序指的是元素可以按插入顺序或访问顺序排列: LinkedHashMa ...

  9. ksvcreate: Process(m000) creation failed

    一测试服务器数据库(Oracle Database 10g Release 10.2.0.5.0 - 64bit Production)突然访问不了,检查发现数据库处于挂起模式(hang mode), ...

  10. Mongodb源代码阅读笔记:Journal机制

    Mongodb源代码阅读笔记:Journal机制 Mongodb源代码阅读笔记:Journal机制 涉及的文件 一些说明 PREPLOGBUFFER WRITETOJOURNAL WRITETODAT ...