几周或几个月后,带有DRF API的Django减慢
我的Django带有DRF网站,它具有基于grenicapi视图和API视图的DRF的几个API。 API用于计算XML与XML和JSON与JSON差异。将两个对象作为主体传递到这些API,而API返回发现差异的差异和确切的节点。它还以添加或删除的节点响应。
当我的环境刚刚启动并持续几个星期时,视线和API正常工作2周。我最近观察到,一个月或3周后,相同的API需要更多时间来计算相同数据的差异。
通常,例如,如果我们有大的JSON对象,则每秒处理1K差异。如果我们的JSON或XML对象很小,例如5至10个键(非常基本)的主要库函数,它可以计算出差异的故事几乎几毫秒。因此,总体API时间大约是200毫秒。
现在,我遇到的问题是在说3周或一个月相同的基本JSON对象比较(只有5-10个键)需要20秒钟才能做出回应。库功能只需20秒即可计算一个或两个差异。
我在这里没有使用任何缓存。我的任何库功能都没有涉及数据库操作。
我确实使用dict并列出python中的数据类型来存储计算的差异。知道为什么会发生这种情况?
下属详细信息:
- 4VCPU机器,带16 GB RAM(AWS T3.XLARGE)
- DOCKER与Nginx,Gunicorn Django组成环境
I have Django with DRF website and it has couple of APIs based on DRF with GenericAPI view and API view. The APIs is used to calculate XML vs XML and JSON vs JSON differences. Two objects are passed as body to these APIs and the API returns the no of differences and exact nodes at which the differences are found. It also respond with nodes which are added or removed.
The sight and APIs work just fine when my environment is just up and running for few weeks say 2 weeks. I have recently observed that after a month or 3 weeks same APIs takes much more time to calculate the differences with same set of data.
Usually it is very fast for example If we have large JSON object then 1k differences per second is processed. If we have pretty small JSON or XML object like 5 to 10 keys (very basic) the main library function which calculates the difference tales just about few milliseconds. So overall API time is like 200 ms.
Now the issue that I have is after lets say 3 weeks or a month same very basic JSON object comparison (with just 5-10 keys) takes 20 seconds to respond. The library function takes almost 20 seconds to calculate just one or two difference.
I am not using any caching here. No Database operations are involved in any of my library function.
I do use dict and list data types in python to store the differences calculated. Any idea why does this happen?
Infra details:
- 4VCPU machine with 16 GB ram (AWS t3.xlarge)
- docker compose environment with nginx, gunicorn django
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论