python - 在第一次请求时,Lighttpd + fastcgi + python ( 用于 Django ) 慢

  显示原文与译文双语对照的内容

我与 lighttpd + fastcgi主机的Django 网站有问题。 它工作得很好,但似乎第一个请求总是需要 3秒的时间。 后续请求的( <1s ) 更快。

我在lighttpd中激活访问日志以跟踪问题。 但是我有点卡住了。

以下是'失去'4s ( 从 10: 04: 17到:04: 21 )的日志:


2012-12-01 10:04:17: (mod_fastcgi.c.3636) handling it in mod_fastcgi 


2012-12-01 10:04:17: (response.c.470) -- before doc_root 


2012-12-01 10:04:17: (response.c.471) Doc-Root :/var/www 


2012-12-01 10:04:17: (response.c.472) Rel-Path :/finderauto.fcgi 


2012-12-01 10:04:17: (response.c.473) Path : 


2012-12-01 10:04:17: (response.c.521) -- after doc_root 


2012-12-01 10:04:17: (response.c.522) Doc-Root :/var/www 


2012-12-01 10:04:17: (response.c.523) Rel-Path :/finderauto.fcgi 


2012-12-01 10:04:17: (response.c.524) Path :/var/www/finderauto.fcgi 


2012-12-01 10:04:17: (response.c.541) -- logical -> physical 


2012-12-01 10:04:17: (response.c.542) Doc-Root :/var/www 


2012-12-01 10:04:17: (response.c.543) Rel-Path :/finderauto.fcgi 


2012-12-01 10:04:17: (response.c.544) Path :/var/www/finderauto.fcgi 


2012-12-01 10:04:21: (response.c.128) Response-Header: 


HTTP/1.1 200 OK


Last-Modified: Sat, 01 Dec 2012 09:04:21 GMT


Expires: Sat, 01 Dec 2012 09:14:21 GMT


Content-Type: text/html; charset=utf-8


Cache-Control: max-age=600


Transfer-Encoding: chunked


Date: Sat, 01 Dec 2012 09:04:21 GMT


Server: lighttpd/1.4.28



我想如果有问题那就是我的配置。 下面是我启动 Django 应用程序的方法:


python manage.py runfcgi method=threaded host=127.0.0.1 port=3033



下面是我的lighttpd conf:


 server.modules = (


"mod_access",


"mod_alias",


"mod_compress",


"mod_redirect",


"mod_rewrite",


"mod_fastcgi",


"mod_accesslog",


)



server.document-root ="/var/www"


server.upload-dirs = ("/var/cache/lighttpd/uploads" )


server.errorlog ="/var/log/lighttpd/error.log"


server.pid-file ="/var/run/lighttpd.pid"


server.username ="www-data"


server.groupname ="www-data"


accesslog.filename ="/var/log/lighttpd/access.log" 



debug.log-request-header ="enable"


debug.log-response-header ="enable"


debug.log-file-not-found ="enable"


debug.log-request-handling ="enable"


debug.log-timeouts ="enable"


debug.log-ssl-noise ="enable"


debug.log-condition-cache-handling ="enable"


debug.log-condition-handling ="enable"



fastcgi.server = (


"/finderauto.fcgi" => (


"main" => (


 # Use host/port instead of socket for TCP fastcgi


"host" =>"127.0.0.1",


"port" => 3033,


 #"socket" =>"/home/finderadmin/finderauto.sock",


"check-local" =>"disable",


"fix-root-scriptname" =>"enable",


 )


 ),


)


alias.url = (


"/media" =>"/home/user/django/contrib/admin/media/",


)



url.rewrite-once = (


"^(/media.*)$" =>"$1",


"^/favicon.ico$" =>"/media/favicon.ico",


"^(/.*)$" =>"/finderauto.fcgi$1",


)



index-file.names = ("index.php","index.html",


"index.htm","default.htm",


" index.lighttpd.html" )



url.access-deny = ("~",".inc" )



static-file.exclude-extensions = (".php",".pl",".fcgi" )



## Use ipv6 if available


#include_shell"/usr/share/lighttpd/use-ipv6.pl"



dir-listing.encoding ="utf-8"


server.dir-listing ="enable"



compress.cache-dir ="/var/cache/lighttpd/compress/"


compress.filetype = ("application/x-javascript","text/css","text/html","text/plain" )



include_shell"/usr/share/lighttpd/create-mime.assign.pl"


include_shell"/usr/share/lighttpd/include-conf-enabled.pl"



如果你们能帮助我找出我丢失这些 3或者 4的地方。 我很感激。

更新:一个信息,我激活了fastcgi日志,并且在以下两个fcgi日志之间得到 3s 个延迟:


2012-12-01 18:18:12: (mod_fastcgi.c.3636) handling it in mod_fastcgi 


2012-12-01 18:18:12: (response.c.470) -- before doc_root 


2012-12-01 18:18:12: (response.c.471) Doc-Root :/var/www 


2012-12-01 18:18:12: (response.c.472) Rel-Path :/finderauto.fcgi 


2012-12-01 18:18:12: (response.c.473) Path : 


2012-12-01 18:18:12: (response.c.521) -- after doc_root 


2012-12-01 18:18:12: (response.c.522) Doc-Root :/var/www 


2012-12-01 18:18:12: (response.c.523) Rel-Path :/finderauto.fcgi 


2012-12-01 18:18:12: (response.c.524) Path :/var/www/finderauto.fcgi 


2012-12-01 18:18:12: (response.c.541) -- logical -> physical 


2012-12-01 18:18:12: (response.c.542) Doc-Root :/var/www 


2012-12-01 18:18:12: (response.c.543) Rel-Path :/finderauto.fcgi 


2012-12-01 18:18:12: (response.c.544) Path :/var/www/finderauto.fcgi 


2012-12-01 18:18:12: (mod_fastcgi.c.3061) got proc: pid: 0 socket: tcp:127.0.0.1:3033 load: 1 



可能它与fastcgi配置相链接?

提前致谢!

时间: 原作者:

有没有可能你的网站上没有多少活动? 我认为 python 解释器在下一次请求之前被从内存中删除。 你有足够的内存储存你的软件? 是否有其他任务正在运行,可能会导致 python 内存不足- 可能只是维护,或者是邮件服务器?

原作者:
...