Recently I’ve been looking quite hard at speeding up my web applications, so I’ve been doing things like optimising my code, creating static HTML files instead of generating pages every request etc., and it’s all gone quite well.
I can now get a page in ~50ms after all of the logic and database access in my code has finish executing.
My problem is though, that if I leave the page open for some time, for example, up to a minute (not sure of an exact time for this), and then make a request to the same page again, it suddenly takes a whole second longer to respond. This is based on the TTFB metric in the Chrome network tab for the document itself.
I know that my code is ok, because even when the response takes over a second the timings in my code report ~50ms or less every single time.
So I was wondering how I would go about debugging this.
For context, the server I’m running my code in is Hapi for Node.js, and Caddy just does a transparent
proxy to it.
This is the relevant part of my Caddyfile:
proxy / localhost:3001 {
transparent
}
As far as I can see this could either be Caddy or Hapi, so does anyone have any suggestions as to how I would go about ruling out Caddy as the problem?
I’m having trouble thinking of what to look at, but it always happens after I’ve left the page for a short time. If I keep on refreshing the page the timings never go above a second and stay within the expected response time.
If it helps, I usually build Caddy from source, so if there’s anywhere in the code that would make sense to add some timings then I’m ok with doing that too.