summary refs log tree commit diff
path: root/synapse/http
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2018-01-20 00:55:44 +0000
committerRichard van der Hoff <richard@matrix.org>2018-01-20 00:55:44 +0000
commit2c8526cac795fa2aa795e1a1aaae2ffb2558824d (patch)
treeed873aa25ccdb06bee132e781d4d1e7cf996ce86 /synapse/http
parentFix bugs in block metrics (diff)
downloadsynapse-2c8526cac795fa2aa795e1a1aaae2ffb2558824d.tar.xz
Use a connection pool for the SimpleHttpClient
In particular I hope this will help the pusher, which makes many requests to
sygnal, and is currently negotiating SSL for each one.
Diffstat (limited to 'synapse/http')
-rw-r--r--synapse/http/client.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py
index 4abb479ae3..930d713013 100644
--- a/synapse/http/client.py
+++ b/synapse/http/client.py
@@ -30,6 +30,7 @@ from twisted.internet.endpoints import HostnameEndpoint, wrapClientTLS
 from twisted.web.client import (
     BrowserLikeRedirectAgent, ContentDecoderAgent, GzipDecoder, Agent,
     readBody, PartialDownloadError,
+    HTTPConnectionPool,
 )
 from twisted.web.client import FileBodyProducer as TwistedFileBodyProducer
 from twisted.web.http import PotentialDataLoss
@@ -64,13 +65,19 @@ class SimpleHttpClient(object):
     """
     def __init__(self, hs):
         self.hs = hs
+
+        pool = HTTPConnectionPool(reactor)
+        pool.maxPersistentPerHost = 5
+        pool.cachedConnectionTimeout = 2 * 60
+
         # The default context factory in Twisted 14.0.0 (which we require) is
         # BrowserLikePolicyForHTTPS which will do regular cert validation
         # 'like a browser'
         self.agent = Agent(
             reactor,
             connectTimeout=15,
-            contextFactory=hs.get_http_client_context_factory()
+            contextFactory=hs.get_http_client_context_factory(),
+            pool=pool,
         )
         self.user_agent = hs.version_string
         self.clock = hs.get_clock()