亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 4684 | 回復: 2
打印 上一主題 下一主題

江湖救急, nginx+webpy+fastcgi模式, 多線程模式會服務(wù)掛起不響應(yīng) [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2015-04-14 10:36 |只看該作者 |倒序瀏覽
本帖最后由 isnowran 于 2015-04-15 17:45 編輯

這個問題折騰了好久, 都想換框架了, 但webpy實在用順手了, 請眾位大神幫忙看看
python fastcgi 代碼:

  1. #!/usr/local/bin/python2.7

  2. import web

  3. class version(object):
  4.     def GET(self, v):
  5.         print "in"
  6.         return "0.1.2"

  7. urls = ('/(.*)', 'version')

  8. if __name__ == "__main__":
  9.     web.config.debug = False
  10.     app = web.application(urls, globals())
  11.     app.run()
復制代碼
運行

  1. [binary@APP src]$ ./run.py fcgi 9002
復制代碼
nginx檢查:

  1. [root@APP ~]# nginx -t
  2. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  3. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
復制代碼
nginx配置:

  1. [root@APP ~]# cat /usr/local/nginx/conf/nginx.conf
  2. worker_processes  1;

  3. events {
  4.     worker_connections  1024;
  5.     use epoll;
  6. }

  7. http {
  8.     include       mime.types;
  9.     default_type  application/octet-stream;

  10.     sendfile        on;

  11.     keepalive_timeout  65;

  12.     server {
  13.         listen       80;
  14.         server_name  localhost;

  15.         location / {
  16.             root   html;
  17.             index  index.html index.htm;
  18.             include fastcgi_params;
  19.                 fastcgi_param REQUEST_METHOD $request_method;
  20.                 fastcgi_param QUERY_STRING $query_string;
  21.                 fastcgi_param CONTENT_TYPE $content_type;
  22.                 fastcgi_param CONTENT_LENGTH $content_length;
  23.                 fastcgi_param GATEWAY_INTERFACE CGI/1.1;
  24.                 fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
  25.                 fastcgi_param REMOTE_ADDR $remote_addr;
  26.                 fastcgi_param REMOTE_PORT $remote_port;
  27.                 fastcgi_param SERVER_ADDR $server_addr;
  28.                 fastcgi_param SERVER_PORT $server_port;
  29.                 fastcgi_param SERVER_NAME $server_name;
  30.                 fastcgi_param SERVER_PROTOCOL $server_protocol;
  31.                 fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
  32.                 fastcgi_param PATH_INFO $fastcgi_script_name;
  33.                 fastcgi_pass 127.0.0.1:9002;
  34.         }

  35.         error_page   500 502 503 504  /50x.html;
  36.         location = /50x.html {
  37.             root   html;
  38.         }
  39.     }
  40. }
  41. [root@APP ~]#
復制代碼
第一次請求測試:

  1. [root@APP ~]# curl http://127.0.0.1/
  2. 0.1.2
復制代碼
ab1000個并發(fā)測試:

  1. [root@APP ~]# ab -c1000 -n 1000 http://127.0.0.1/      
  2. This is ApacheBench, Version 2.3 <$Revision: 655654 $>
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  4. Licensed to The Apache Software Foundation, http://www.apache.org/

  5. Benchmarking 127.0.0.1 (be patient)
  6. apr_socket_recv: Connection reset by peer (104)
  7. Total of 32 requests completed
復制代碼
再次請求測試, 就卡死了, 但是, fcgi能打印出"in":

  1. [root@APP ~]# curl http://127.0.0.1/
復制代碼
重啟nginx沒用, 必須重啟fastcgi

為了排除是nginx的問題, 我又用c做fastcgi測試, 就沒有問題, 無論并發(fā)有多大, 都不會造成無響應(yīng), 代碼如下:

  1. [binary@APP src]$ cat cgi.cpp
  2. #include <iostream>
  3. #include <fcgi_stdio.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>

  6. using namespace std;

  7. int main ()
  8. {
  9.         int count = 0;

  10.         while (FCGI_Accept () >= 0)
  11.         {

  12.                 printf ("Content-type:text/html\r\n\r\n");
  13.                 printf ("<p> Hello FastCGI !  </ p>");
  14.                 printf ("<br /> Request number = [%d]", ++count);
  15.                 printf ("<br /> Process ID: %d ", getpid ());
  16.         }

  17.         return 0;
  18. }
復制代碼
各個組件版本, nginx:1.63. webpy:0.3.7:

  1. [binary@APP src]$ nginx -v  
  2. nginx version: nginx/1.6.3
  3. [binary@APP src]$
復制代碼

  1. NAME
  2.     web - web.py: makes web apps (http://webpy.org)

  3. FILE
  4.     /usr/local/lib/python2.7/site-packages/web/__init__.py

  5. PACKAGE CONTENTS
  6.     application
  7.     browser
  8.     contrib (package)
  9.     db
  10.     debugerror
  11.     form
  12.     http
  13.     httpserver
  14.     net
  15.     python23
  16.     session
  17.     template
  18.     test
  19.     utils
  20.     webapi
  21.     webopenid
  22.     wsgi
  23.     wsgiserver (package)

  24. SUBMODULES
  25.     __init__
  26.     web

  27. DATA
  28.     __author__ = ['Aaron Swartz <me@aaronsw.com>', 'Anand Chitipothu <anan...
  29.     __contributors__ = 'see http://webpy.org/changes'
  30.     __license__ = 'public domain'
  31.     __version__ = '0.37'
  32.     config = <Storage {'debug': True, '__doc__': '\nA configu...A0A0J', 'h...
  33.     ctx = <ThreadedDict {'__doc__': '\nA `storage` object ...`\n   : A str...
  34.     generators = _Feature((2, 2, 0, 'alpha', 1), (2, 3, 0, 'final', 0), 0)
  35.     iters = (<type 'list'>, <type 'tuple'>, <type 'set'>, <type 'set'>)
  36.     re_compile = <web.utils.Memoize instance>

  37. VERSION
  38.     0.37

  39. AUTHOR
  40.     ['Aaron Swartz <me@aaronsw.com>', 'Anand Chitipothu <anandology@gmail.com>']
復制代碼

論壇徽章:
0
2 [報告]
發(fā)表于 2015-04-14 12:36 |只看該作者
本帖最后由 isnowran 于 2015-04-14 12:37 編輯

找到了問題所在, 應(yīng)該是flup多線程不加鎖導致的, 但不知道為啥, 莫非這個參數(shù)會導致flup死鎖?:
哪位大俠能深究一下, 給兄弟長長眼吧
在 /usr/local/lib/python2.7/site-packages/web/wsgi.py:

  1. def runfcgi(func, addr=('localhost', 8000)):
  2.     """Runs a WSGI function as a FastCGI server."""
  3.     import flup.server.fcgi as flups
  4.     #return flups.WSGIServer(func, multiplexed=True, bindAddress=addr, debug=False).run()
  5.     # 改為 multiplexed = False
  6.     return flups.WSGIServer(func, multiplexed=False, bindAddress=addr, debug=False).run()
復制代碼
影響到的flup代碼:
vi /usr/local/lib/python2.7/site-packages/flup/server/fcgi_base.py

  1.         if not self.multithreaded:
  2.             self._appLock.acquire()
  3.         try:
  4.             try:
  5.                 result = self.application(environ, start_response)
  6.                 try:
  7.                     for data in result:
  8.                         if data:
  9.                             write(data)
  10.                     if not headers_sent:
  11.                         write('') # in case body was empty
  12.                 finally:
  13.                     if hasattr(result, 'close'):
  14.                         result.close()
  15.             except socket.error, e:
  16.                 if e[0] != errno.EPIPE:
  17.                     raise # Don't let EPIPE propagate beyond server
  18.         finally:
  19.             if not self.multithreaded:
  20.                 self._appLock.release()
復制代碼

論壇徽章:
0
3 [報告]
發(fā)表于 2015-04-24 15:02 |只看該作者
我來學習了!!好帖,支持下!
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP