Discourse site with very large database gives error 502 frequently

my swap is not even getting filled. 1 mb of swap is getting used.