MINOR: backend: improve perf with tcp proxies skipping idle conns
Skip the hash connection calcul when reuse must not be used in
connect_server() : this is the case for TCP proxies. This should result
in slightly better performance when using this use-case.
diff --git a/src/backend.c b/src/backend.c
index 6d77864..ee55e45 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -1269,48 +1269,55 @@
* it can be NULL for dispatch mode or transparent backend */
srv = objt_server(s->target);
- /* first, set unique connection parameters and then calculate hash */
- memset(&hash_params, 0, sizeof(hash_params));
+ if (!(s->flags & SF_ADDR_SET)) {
+ err = alloc_dst_address(&s->target_addr, srv, s);
+ if (err != SRV_STATUS_OK)
+ return SF_ERR_INTERNAL;
- /* 1. target */
- hash_params.target = s->target;
+ s->flags |= SF_ADDR_SET;
+ }
+
+ err = alloc_bind_address(&bind_addr, srv, s);
+ if (err != SRV_STATUS_OK)
+ return SF_ERR_INTERNAL;
#ifdef USE_OPENSSL
- /* 2. sni */
if (srv && srv->ssl_ctx.sni) {
sni_smp = sample_fetch_as_type(s->be, s->sess, s,
SMP_OPT_DIR_REQ | SMP_OPT_FINAL,
srv->ssl_ctx.sni, SMP_T_STR);
+ }
+#endif
- /* only test if the sample is not null as smp_make_safe (called
- * before ssl_sock_set_servername) can only fails if this is
- * not the case
- */
- if (sni_smp) {
- hash_params.sni_prehash =
- conn_hash_prehash(sni_smp->data.u.str.area,
- sni_smp->data.u.str.data);
- }
+ /* do not reuse if mode is not http */
+ if (!IS_HTX_STRM(s)) {
+ DBG_TRACE_STATE("skip idle connections reuse: no htx", STRM_EV_STRM_PROC|STRM_EV_SI_ST, s);
+ goto skip_reuse;
}
-#endif /* USE_OPENSSL */
- /* 3. destination address */
- if (!(s->flags & SF_ADDR_SET)) {
- err = alloc_dst_address(&s->target_addr, srv, s);
- if (err != SRV_STATUS_OK)
- return SF_ERR_INTERNAL;
+ /* first, set unique connection parameters and then calculate hash */
+ memset(&hash_params, 0, sizeof(hash_params));
- s->flags |= SF_ADDR_SET;
+ /* 1. target */
+ hash_params.target = s->target;
+
+#ifdef USE_OPENSSL
+ /* 2. sni
+ * only test if the sample is not null as smp_make_safe (called before
+ * ssl_sock_set_servername) can only fails if this is not the case
+ */
+ if (sni_smp) {
+ hash_params.sni_prehash =
+ conn_hash_prehash(sni_smp->data.u.str.area,
+ sni_smp->data.u.str.data);
}
+#endif /* USE_OPENSSL */
+ /* 3. destination address */
if (srv && (!is_addr(&srv->addr) || srv->flags & SRV_F_MAPPORTS))
hash_params.dst_addr = s->target_addr;
/* 4. source address */
- err = alloc_bind_address(&bind_addr, srv, s);
- if (err != SRV_STATUS_OK)
- return SF_ERR_INTERNAL;
-
hash_params.src_addr = bind_addr;
/* 5. proxy protocol */
@@ -1324,12 +1331,6 @@
hash = conn_calculate_hash(&hash_params);
- /* do not reuse if mode is not http */
- if (!IS_HTX_STRM(s)) {
- DBG_TRACE_STATE("skip idle connections reuse: no htx", STRM_EV_STRM_PROC|STRM_EV_SI_ST, s);
- goto skip_reuse;
- }
-
/* first, search for a matching connection in the session's idle conns */
srv_conn = session_get_conn(s->sess, s->target, hash);
if (srv_conn) {