1

いくつかの技術仕様:

  • CentOS 6.0
  • uWSGI 0.9.9.2
  • ニンクス 1.0.5
  • ジャンゴ 1.3.1

uWSGI:

    [uwsgi]
    socket = 127.0.0.1:3031
    master = true
    processes = 5
    uid = xx
    gid = xx
    env = DJANGO_SETTINGS_MODULE=xx.settings
    module = django.core.handlers.wsgi:WSGIHandler()
    post-buffering = 8192
    harakiri = 30
    harakiri-verbose = true
    disable-logging = true
    logto = /var/log/xx.log
    vacuum = true
    optimize = 2

JSON シリアライザー:

class LazyEncoder(simplejson.JSONEncoder, json.Serializer):
    def default(self, obj):
        if isinstance(obj, Promise):
            return force_unicode(obj)
        if isinstance(obj, Decimal):
            u_value = force_unicode(obj)
            if u'.' in u_value:
                return float(u_value)
            return int(u_value)
        return super(lazy_encoder, self).default(obj)

JSON HttpResponse:

class JsonResponse(HttpResponse):
    status_code = 200
    json_status_code = 200
    message = _('OK')

    def __init__(self, json={}, *args, **kwargs):
        mimetype = kwargs.pop('mimetype', 'application/json')
        if not 'status' in json:
            json['status'] = {'code': self.json_status_code, 'message': self.message}
    super(JsonResponse, self).__init__(LazyEncoder(indent=settings.DEBUG and 4 or None, separators=settings.DEBUG and (', ', ': ') or (',', ':')).encode(json), mimetype=mimetype, *args, **kwargs)

他の json_status_code とメッセージを持つ JsonResponse のサブクラスがいくつかあります。

意見:

....
if application.status == Application.STATUS_REMOVED:
    return JsonApplicationSuspendedResponse()
....
return JsonResponse()

問題:

アプリケーションのステータスが変化している場合でも、3〜4秒間古いjsonを受け取り、JsonApplicationSuspendedResponse()を正しく返すことがあります。

データベース アプリケーションのステータス更新がすぐに行われることを確認しました。また、uWSGI を再起動してリクエスト応答を送信すると、正しく、逆の状況が発生することにも気付きました。ステータス変更後の 2 番目のリクエストは、古い json を持つことができます。

いくつかの sencods の応答を書き込み、更新に問題があったようです (キャッシュが無効になっています)。

それが問題になる可能性のあるアイデアはありますか?

同じコードが Apache2 と mod_wsgi で正常に動作します

修繕

これは、私が持っていた JsonResponse で、本当にばかげたバグでした:

def __init__(self, json={}, *args, **kwargs):

部分json={}はここで非常に重要です。JsonResponse と init 後の JsonResponse の各サブクラスは、最初の dict とその内容を共有していたため、答えは変更されていないように見えました。

def __init__(self, json=None, *args, **kwargs):
    mimetype = kwargs.pop('mimetype', 'application/json')
    if not json:
        json = {}
    if not 'status' in json:
        json['status'] = {'code': self.json_status_code, 'message': self.message}

御時間ありがとうございます

4

1 に答える 1

0

Python オプティマイザーを無効にしてみましたか (uWSGI 構成ファイルから最適化オプションを削除します)?

js/html/client の問題のように見えても、最適化を有効にすると、一部のオブジェクトが何らかの混乱を招く可能性があります。また、サポートされていない 1 年以上前のバージョンにダウングレードするなどのばかげたアドバイスに従わないでください。

于 2011-09-29T04:46:29.747 に答える