0
我正在查看Google Chrome控制檯ajax請求時間。 我在後端測量,mysql查詢執行5毫秒。 在Chrome控制檯,我看到this pictureDjango + Gunicorn大TTFB時間
TTFB時間333.07毫秒。 我有9個gunicorn工作者,Django框架和REST框架。什麼需要這麼多時間?
例如, 我的觀點:
@api_view(['GET'])
def get_gallery(request, slug):
query = Gallery.objects.filter(route__slug=slug, route__is_active=True)
return JSONResponse(GallerySerializer(query, many=True).data)
class JSONResponse(HttpResponse):
"""
An HttpResponse that renders its content into JSON.
"""
def __init__(self, data, **kwargs):
content = JSONRenderer().render(data)
kwargs['content_type'] = 'application/json; charset=utf-8'
super(JSONResponse, self).__init__(content, **kwargs)
我的串行:
class GallerySerializer(ModelSerializerWithAuth):
image = serializers.ImageField(use_url=False)
thumb = serializers.ImageField(use_url=False)
class Meta:
model = Gallery
fields = ('id', 'image', 'thumb')
gunicorn配置:
bind = '127.0.0.1:9090'
errorlog = '/path/to/log'
timeout=120
user = 'user'
import multiprocessing
workers = multiprocessing.cpu_count() * 2 + 1
您是否嘗試過使用分析器? –
我們應該怎麼回答這個問題,甚至沒有看到你的代碼?我們應該使用水晶球嗎? –
@NilsWerner,什麼是分析器? – MarinaaaniraM