FCGI功能
fcgi function是基于C/CPP语言的接口,它构建在FastCGI的基础上,并具有内置功能处理程序支持,它还提供了有用的收集工具来增强设施。它可以与nginx fastcgi模块集成
它如何工作
安装了先决权
nginx –https://www.***nginx.com/
FCGI库-https://g*it*hub.co*m/fastcgi-archives/fastcgi.com
cmake和制造
支持的OS:Linux,Mac OSX和Windows
递归克隆存储库
git克隆-Recursive https://g*ith*ub.*com/taymindis/fcgi-function.git
如何构建
只需在您的项目中加入ffunc.h和ffunc.c,最简单的方式(适用于Linux,Darwin和Windows平台)
建立样本
gcc profile_service.c ffunc.c ffunc.h -lfcgi -pthread -ldl -rdynamic
g ++ profile_service.cpp ffunc.c ffunc.h -lfcgi -pthread -ldl -rdynamic
G ++ -STD = C ++ 11 -I/HOME/HOME/XXX/CPPLIB/SPDLOG -0.17.0/include -dspdlog_fmt_printf service_with_with_spdlog.cpp ffunc.c ffunc.c ffunc.c ffunc.h -lfcgi -lfcgi -pthRead -pthRead -pthread -pthRead -lddl -lddlynamic namemic
当您输入时
./ simple_service
它将结果: –
Service starting sock_port=2005, backlog=16 total function = 3 64 threads in process Socket on hook 2005
通过设置ffunc_conf->daemon = 1在后台运行,请参见模式详细信息示例
int ffunc_main ( int argc , char * argv [], ffunc_config_t * ffunc_conf ) { ffunc_conf -> sock_port = 2005 ; ffunc_conf -> backlog = 160 ; ffunc_conf -> max_thread = 64 ; ffunc_conf -> daemon = 1 ; // run as daemon ffunc_parse_function ( ffunc_conf , \"getProfile\" , \"postError\" , \"postProfile\" ); return 0 ; }
在Valgrind上运行(性能会影响)
valgrind-leak-check = full-show-leak-kinds = all – trace-children = yes ./ simple_service
通过在您的服务器块中附加编辑nginx配置文件夹中的nginx.conf: –
location /getProfile {
add_header Allow \"GET, POST, HEAD\" always;
if ( $request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
include /etc/nginx/fastcgi_params;
fastcgi_param FN_HANDLER getProfile;
fastcgi_pass 127.0.0.1:2005;
}
location /postProfile {
add_header Allow \"GET, POST, HEAD\" always;
if ( $request_method !~ ^(POST)$ ) {
return 405;
}
include /etc/nginx/fastcgi_params;
fastcgi_param FN_HANDLER postProfile;
fastcgi_pass 127.0.0.1:2005;
}
通过附加在您的httpd配置文件夹中编辑httpd.conf
<Location \"/getProfile\">
# Timeout values are in seconds
ProxyPass \"fcgi://127.0.0.1:2005\" connectiontimeout=300 timeout=300
ProxyPassReverse \"fcgi://127.0.0.1:2005\"
SetEnv FN_HANDLER \"getProfile\"
</Location>
您会看到fn_handler是功能名称映射,其中包含simple_service代码中的函数,fastcgi port 2005是您开始使用的服务(请查看步骤10以获取更多详细信息。
启动NGINX/HTTPD服务器
使用Apache基准测试获得请求加载测试
AB -C 100 -N 10000 http://127.0.0.1:80/getProfile
用于后请求负载测试
AB -P“ PAYLOAD.TXT” -T应用程序/JSON -C 100 -N 10000 http://127.0.0.0.1:80/postProfile
有效load.txt在根目录内
关闭背景实例
通过使用kill -2 <pid>杀死该过程
对于Valgrind Log,您将在kill -2 <pid>后获得摘要报告
如何构建Docker图像的示例
cd DockerExample docker build -t nginx_ffunc -f Dockerfile_ngx_ffunc . docker run -d -v ~ /fcgi-function/DockerExample:/tmp -p 80:80 --name testffunc nginx_ffunc curl \" http://127.***0.0.1/getProfile \"
记录建议
由于内置的日志记录机制,将降低过程速度,建议使用第三方记录机制为您的应用层进行: –
C ++ SPDLOG
C ++ G3log
C mini-assync-log
