Skip to content

Commit

Permalink
Fix proxy slowdown with intercepted HTTPS requests (#6705)
Browse files Browse the repository at this point in the history
* use 2x chrome total time as benchmark

* set TLS minVersion to v1 only if connection already failed with TLS version mismatch

* correct percentile function

* assert at least 1000 requests were made

* setNoDelay on HTTPS-over-HTTPS requests

* allow for tests with HTTPS upstreams to be slightly slower

* try 3x

* add note for add'l multiplier on httpsUpstreamProxy
  • Loading branch information
flotwig committed Mar 11, 2020
1 parent ec027e9 commit 53be237
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
5 changes: 1 addition & 4 deletions packages/network/lib/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,6 @@ class HttpsAgent extends https.Agent {
}

createConnection (options: HttpsRequestOptions, cb: http.SocketCallback) {
// allow requests to use older TLS versions
// https://github.com/cypress-io/cypress/issues/5446
options.minVersion = 'TLSv1'

if (process.env.HTTPS_PROXY) {
const proxy = getProxyForUrl(options.href)

Expand Down Expand Up @@ -353,6 +349,7 @@ class HttpsAgent extends https.Agent {

const connectReq = buildConnectReqHead(hostname, port, proxy)

proxySocket.setNoDelay(true)
proxySocket.write(connectReq)
})
}
Expand Down
11 changes: 10 additions & 1 deletion packages/server/lib/request.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SERIALIZABLE_COOKIE_PROPS = ['name', 'value', 'domain', 'expiry', 'path', 'secur
NETWORK_ERRORS = "ECONNREFUSED ECONNRESET EPIPE EHOSTUNREACH EAI_AGAIN ENOTFOUND".split(" ")
VERBOSE_REQUEST_OPTS = "followRedirect strictSSL".split(" ")
HTTP_CLIENT_REQUEST_EVENTS = "abort connect continue information socket timeout upgrade".split(" ")
TLS_VERSION_ERROR_RE = /TLSV1_ALERT_PROTOCOL_VERSION|UNSUPPORTED_PROTOCOL/

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"

Expand Down Expand Up @@ -81,7 +82,15 @@ maybeRetryOnNetworkFailure = (err, options = {}) ->

debug("received an error making http request %o", merge(opts, { err }))

if not isRetriableError(err, retryOnNetworkFailure)
isTlsVersionError = TLS_VERSION_ERROR_RE.test(err.message)

if isTlsVersionError
## because doing every connection via TLSv1 can lead to slowdowns, we set it only on failure
## https://github.com/cypress-io/cypress/pull/6705
debug('detected TLS version error, setting min version to TLSv1')
opts.minVersion = 'TLSv1'

if not isTlsVersionError and not isRetriableError(err, retryOnNetworkFailure)
return onElse()

## else see if we have more delays left...
Expand Down
19 changes: 14 additions & 5 deletions packages/server/test/performance/proxy_performance_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const average = (arr) => {
}

const percentile = (sortedArr, p) => {
const i = Math.floor(p / 100 * sortedArr.length - 1)
const i = Math.floor(p / 100 * (sortedArr.length - 1))

return Math.round(sortedArr[i])
}
Expand Down Expand Up @@ -167,6 +167,8 @@ const getResultsFromHar = (har) => {

results['Min'] = mins.total

expect(timings.total.length).to.be.at.least(1000)

;[1, 5, 25, 50, 75, 95, 99, 99.7].forEach((p) => {
results[`${p}% <=`] = percentile(timings.total, p)
})
Expand Down Expand Up @@ -356,10 +358,9 @@ describe('Proxy Performance', function () {
})

URLS_UNDER_TEST.map((urlUnderTest) => {
const testCases = _.cloneDeep(TEST_CASES)

describe(urlUnderTest, function () {
let baseline
const testCases = _.cloneDeep(TEST_CASES)

before(function () {
// run baseline test
Expand All @@ -373,12 +374,20 @@ describe('Proxy Performance', function () {

// slice(1) since first test is used as baseline above
testCases.slice(1).map((testCase) => {
it(`${testCase.name} loads 1000 images, with 75% loading no more than 2x as slow as the slowest baseline request`, function () {
let multiplier = 3

if (testCase.httpsUpstreamProxy) {
// there is extra slowdown when the HTTPS upstream is used, so slightly increase the multiplier
// maybe from higher CPU utilization with debugging-proxy and HTTPS
multiplier *= 1.5
}

it(`${testCase.name} loads 1000 images less than ${multiplier}x as slowly as Chrome`, function () {
debug('Current test: ', testCase.name)

return runBrowserTest(urlUnderTest, testCase)
.then((results) => {
expect(results['75% <=']).to.be.lessThan(baseline['Max'] * 2)
expect(results['Total']).to.be.lessThan(multiplier * baseline['Total'])
})
})
})
Expand Down

4 comments on commit 53be237

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 53be237 Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.0/linux-x64/circle-develop-53be237d11a415fd799d4e3380b67df3baeb7503-279086/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.0/circle-develop-53be237d11a415fd799d4e3380b67df3baeb7503-279067/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 53be237 Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.0/darwin-x64/circle-develop-53be237d11a415fd799d4e3380b67df3baeb7503-279091/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.0/circle-develop-53be237d11a415fd799d4e3380b67df3baeb7503-279089/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 53be237 Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.0/win32-ia32/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.0/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.2.0/win32-ia32/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.0/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.0/win32-ia32/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.0/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.0/win32-ia32/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.2.0/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 53be237 Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.0/win32-x64/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.0/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.2.0/win32-x64/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.0/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.0/win32-x64/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.0/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.0/win32-x64/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.2.0/appveyor-develop-53be237d11a415fd799d4e3380b67df3baeb7503-31408553/cypress.tgz

Please sign in to comment.