So the unicorn process is what’s responsible for rendering the page and handing it over to nginx. After 30 seconds, nginx gives up, but the unicorn process does not know that, so it continues rendering the page.
The question is: why does unicorn take so long on rendering certain topics?
I think your RAM is fine.
You could try to use the mini-profiler to see what is going on. Here’s how to do that (it’s in the context of an unrelated problem).
You can check on Sidekiq by going to /sidekiq
as an admin.