I am hosting a Wordpress instance on GCP Compute Engine (using the Marketplace image). It works great when I directly access the instance IP, and the latency is around 20 ms.
However, in order to make the site secure, I am using a GCP HTTP load balancer in front of the instance. I have pointed my domain to the load balancer.
When I access the Wordpress through the load balancer (either HTTP or HTTPS), I get a few queries that are very good latency times (around 17 ms), but then every 4 or 5 queries, there's a request that takes about 5 seconds. When I access the instance directly, this does not happen.
I enabled the load balancer log, and I observed that the instance is responding slowly every few requests. I tried to set the KeepAlive Apache2 parameter of the instance to 300, but it doesn't make any difference.
What might be the root cause of this? (I am not sure whether it's Wordpress, or the instance, or the load balancer).