In the past few months, we have observed 2400~3000 concurrent sessions from CloudFlare on our origin server (HaProxy).
Now, we have created this page rule (anonymized domain):
https://domain.com/stories/*?*cf=2* Cache Level: Cache Everything, Origin Cache Control: On
When we enable this rule, the amount of connections from CloudFlare to our origin server ramps up from ~2500 to over 7000 in less than two minutes. When we disable this rule, the amount of connections goes back to ~2500. Multiple DevOps have tested this multiple times to make sure this specific rule is causing this surge in connections.
As far as we know, the rule is working correctly, as looking at the CloudFlare dashboard’s cache statistics shows that about 30% of the requests to /stories/* are served by CloudFlare without hitting the origin server. Theoretically, we would expect the amount of connections to go down, not up.
We did run some tests with
Connection: close response header from our web server, this makes the amount of connections drop from ~7000 to about 50. However, this also increases response times by 100~150ms for our customers, as CloudFlare has to establish a new connection for every request.
This test seems to indicate that this behavior is related to Keep-Alive connections. However, we would like to better understand the reasoning behind this raise in connections when applying this rule. We would like to make better use of the cache, but we fear it may end up overloading our origin server if the amount of connections raise as we add new rules and cached routes.
Is there a specific reason for this behavior so we can better plan ahead?
Is this expected behavior from CloudFlare to keep so many alive connections due to this rule?
Is there any setup recommendations for our end?