Asked 9 months ago by SaturnianRanger210
Why Does a Simple Field Update in a Django API Endpoint Cause a Major Performance Drop?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 9 months ago by SaturnianRanger210
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I'm encountering a significant performance degradation when executing a field update in a high-frequency Django API endpoint. The endpoint handles around 4000 requests per second when it simply retrieves the last Url object and returns its data. The original implementation is as follows:
PYTHONdef get(self, request): urls = Url.objects.all().last() if urls: data = {"name": urls.name, "url": urls.url} return Response(data, status=200) return Response({"name": "not found", "url": "not found"}, status=200)
However, when adding a field update, the number of requests per second drops to about 700. The modified code is:
PYTHONdef get(self, request): urls = Url.objects.all().last() if urls: urls.remark = "test remark" urls.save() data = {"name": urls.name, "url": urls.url} return Response(data, status=200) return Response({"name": "not found", "url": "not found"}, status=200)
I would like to know:
urls.remark = "test remark"
and urls.save()
) cause such a dramatic performance decrease?Any insights or recommendations would be greatly appreciated.
Comments 0
•Answers 0
•Views 234
No comments yet.