Skip to content

Commit 0c3530b

Browse files
committed
Reduce TLS handshake contention on SSLCertContext
Replace std::mutex with ts::bravo::shared_mutex on SSLCertContext to allow true reader concurrency for getCtx() on the TLS handshake hot path. setCtx() (config reload only) takes an exclusive lock. Memory trade-off: BRAVO uses 256 cache-line-aligned reader slots (~16 KB per mutex) vs ~40 bytes for std::mutex or ~56 bytes for std::shared_mutex on Linux. For 256 certificates this is ~4 MB (vs 10 KB / 14 KB), a modest cost relative to the SSL_CTX objects themselves but worth noting for deployments with many certs.
1 parent 8e6b509 commit 0c3530b

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/iocore/net/P_SSLCertLookup.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
#include "iocore/eventsystem/ConfigProcessor.h"
2727
#include "iocore/net/SSLTypes.h"
2828
#include "records/RecCore.h"
29+
#include "tsutil/Bravo.h"
2930

3031
#include <set>
3132
#include <openssl/ssl.h>
32-
#include <mutex>
3333
#include <unordered_map>
3434
#include <utility>
3535

@@ -94,8 +94,8 @@ using shared_ssl_ticket_key_block = std::shared_ptr<ssl_ticket_key_block>;
9494
*/
9595
struct SSLCertContext {
9696
private:
97-
mutable std::mutex ctx_mutex;
98-
shared_SSL_CTX ctx;
97+
mutable ts::bravo::shared_mutex ctx_mutex;
98+
shared_SSL_CTX ctx;
9999

100100
public:
101101
SSLCertContext() : ctx_mutex(), ctx(nullptr), opt(SSLCertContextOption::OPT_NONE), userconfig(nullptr), keyblock(nullptr) {}

src/iocore/net/SSLCertLookup.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ SSLCertContext::SSLCertContext(SSLCertContext const &other)
237237
userconfig = other.userconfig;
238238
keyblock = other.keyblock;
239239
ctx_type = other.ctx_type;
240-
std::lock_guard<std::mutex> lock(other.ctx_mutex);
240+
ts::bravo::shared_lock lock(other.ctx_mutex);
241241
ctx = other.ctx;
242242
}
243243

@@ -249,7 +249,7 @@ SSLCertContext::operator=(SSLCertContext const &other)
249249
this->userconfig = other.userconfig;
250250
this->keyblock = other.keyblock;
251251
this->ctx_type = other.ctx_type;
252-
std::lock_guard<std::mutex> lock(other.ctx_mutex);
252+
ts::bravo::shared_lock lock(other.ctx_mutex);
253253
this->ctx = other.ctx;
254254
}
255255
return *this;
@@ -258,14 +258,14 @@ SSLCertContext::operator=(SSLCertContext const &other)
258258
shared_SSL_CTX
259259
SSLCertContext::getCtx()
260260
{
261-
std::lock_guard<std::mutex> lock(ctx_mutex);
261+
ts::bravo::shared_lock lock(ctx_mutex);
262262
return ctx;
263263
}
264264

265265
void
266266
SSLCertContext::setCtx(shared_SSL_CTX sc)
267267
{
268-
std::lock_guard<std::mutex> lock(ctx_mutex);
268+
std::lock_guard lock(ctx_mutex);
269269
ctx = std::move(sc);
270270
}
271271

0 commit comments

Comments
 (0)