2012-12-01 112 views
2

我遇到了一個我用lighttpd + fastcgi託管的django網站的問題。 它的效果很好,但似乎第一個請求總是需要3秒。後續請求要快得多(< 1秒)。Lighttpd + fastcgi + python(for django)第一次請求很慢

我激活了lighttpd中的訪問日誌以跟蹤問題。但我有點卡住了。

這裏有日誌,我「丟失」 4S(從10點04分17秒至10時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配置有關?

在此先感謝!

+0

1.這裏只有一個日誌,而不是兩個。 2.在windows上,我有和lighttpd和PHP相同的問題。你有解決方案嗎 ?發佈它作爲答案:)謝謝。 – Sandman4

回答

0

有沒有可能您的網站上沒有太多活動?我在考慮下一個請求之前python解釋器是從內存中刪除的。你有足夠的內存來保存所有的軟件嗎?是否還有其他任務可能會導致python內存不足 - 可能只是維護或郵件服務器?