拥有运行在简单的基于泛型类的视图上的网站。首先,我认为-- QuerySets是问题所在,但由于我的所有查询都低于8ms,所以这不是问题所在。在当地,该网站运行速度低于-200/300毫秒与所有图像和一切。当我把它推给Heroku时,速度很慢。在检查铬条-它显示1直线1-2秒,然后加载其余-它等待1-2秒,然后它加载。因此,我已经开始分解这个过程,得出了一个结论--删除DB,它开始加载非常快,就像100 in -当我插入Postgres时,它立即进入慢模式。
还安装了Django-Toolbar来查看正在发生的事情。
Note: this is not a question about the load time when the dyno is sleeping. It is a question about every single refresh, request while browsing the site - the experience.
以下是结果。我甚至试着把DB和app放在更高的层次上,只是为了看,没有区别。所以我所做的是很好地创建了简单的视图测试--我看到的3幅图像不会导致它并加载它--需要1-2秒才能开始加载,同时也可以快速删除DB负载。
然后我发现了这个:持久连接
如果我设置为500 -它加载更长的设置为None -稍微快一点-但始终没有关闭数据库连接是不好的。没有理由小站点会在没有设置的情况下加载那么慢。
我甚至尝试把它放在18.04 Ubuntu上的数字海洋上--并安装Postgres --虽然速度稍快,但效果相似。不知道我还能做什么。
views.py -所有的视图都非常简单,没有复杂的逻辑,大多数情况下它们甚至没有get_context_data方法。
class DocumentaryFullDetailView(DetailView):
model = Documentary
template_name = "documentary-full.html"
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super().get_context_data(**kwargs)
context['all_documentary_photos'] = Photo.objects.filter(documentary=self.get_object()).prefetch_related('documentary')
return context依赖关系:
bleach==3.1.0
boto==2.49.0
boto3==1.9.130
botocore==1.12.130
Collectfast==0.6.2
coverage==4.5.3
dj-database-url==0.5.0
dj-static==0.0.6
Django==2.2.3
django-admin-sortable2==0.7.2
django-appconf==1.0.3
django-bleach==0.5.3
django-boto==0.3.12
django-cacheops==4.1
django-ckeditor==5.6.1
django-compressor==2.2
django-debug-toolbar==2.0
django-environ==0.4.5
django-js-asset==1.2.2
django-markdown-deux==1.0.5
django-markdownx==2.0.28
django-model-utils==3.2.0
django-nocaptcha-recaptcha==0.0.20
django-redis==4.10.0
django-sendgrid-v5==0.8.0
django-storages==1.7.1
docutils==0.14
entrypoints==0.3
flake8==3.7.7
funcy==1.12
future==0.17.1
gunicorn==19.9.0
jmespath==0.9.4
Markdown==3.1
markdown2==2.3.7
mccabe==0.6.1
olefile==0.44
Pillow==6.0.0
psycopg2-binary==2.8.2
pycodestyle==2.5.0
pyflakes==2.1.1
python-dateutil==2.8.0
python-http-client==3.1.0
pytz==2018.9
rcssmin==1.0.6
redis==3.2.1
rjsmin==1.0.12
s3transfer==0.2.0
sendgrid==6.0.5
six==1.12.0
sqlparse==0.3.0
static3==0.7.0
urllib3==1.25.3
webencodings==0.5.1这里是大约2000 is 的直线




发布于 2019-07-29 19:25:11
建立与Postgres数据库的连接可能非常缓慢。我建议使用像PgBouncer (https://pgbouncer.github.io/)这样的连接池。您可以为Heroku获得一个构建包,该包透明地为您完成了大部分艰苦工作:https://github.com/heroku/heroku-buildpack-pgbouncer
这样,Django应用程序就会创建与本地套接字一样多的连接,并在需要的时候创建这些连接,而PgBouncer保存到实际数据库的长寿命连接池,并且只在必要时进行代价高昂的Postgres连接创建握手。
https://stackoverflow.com/questions/57259236
复制相似问题