- 论坛徽章:
- 0
|
本帖最后由 isnowran 于 2015-04-15 17:45 编辑
这个问题折腾了好久, 都想换框架了, 但webpy实在用顺手了, 请众位大神帮忙看看
python fastcgi 代码:
- #!/usr/local/bin/python2.7
- import web
- class version(object):
- def GET(self, v):
- print "in"
- return "0.1.2"
- urls = ('/(.*)', 'version')
- if __name__ == "__main__":
- web.config.debug = False
- app = web.application(urls, globals())
- app.run()
复制代码 运行
- [binary@APP src]$ ./run.py fcgi 9002
复制代码 nginx检查:
- [root@APP ~]# nginx -t
- nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
- nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
复制代码 nginx配置:
- [root@APP ~]# cat /usr/local/nginx/conf/nginx.conf
- worker_processes 1;
- events {
- worker_connections 1024;
- use epoll;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 65;
- server {
- listen 80;
- server_name localhost;
- location / {
- root html;
- index index.html index.htm;
- include fastcgi_params;
- fastcgi_param REQUEST_METHOD $request_method;
- fastcgi_param QUERY_STRING $query_string;
- fastcgi_param CONTENT_TYPE $content_type;
- fastcgi_param CONTENT_LENGTH $content_length;
- fastcgi_param GATEWAY_INTERFACE CGI/1.1;
- fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
- fastcgi_param REMOTE_ADDR $remote_addr;
- fastcgi_param REMOTE_PORT $remote_port;
- fastcgi_param SERVER_ADDR $server_addr;
- fastcgi_param SERVER_PORT $server_port;
- fastcgi_param SERVER_NAME $server_name;
- fastcgi_param SERVER_PROTOCOL $server_protocol;
- fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
- fastcgi_param PATH_INFO $fastcgi_script_name;
- fastcgi_pass 127.0.0.1:9002;
- }
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- }
- [root@APP ~]#
复制代码 第一次请求测试:
- [root@APP ~]# curl http://127.0.0.1/
- 0.1.2
复制代码 ab1000个并发测试:
- [root@APP ~]# ab -c1000 -n 1000 http://127.0.0.1/
- 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)
- apr_socket_recv: Connection reset by peer (104)
- Total of 32 requests completed
复制代码 再次请求测试, 就卡死了, 但是, fcgi能打印出"in":
- [root@APP ~]# curl http://127.0.0.1/
复制代码 重启nginx没用, 必须重启fastcgi
为了排除是nginx的问题, 我又用c做fastcgi测试, 就没有问题, 无论并发有多大, 都不会造成无响应, 代码如下:
- [binary@APP src]$ cat cgi.cpp
- #include <iostream>
- #include <fcgi_stdio.h>
- #include <stdlib.h>
- #include <stdio.h>
- using namespace std;
- int main ()
- {
- int count = 0;
- while (FCGI_Accept () >= 0)
- {
- printf ("Content-type:text/html\r\n\r\n");
- printf ("<p> Hello FastCGI ! </ p>");
- printf ("<br /> Request number = [%d]", ++count);
- printf ("<br /> Process ID: %d ", getpid ());
- }
- return 0;
- }
复制代码 各个组件版本, nginx:1.63. webpy:0.3.7:
- [binary@APP src]$ nginx -v
- nginx version: nginx/1.6.3
- [binary@APP src]$
复制代码
- NAME
- web - web.py: makes web apps (http://webpy.org)
- FILE
- /usr/local/lib/python2.7/site-packages/web/__init__.py
- PACKAGE CONTENTS
- application
- browser
- contrib (package)
- db
- debugerror
- form
- http
- httpserver
- net
- python23
- session
- template
- test
- utils
- webapi
- webopenid
- wsgi
- wsgiserver (package)
- SUBMODULES
- __init__
- web
- DATA
- __author__ = ['Aaron Swartz <me@aaronsw.com>', 'Anand Chitipothu <anan...
- __contributors__ = 'see http://webpy.org/changes'
- __license__ = 'public domain'
- __version__ = '0.37'
- config = <Storage {'debug': True, '__doc__': '\nA configu...A0A0J', 'h...
- ctx = <ThreadedDict {'__doc__': '\nA `storage` object ...`\n : A str...
- generators = _Feature((2, 2, 0, 'alpha', 1), (2, 3, 0, 'final', 0), 0)
- iters = (<type 'list'>, <type 'tuple'>, <type 'set'>, <type 'set'>)
- re_compile = <web.utils.Memoize instance>
- VERSION
- 0.37
- AUTHOR
- ['Aaron Swartz <me@aaronsw.com>', 'Anand Chitipothu <anandology@gmail.com>']
复制代码 |
|