Convert TransportInfo SSL fields to shared_ptrs
authorViswanath Sivakumar <viswanath@fb.com>
Wed, 28 Jan 2015 20:08:36 +0000 (12:08 -0800)
committerwoo <woo@fb.com>
Mon, 2 Feb 2015 21:14:08 +0000 (13:14 -0800)
Summary:
We do a lot of copying of TransportInfo in proxygen, and in most cases
the SSL structs don't change after connection establishment. We could
cut down on memory usage by sharing these huge strings. This is
especially true with SPDY where all streams belonging to a session could
share these fields.

Facebook:

Test Plan: Unit tests, will canary

Reviewed By: afrind@fb.com

Subscribers: fugalh, bmatheny, ssl-diffs@, folly-diffs@, jsedgwick, woo

FB internal diff: D1807557

Tasks: 5343753

Signature: t1:1807557:1422472932:53038345fca620632097586fb9e410bca8fe748d

folly/wangle/acceptor/Acceptor.cpp
folly/wangle/acceptor/TransportInfo.h

index 2d31e7196a2e5ac04ef506996311ba19047b8e23..8e616c236ddc73343ef8ec306b50f4f8f1b371c7 100644 (file)
@@ -118,13 +118,17 @@ class AcceptorHandshakeHelper :
     tinfo.sslVersion = sock->getSSLVersion();
     tinfo.sslCertSize = sock->getSSLCertSize();
     tinfo.sslResume = SSLUtil::getResumeState(sock);
-    sock->getSSLClientCiphers(tinfo.sslClientCiphers);
-    sock->getSSLServerCiphers(tinfo.sslServerCiphers);
-    tinfo.sslClientComprMethods = sock->getSSLClientComprMethods();
-    tinfo.sslClientExts = sock->getSSLClientExts();
-    tinfo.sslNextProtocol.assign(
-        reinterpret_cast<const char*>(nextProto),
-        nextProtoLength);
+    tinfo.sslClientCiphers = std::make_shared<std::string>();
+    sock->getSSLClientCiphers(*tinfo.sslClientCiphers);
+    tinfo.sslServerCiphers = std::make_shared<std::string>();
+    sock->getSSLServerCiphers(*tinfo.sslServerCiphers);
+    tinfo.sslClientComprMethods =
+        std::make_shared<std::string>(sock->getSSLClientComprMethods());
+    tinfo.sslClientExts =
+        std::make_shared<std::string>(sock->getSSLClientExts());
+    tinfo.sslNextProtocol = std::make_shared<std::string>();
+    tinfo.sslNextProtocol->assign(reinterpret_cast<const char*>(nextProto),
+                                  nextProtoLength);
 
     acceptor_->updateSSLStats(sock, tinfo.sslSetupTime, SSLErrorEnum::NO_ERROR);
     acceptor_->downstreamConnectionManager_->removeConnection(this);
index 831e251735e12ad15a9ded7014b6ad6f7c703f24..c02bac42fbbc5c22f1c062e459641af6507ee4b0 100644 (file)
@@ -86,37 +86,37 @@ struct TransportInfo {
   /*
    * list of ciphers sent by the client
    */
-  std::string sslClientCiphers{};
+  std::shared_ptr<std::string> sslClientCiphers{nullptr};
 
   /*
    * list of compression methods sent by the client
    */
-  std::string sslClientComprMethods{};
+  std::shared_ptr<std::string> sslClientComprMethods{nullptr};
 
   /*
    * list of TLS extensions sent by the client
    */
-  std::string sslClientExts{};
+  std::shared_ptr<std::string> sslClientExts{nullptr};
 
   /*
    * hash of all the SSL parameters sent by the client
    */
-  std::string sslSignature{};
+  std::shared_ptr<std::string> sslSignature{nullptr};
 
   /*
    * list of ciphers supported by the server
    */
-  std::string sslServerCiphers{};
+  std::shared_ptr<std::string> sslServerCiphers{nullptr};
 
   /*
    * guessed "(os) (browser)" based on SSL Signature
    */
-  std::string guessedUserAgent{};
+  std::shared_ptr<std::string> guessedUserAgent{nullptr};
 
   /**
    * The result of SSL NPN negotiation.
    */
-  std::string sslNextProtocol{};
+  std::shared_ptr<std::string> sslNextProtocol{nullptr};
 
   /*
    * total number of bytes sent over the connection