bug 528288 spdy - when coalescing get ip from nsISocket instead of dns lookup r=honzab
authorPatrick McManus <mcmanus@ducksong.com>
Fri, 02 Dec 2011 10:28:57 -0500
changeset 81187 c80e1a5653cb39d1393a769505bae7efe60c9258
parent 81186 56b778efac493e2879ec6bf52e778bb741f1cf30
child 81188 0c7ba908f2fd9ce258f3adf169f708126a9319dc
push id21564
push usermak77@bonardo.net
push dateSat, 03 Dec 2011 11:10:17 +0000
treeherdermozilla-central@a68c96c1d8e0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs528288
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 528288 spdy - when coalescing get ip from nsISocket instead of dns lookup r=honzab patch 11
netwerk/protocol/http/nsHttpConnectionMgr.cpp
netwerk/protocol/http/nsHttpConnectionMgr.h
--- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp
+++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp
@@ -42,22 +42,20 @@
 #include "nsHttpHandler.h"
 #include "nsNetCID.h"
 #include "nsCOMPtr.h"
 #include "nsNetUtil.h"
 
 #include "nsIServiceManager.h"
 
 #include "nsIObserverService.h"
-#include "nsIDNSRecord.h"
-#include "nsIDNSService.h"
-#include "nsICancelable.h"
 
 #include "nsISSLStatusProvider.h"
 #include "nsISSLStatus.h"
+#include "prnetdb.h"
 
 using namespace mozilla;
 
 // defined by the socket transport service while active
 extern PRThread *gSocketThread;
 
 static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
 
@@ -1813,37 +1811,16 @@ nsHalfOpenSocket::SetupStreams(nsISocket
 }
 
 nsresult
 nsHttpConnectionMgr::nsHalfOpenSocket::SetupPrimaryStreams()
 {
     NS_ABORT_IF_FALSE(PR_GetCurrentThread() == gSocketThread, "wrong thread");
 
     nsresult rv;
-    if (gHttpHandler->IsSpdyEnabled() &&
-        gHttpHandler->CoalesceSpdy() &&
-        mEnt->mConnInfo->UsingSSL() &&
-        !mEnt->mConnInfo->UsingHttpProxy() &&
-        !mEnt->mDidDNS) {
-
-        // Grab the DNS resolution for this host for un-sharding purposes
-        // This lookup will no doubt be coalesced by the DNS sub system as it
-        // overlaps with the SocketTransport
-        
-        nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID,
-                                                    &rv);
-        mEnt->mDidDNS = true;
-
-        if (NS_SUCCEEDED(rv)) {
-            nsCOMPtr<nsICancelable> cancelable;
-            dns->AsyncResolve(mEnt->mConnInfo->GetHost(), 0, this,
-                              NS_GetCurrentThread(),
-                              getter_AddRefs(cancelable));
-        }
-    }
 
     rv = SetupStreams(getter_AddRefs(mSocketTransport),
                       getter_AddRefs(mStreamIn),
                       getter_AddRefs(mStreamOut),
                       false);
     LOG(("nsHalfOpenSocket::SetupPrimaryStream [this=%p ent=%s rv=%x]",
          this, mEnt->mConnInfo->Host(), rv));
     if (NS_FAILED(rv)) {
@@ -1870,38 +1847,16 @@ nsHttpConnectionMgr::nsHalfOpenSocket::S
             mBackupStreamOut->AsyncWait(nsnull, 0, 0, nsnull);
         mBackupStreamOut = nsnull;
         mBackupStreamIn = nsnull;
         mBackupTransport = nsnull;
     }
     return rv;
 }
 
-
-NS_IMETHODIMP // nsIDNSListener
-nsHttpConnectionMgr::
-nsHalfOpenSocket::OnLookupComplete(nsICancelable *aRequest,
-                                   nsIDNSRecord *aRecord,
-                                   nsresult aStatus)
-{
-    NS_ABORT_IF_FALSE(PR_GetCurrentThread() == gSocketThread, "wrong thread");
-
-    if (NS_SUCCEEDED(aStatus) && mEnt) {
-        aRecord->GetNextAddrAsString(mEnt->mCoalescingKey);
-        if (mEnt->mConnInfo->GetAnonymous())
-            mEnt->mCoalescingKey.Append("~A:");
-        else
-            mEnt->mCoalescingKey.Append("~.:");
-        mEnt->mCoalescingKey.AppendInt(mEnt->mConnInfo->Port());
-
-        gHttpHandler->ConnMgr()->ProcessSpdyPendingQ(mEnt);
-    }
-    return NS_OK;
-}
-
 void
 nsHttpConnectionMgr::nsHalfOpenSocket::SetupBackupTimer()
 {
     PRUint16 timeout = gHttpHandler->GetIdleSynTimeout();
     NS_ABORT_IF_FALSE(!mSynTimer, "timer already initd");
     
     if (timeout) {
         // Setup the timer that will establish a backup socket
@@ -2063,16 +2018,52 @@ nsHalfOpenSocket::OnOutputStreamReady(ns
 
 // method for nsITransportEventSink
 NS_IMETHODIMP
 nsHttpConnectionMgr::nsHalfOpenSocket::OnTransportStatus(nsITransport *trans,
                                                          nsresult status,
                                                          PRUint64 progress,
                                                          PRUint64 progressMax)
 {
+    NS_ASSERTION(PR_GetCurrentThread() == gSocketThread, "wrong thread");
+
+    // if we are doing spdy coalescing and haven't recorded the ip address
+    // for this entry before then make the hash key if our dns lookup
+    // just completed
+
+    if (gHttpHandler->IsSpdyEnabled() &&
+        gHttpHandler->CoalesceSpdy() &&
+        mEnt && mEnt->mConnInfo && mEnt->mConnInfo->UsingSSL() &&
+        !mEnt->mConnInfo->UsingHttpProxy() &&
+        mEnt->mCoalescingKey.IsEmpty() &&
+        status == nsISocketTransport::STATUS_CONNECTED_TO) {
+
+        PRNetAddr addr;
+        nsresult rv = mSocketTransport->GetPeerAddr(&addr);
+        if (NS_SUCCEEDED(rv)) {
+            mEnt->mCoalescingKey.SetCapacity(72);
+            PR_NetAddrToString(&addr, mEnt->mCoalescingKey.BeginWriting(), 64);
+            mEnt->mCoalescingKey.SetLength(
+                strlen(mEnt->mCoalescingKey.BeginReading()));
+
+            if (mEnt->mConnInfo->GetAnonymous())
+                mEnt->mCoalescingKey.AppendLiteral("~A:");
+            else
+                mEnt->mCoalescingKey.AppendLiteral("~.:");
+            mEnt->mCoalescingKey.AppendInt(mEnt->mConnInfo->Port());
+
+            LOG(("nsHttpConnectionMgr::nsHalfOpenSocket::OnTransportStatus "
+                 "STATUS_CONNECTED_TO Established New Coalescing Key for host "
+                 "%s [%s]", mEnt->mConnInfo->Host(),
+                 mEnt->mCoalescingKey.get()));
+
+            gHttpHandler->ConnMgr()->ProcessSpdyPendingQ(mEnt);
+        }
+    }
+
     if (mTransaction)
         mTransaction->OnTransportStatus(trans, status, progress);
 
     if (trans != mSocketTransport)
         return NS_OK;
 
     switch (status) {
     case nsISocketTransport::STATUS_CONNECTING_TO:
--- a/netwerk/protocol/http/nsHttpConnectionMgr.h
+++ b/netwerk/protocol/http/nsHttpConnectionMgr.h
@@ -44,17 +44,16 @@
 #include "nsHttpTransaction.h"
 #include "nsTArray.h"
 #include "nsThreadUtils.h"
 #include "nsClassHashtable.h"
 #include "nsDataHashtable.h"
 #include "nsAutoPtr.h"
 #include "mozilla/ReentrantMonitor.h"
 #include "nsISocketTransportService.h"
-#include "nsIDNSListener.h"
 #include "nsHashSets.h"
 
 #include "nsIObserver.h"
 #include "nsITimer.h"
 #include "nsIX509Cert3.h"
 
 class nsHttpPipeline;
 
@@ -174,17 +173,16 @@ private:
     //
     struct nsConnectionEntry
     {
         nsConnectionEntry(nsHttpConnectionInfo *ci)
           : mConnInfo(ci),
             mUsingSpdy(false),
             mTestedSpdy(false),
             mSpdyRedir(false),
-            mDidDNS(false),
             mSpdyPreferred(false)
         {
             NS_ADDREF(mConnInfo);
         }
         ~nsConnectionEntry();
 
         nsHttpConnectionInfo        *mConnInfo;
         nsTArray<nsHttpTransaction*> mPendingQ;    // pending transaction queue
@@ -201,17 +199,16 @@ private:
         // mSpdyPreferred, and the others are marked mSpdyRedir. The mapping is
         // maintained in the conection manager mSpdyPreferred hash.
         //
         nsCString mCoalescingKey;
 
         bool mUsingSpdy;
         bool mTestedSpdy;
         bool mSpdyRedir;
-        bool mDidDNS;
         bool mSpdyPreferred;
         nsCOMPtr<nsIX509Cert3> mCert;
     };
 
     // nsConnectionHandle
     //
     // thin wrapper around a real connection, used to keep track of references
     // to the connection to determine when the connection may be reused.  the
@@ -233,26 +230,24 @@ private:
     };
 
     // nsHalfOpenSocket is used to hold the state of an opening TCP socket
     // while we wait for it to establish and bind it to a connection
 
     class nsHalfOpenSocket : public nsIOutputStreamCallback,
                              public nsITransportEventSink,
                              public nsIInterfaceRequestor,
-                             public nsITimerCallback,
-                             public nsIDNSListener
+                             public nsITimerCallback
     {
     public:
         NS_DECL_ISUPPORTS
         NS_DECL_NSIOUTPUTSTREAMCALLBACK
         NS_DECL_NSITRANSPORTEVENTSINK
         NS_DECL_NSIINTERFACEREQUESTOR
         NS_DECL_NSITIMERCALLBACK
-        NS_DECL_NSIDNSLISTENER
 
         nsHalfOpenSocket(nsConnectionEntry *ent,
                          nsHttpTransaction *trans);
         ~nsHalfOpenSocket();
         
         nsresult SetupStreams(nsISocketTransport **,
                               nsIAsyncInputStream **,
                               nsIAsyncOutputStream **,