English 中文(简体)
Nginx + uWsgi + Djangopinrange json response conduct
原标题:Nginx + uWsgi + Django strange json response behavior

一些技术规格:

  • CentOS 6.0
  • uWSGI 0.9.9.2
  • Nginx 1.0.5
  • Django 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序列izer:

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)

纽约总部 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)

我有几句JsonResponse与其他一些json_status_code和电文。

观点:

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

<><>>>>:>>

即使在申请状况发生变化时,我还是收到3至4秒的老小 j,然后回到JsonApplication SuspbilResponse正确。

I checked the database application status update takes place immediately, also noticed that if I reboot uWSGI and send request response is correct and the opposite situation happens. Second request after status change can have old json.

It looks as if they write the response for few sencods and had a problem with her ​​refresh (Cache is disabled).

Any ideas where it might be the problem ?

同一法典在Appa2和Mod_wsgi实施罚款。

<>限值>

在JsonResponse,我说:

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

<<>json={>>>>部分非常重要,JsonResponse和JsonResponse在共享初始字典及其内容后各分流,因此答案不改变。

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}

Thanks for your time

问题回答

你们是否试图使假肢最佳化(将最佳选择从育空观测组的议事档案中删除)?

即便如此看一格/html/客户问题,某些物体也能够使某些东西得到优化。 并且,请不要 advise地认为降级为1年以上未证实的版本。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签