Skip to content

Commit

Permalink
Avoid duplicate URL parsing for async connections (#958)
Browse files Browse the repository at this point in the history
With this commit we provide a URL object when issuing a request instead
of a string representation to avoid expensive string parsing in aiohttp.
In our tests this has reduced the client side overhead by about one
millisecond which is important when benchmarking queries which finish
within single-digit milliseconds.

Relates #944
  • Loading branch information
danielmitterdorfer authored Apr 14, 2020
1 parent 7735f08 commit 40c1dca
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions esrally/async_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import aiohttp
from aiohttp.client_exceptions import ServerFingerprintMismatch
import async_timeout
import yarl

from elasticsearch.exceptions import ConnectionError, ConnectionTimeout, ImproperlyConfigured, SSLError
from elasticsearch.connection import Connection
Expand Down Expand Up @@ -97,11 +98,7 @@ def __init__(self, host='localhost', port=9200, http_auth=None,
trace_configs=trace_configs,
response_class=RawClientResponse
)

self.base_url = 'http%s://%s:%d%s' % (
's' if use_ssl else '',
host, port, self.url_prefix
)
self.scheme = "https" if use_ssl else "http"

@asyncio.coroutine
def close(self):
Expand All @@ -111,8 +108,16 @@ def close(self):
def perform_request(self, method, url, params=None, body=None, timeout=None, ignore=(), headers=None):
url_path = url
if params:
url_path = '%s?%s' % (url, urlencode(params or {}))
url = self.base_url + url_path
query_string = urlencode(params)
else:
query_string = ""
# Provide correct URL object to avoid string parsing in low-level code
url = yarl.URL.build(scheme=self.scheme,
host=self.hostname,
port=self.port,
path=url,
query_string=query_string,
encoded=True)

start = self.loop.time()
response = None
Expand Down

0 comments on commit 40c1dca

Please sign in to comment.