我正在开发一个SPA + SSR(通用应用程序),使用Django作为后端,使用ReactJS作为前端,与仅具有相同堆栈并将其部署在Heroku上的SPA相比,具有更好的SEO和Page Speed结果。由于React上的SSR需要一个Node服务器,因此我遵循this guide on Heroku for running Django and Node together的警告:
“此解决方案面临着一系列挑战。与Django或节点dyno相比,Web dynos现在面临更大的资源争用。dyno上的所有进程共享内存,CPU和单个文件系统,因此选择您的测功机类型要小心。“
一段时间以来,我的日志中一直出现错误R14(超出内存配额)和错误R10(启动超时):
2018-09-27T07:35:43.272457+00:00 heroku[web.1]: source=web.1 dyno=heroku.110010347.d0013afc-887b-4913-b983-15871a5c4200 sample#memory_total=323.27MB sample#memory_rss=314.05MB sample#memory_cache=9.22MB sample#memory_swap=0.00MB sample#memory_pgpgin=102968pages sample#memory_pgpgout=20212pages sample#memory_quota=512.00MB
2018-09-27T07:36:04.717690+00:00 heroku[web.1]: source=web.1 dyno=heroku.110010347.d0013afc-887b-4913-b983-15871a5c4200 sample#load_avg_1m=3.10
2018-09-27T07:36:04.717851+00:00 heroku[web.1]: source=web.1 dyno=heroku.110010347.d0013afc-887b-4913-b983-15871a5c4200 sample#memory_total=710.81MB sample#memory_rss=488.09MB sample#memory_cache=0.03MB sample#memory_swap=222.70MB sample#memory_pgpgin=231609pages sample#memory_pgpgout=106651pages sample#memory_quota=512.00MB
2018-09-27T07:36:04.718474+00:00 heroku[web.1]: Process running mem=710M(138.8%)
我本来要放弃的,但是突然之间有了一点希望,因为重新启动dyno使其工作于以下结果:
2018-09-27T07:40:21.262437+00:00 heroku[web.1]: State changed from starting to up
2018-09-27T07:40:21.164398+00:00 app[web.1]: started
2018-09-27T07:41:03.716638+00:00 heroku[web.1]: source=web.1 dyno=heroku.110010347.352f824e-c3c5-4527-a723-0faa0f874444 sample#load_avg_1m=0.46
2018-09-27T07:41:03.716756+00:00 heroku[web.1]: source=web.1 dyno=heroku.110010347.352f824e-c3c5-4527-a723-0faa0f874444 sample#memory_total=109.86MB sample#memory_rss=28.20MB sample#memory_cache=9.07MB sample#memory_swap=72.59MB sample#memory_pgpgin=434422pages sample#memory_pgpgout=424881pages sample#memory_quota=512.00MB
2018-09-27T07:41:25.259627+00:00 heroku[web.1]: source=web.1 dyno=heroku.110010347.352f824e-c3c5-4527-a723-0faa0f874444 sample#load_avg_1m=0.32
2018-09-27T07:41:25.259711+00:00 heroku[web.1]: source=web.1 dyno=heroku.110010347.352f824e-c3c5-4527-a723-0faa0f874444 sample#memory_total=109.86MB sample#memory_rss=28.20MB sample#memory_cache=9.07MB sample#memory_swap=72.59MB sample#memory_pgpgin=434422pages sample#memory_pgpgout=424881pages sample#memory_quota=512.00MB
我的问题是,在Heroku上使用Django + Node是否真的导致512MB RAM /内存使用?此外,是否有解决此问题的方法/解决方案,而无需升级到专业Dyno类型?我正在经营一家小型企业,并且在编程方面自学成才。 (到目前为止,这要归功于SO中的好心人以及发布教程等的人。)