When trying to reuse a backend connection, a connection hash is
calculated to match an entry with similar parameters. Previously, this
operation was skipped if the stream content wasn't based on HTTP, as it
would have been incompatible with http-reuse.
With the introduction of SPOP backends, this condition was removed, so
that it can also benefit from connection reuse. However, this means that
now hash calcul is always performed when connecting to a server, even
for TCP or log backends. This is unnecessary as these proxies cannot
perform connection reuse.
Note also that reuse mode is resetted on postparsing for incompatible
backends. This at least guarantees that no tree lookup will be performed
via be_reuse_connection(). However, connection lookup is still performed
in the session via session_get_conn() which is another unnecessary
operation.
Thus, this patch restores the condition so that reuse operations are now
entirely skipped if a backend mode is incompatible. This is implemented
via a new utility function named be_supports_conn_reuse().
This could be backported up to 3.1, as this commit could be considered
as a performance regression for tcp/log backend modes.
unsigned int gen_hash(const struct proxy* px, const char* key, unsigned long len);
+/* Returns true if connection reuse is supported by <be> backend. */
+static inline int be_supports_conn_reuse(const struct proxy *be)
+{
+ return be->mode == PR_MODE_HTTP || be->mode == PR_MODE_SPOP;
+}
+
#endif /* _HAPROXY_BACKEND_H */
/*
* conducted on <sess> session. This allows to use a connection not yet
* labelled as safe under http-reuse safe policy.
*
+ * This function should only be called for backends which supports connection
+ * reuse. It may be necessary to extend be_supports_conn_reuse() when
+ * implementing a new proxy mode.
+ *
* Returns SF_ERR_NONE if a connection has been reused. The connection instance
* can be retrieve via <sc> stconn. SF_ERR_RESOURCE is returned if no matching
* connection found. SF_ERR_INTERNAL is used on internal error.
if (err != SRV_STATUS_OK)
return SF_ERR_INTERNAL;
+ if (!be_supports_conn_reuse(s->be))
+ goto skip_reuse;
+
/* disable reuse if websocket stream and the protocol to use is not the
* same as the main protocol of the server.
*/
}
}
+ skip_reuse:
/* no reuse or failed to reuse the connection above, pick a new one */
if (!srv_conn) {
unsigned int total_conns;