mod_wsgi& django定期挂在铬中

时间:2011-06-09 21:42:21

标签: django mod-wsgi

之前我遇到过这个问题,但刚刚将一个新站点部署到一个完全不同的服务器并遇到了同样的问题。如果我浏览网站使用Chromium,它偶尔会挂起。 Chromium已向服务器发出请求,只是坐在那里等待响应。它保持这样一分钟或直到我点击停止按钮再试一次。有时它也会挂起响应 - 铬中的微调器改变方向,页面变白,但没有其他事情发生。

为了实现这一点,我通常只需要快速连续访问几个页面。我通常在查看大约10页后看到这一点。服务器上的“顶部”显示没有发生任何事情(python / wsgi没有执行),所以这不是服务器重载的问题。访问日志中没有任何内容(即它没有注册),也没有在错误日志中。

我很难过。请有人指出我可能会如何进行调试。我无法发布一个执行当前这种方式的网站: - (

由于

配置文件如下:

apache conf file:

<VirtualHost *:80>
ServerName mysite.org
ServerAlias www.mysite.* demo.mysite.org

# Rewrite rules to add 'www.' if it's not present
RewriteEngine On
RewriteCond %{HTTP_HOST} !(www|demo)\.mysite.org
RewriteRule ^(.*)$ http://www.mysite.org$1 [R=301,L]

WSGIDaemonProcess mycms processes=5 threads=5 display-name=%{GROUP} \
    user=nobody group=nobody

WSGIScriptAlias / /var/www/python/mycms/mycms/conf/apache/mycms.wsgi \
    process-group=mycms application-group=%{GLOBAL}

<Directory /var/www/python/mycms/mycms/conf/apache/>
  WSGIProcessGroup mycms
  Order deny,allow
  Allow from all
</Directory>

Alias /media/admin/ /var/www/python/mycms/venv/lib/python2.7/site-packages/Django-1.2.5-py2.7.egg/django/contrib/admin/media/

<Directory /var/www/python/mycms/venv/lib/python2.7/site-packages/Django-1.2.5-py2.7.egg/django/contrib/admin/media>
  Order deny,allow
  Allow from all
  Options +FollowSymLinks
</Directory>

Alias /media/ /var/www/python/mycms/mycms/media/

<Directory /var/www/python/mycms/mycms/media>
  Order deny,allow
  Allow from all
</Directory>
</VirtualHost>

WSGI:

import os
import sys

root = os.path.join(os.path.dirname(__file__), '../../..')
sys.path.insert(0, root)

activate_this = os.path.join(root, 'venv/bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))

os.environ['PYTHON_EGG_CACHE'] = '/tmp/python-eggs'
os.environ['DJANGO_SETTINGS_MODULE'] = 'mycms.settings_production'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

(部分)settings.py:

import os

# Django settings for mycms project.

gettext = lambda s: s

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'mycms',                      # Or path to database file if using sqlite3.
    'USER': 'user',                      # Not used with sqlite3.
    'PASSWORD': 'pass',                  # Not used with sqlite3.
    'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
}
}


SITE_ID = 1

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/media/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/admin/'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'mycms.app.middleware.SiteDetectionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.multilingual.MultilingualURLMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.media.PlaceholderMediaMiddleware',
)

ROOT_URLCONF = 'mycms.urls'

TEMPLATE_DIRS = os.path.join(BASE_DIR, 'templates')

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.sitemaps',
'cms',
'cms.plugins.text',
'cms.plugins.picture',
'cms.plugins.link',
'cms.plugins.file',
'cms.plugins.teaser',
'cms.plugins.googlemap',
'appmedia',
'mptt',
'publisher',
'menus',
'cmsplugin_contact',
'mycms.app.html-sitemap',
'mycms.app.siteprofile',
'haystack',
'cms_search',
'cms_search.search_helpers',
)

TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.i18n",
"django.core.context_processors.request",
"django.core.context_processors.media",
"mycms.app.context_processors.multisite",
"cms.context_processors.media",
)

SiteDetectionMiddleware(禁用此功能并不能解决问题)。我正在使用这个,因为我想从一个django安装服务说50个站点,并有一个工作池可以服务所有站点。每个站点有一个wsgi会预先分配资源,但是当某些站点比其他站点更繁忙时,不允许在站点之间重新分配它们的任何灵活性:

from django.contrib.sites.models import Site
from django.conf import settings
from django.http import HttpResponseServerError
from mycms.app.siteprofile.models import *

class SiteDetectionMiddleware:
    """
    Sets the SITE_ID depending on the current HTTP host name.

    This allows multiple sites with identical settings to be run
    easily.
    """
    def process_request(self, request):
        host = request.META.get('HTTP_HOST')
        if host:
            try:
                site = Site.objects.get(domain=host)
                settings.SITE_ID = site.id

                profile = Profile.objects.get(site=site)

                settings.CMS_TEMPLATES = profile.get_template_tuples() + \
                    (settings.CMS_TEMPLATES[len(settings.CMS_TEMPLATES) - 1],)
            except Site.DoesNotExist:
                return HttpResponseServerError()
            except Profile.DoesNotExist:
                pass

1 个答案:

答案 0 :(得分:0)

使用:

http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Tracking_Request_and_Response

确定挂起发生时是否实际到达mod_wsgi。从那里调试。