Skip to content

Commit c71ef29

Browse files
committed
OPTIM: backend: reduce contention when checking MUX init with ALPN
In connect_server(), MUX initialization must be delayed if ALPN negotiation is configured, unless ALPN can already be retrieved via the server cache. A readlock is used to consult the server cache. Prior to this patch, it was always taken even if no ALPN is configured. The lock was thus used for every new backend connection instantiation. Rewrite the check so that now the lock is only used if ALPN is configured. Thus, no lock access is done if SSL is not used or if ALPN is not defined. In practice, there will be no performance gain, as the read lock should never block if ALPN is not configured. However, the code is cleaner as it better reflect that only access to server nego_alpn requires the path_params lock protection.
1 parent 55e9c67 commit c71ef29

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/backend.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,12 +2070,13 @@ int connect_server(struct stream *s)
20702070
* to ensure consistency accross the whole stack, in
20712071
* particular for QUIC between quic-conn and mux layer.
20722072
*/
2073-
HA_RWLOCK_RDLOCK(SERVER_LOCK, &srv->path_params.param_lock);
20742073
if (IS_HTX_STRM(s) && srv->use_ssl &&
2075-
(srv->ssl_ctx.alpn_str || srv->ssl_ctx.npn_str) &&
2076-
srv->path_params.nego_alpn[0] == 0)
2077-
may_start_mux_now = 0;
2078-
HA_RWLOCK_RDUNLOCK(SERVER_LOCK, &srv->path_params.param_lock);
2074+
(srv->ssl_ctx.alpn_str || srv->ssl_ctx.npn_str)) {
2075+
HA_RWLOCK_RDLOCK(SERVER_LOCK, &srv->path_params.param_lock);
2076+
if (srv->path_params.nego_alpn[0] == 0)
2077+
may_start_mux_now = 0;
2078+
HA_RWLOCK_RDUNLOCK(SERVER_LOCK, &srv->path_params.param_lock);
2079+
}
20792080
#endif /* TLSEXT_TYPE_application_layer_protocol_negotiation */
20802081

20812082
#endif /* USE_OPENSSL */

0 commit comments

Comments
 (0)