我将 S3 Buckets 用于我的 Django 应用程序的静态和媒体文件。我在存储桶“前面”有 AWS CloudFront,我已经设置django-storages
好使用这个 CDN 为我提供文件。但是,我的请求花费了太长时间。值得一提的是,我正在使用HyperlinkedModelSerializer
and VersatileImageField
。我希望 CDN 检索到我的文件,但看起来我的应用程序正在使用 boto3 实际从 S3 下载文件(我认为这是在序列化过程中发生的)。
以下是来自 cProfile 的一些信息:
ncalls tottime percall cumtime percall filename:lineno(function)
174 0.004 0.000 17.172 0.099 /MyProjectPath/env/lib/python3.8/site-packages/storages/backends/s3boto3.py:515(exists)
61 0.003 0.000 16.586 0.272 /MyProjectPath/env/lib/python3.8/site-packages/boto3/s3/inject.py:723(object_download_fileobj)
61 0.001 0.000 16.582 0.272 /MyProjectPath/env/lib/python3.8/site-packages/boto3/s3/inject.py:624(download_fileobj)
62 0.003 0.000 57.723 0.931 /MyProjectPath/env/lib/python3.8/site-packages/rest_framework/serializers.py:507(to_representation)
62 0.000 0.000 57.687 0.930 /MyProjectPath/env/lib/python3.8/site-packages/versatileimagefield/serializers.py:53(to_representation)
62 0.000 0.000 57.687 0.930 /MyProjectPath/env/lib/python3.8/site-packages/versatileimagefield/serializers.py:42(to_native)
62 0.003 0.000 57.686 0.930 /MyProjectPath/env/lib/python3.8/site-packages/versatileimagefield/utils.py:220(build_versatileimagefield_url_set)
我认为应用程序不应该直接联系 S3 存储桶。有没有人经历过这个?这可能是因为配置错误,还是有任何与 DRF/django-storages/VersatileImage 相关的已知问题会严重影响性能?