Forums

Slow response - Django

Hello guys,I would need help with my first app. I am beginner so sorry for noob terminology used. So I followed "Why is my site slow?" and found out that everything until last line is "instant". Last line is return JsonResponse and this one takes 7-16 sec (response time). I use SQlite but there is not much data that it should make a difference.(I guess it would slow down all filtering steps before JsonResponse which is not case). Gzip middleware trick in settings made size smaller but no difference in Time.Last time I did request by Postman size of response was 30Kb and time was 20 sec. What may be issue and how can I solve this? It rapidly slowed down when my DB went from 800 items to 2000 items.( around 5MB sqlite file). Thank you.

You may actually be doing other work in the call to JsonResponse that is not obvious. For instance, you may be passing something to the JsonResponse that takes time to create. If you are passing anything other than a simple, pre-created dictionary, try extracting that part into a variable and then passing that variable into the JsonResponse. Then you can see if it's the JsonResponse or whether there is other non-obvious work going on.

@glenn Hi,thank you. You are right. serializer.data is the problem. Do you know why is that and what should I look for or you need more detail? One more thing I noticed. Higher page,slower response

I commented out in class Meta: "#ordering = ["-price"]" and it works fast now. I am still looking for "why" on net

Thanks for letting us know!