better HTTP connection reuse

Enable HTTP connection reuse across multiple files, when git-annex
uses http-conduit. Before, a new Manager was created each time
Utility.Url used it. Now, a single Manager gets created the first time,
so connections are reused.

Doesn't help when external programs are used for url download,
but does speed up addurl --fast, fsck --from web, etc.

Testing fsck --fast --from web with 3 files, over high-latency
satellite internet, it sped up from 19.37s to 14.96s.

This commit was supported by the NSF-funded DataLad project.
This commit is contained in:
Joey Hess 2018-04-04 15:15:12 -04:00
parent 2ec07bc29f
commit 9b98d3f630
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
12 changed files with 61 additions and 53 deletions

View file

@ -1,6 +1,6 @@
{- S3 remotes
-
- Copyright 2011-2017 Joey Hess <id@joeyh.name>
- Copyright 2011-2018 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@ -22,7 +22,7 @@ import qualified Data.ByteString as S
import qualified Data.Map as M
import Data.Char
import Network.Socket (HostName)
import Network.HTTP.Conduit (Manager, newManager)
import Network.HTTP.Conduit (Manager)
import Network.HTTP.Client (responseStatus, responseBody, RequestBody(..))
import Network.HTTP.Types
import Control.Monad.Trans.Resource
@ -51,7 +51,7 @@ import Utility.DataUnits
import Utility.FileSystemEncoding
import Annex.Content
import Annex.Url (withUrlOptions)
import Utility.Url (checkBoth, managerSettings, closeManager)
import Utility.Url (checkBoth, UrlOptions(..))
type BucketName = String
@ -295,7 +295,7 @@ checkKey r info Nothing k = case getpublicurl info of
giveup "No S3 credentials configured"
Just geturl -> do
showChecking r
withUrlOptions $ checkBoth (geturl k) (keySize k)
withUrlOptions $ liftIO . checkBoth (geturl k) (keySize k)
checkKey r info (Just h) k = do
showChecking r
checkKeyHelper info h (T.pack $ bucketObject info k)
@ -500,8 +500,8 @@ withS3HandleMaybe c gc u a = do
#if MIN_VERSION_aws(0,17,0)
Nothing
#endif
bracketIO (newManager managerSettings) closeManager $ \mgr ->
a $ Just $ S3Handle mgr awscfg s3cfg
withUrlOptions $ \ou ->
a $ Just $ S3Handle (httpManager ou) awscfg s3cfg
Nothing -> a Nothing
where
s3cfg = s3Configuration c