reportportal / agent-ruby

Agent - Ruby Cucumber and RSpec formatters
Apache License 2.0
15 stars 43 forks source link

Use persistent client for HTTP #64

Closed abotalov closed 5 years ago

abotalov commented 5 years ago

Persistent connections (keep-alive) significantly improve request-response cycle speed if the connection between hosts is not very fast.

On the other hand, if the connection is very good, persistent connections may reduce speed a bit

Below are details of the benchmark I made to check the performance improvement of persistent connections for our case.

I introduced a config option so it would be easy to check it in other scenarios too.

Benchmark 1 - remote endpoint

YAML file:

uuid: my-uuid
endpoint: https://web.demo.reportportal.io
launch: example_launch_name
project: abotalov_personal
formatter_modes: [skip_reporting_hierarchy, use_same_thread_for_reporting]
disable_ssl_verification: false

Command (ran from my laptop, currently located in Spain):

for run in {1..5}; do bundle exec cucumber tests/features/ -r tests/features/ -f ReportPortal::Cucumber::Formatter; done

Execution time using persistent-benchmark branch:

86.00392306
85.71174958
84.6365683
100.3799417
107.1182389

Average is 92 seconds.

Execution time using non-persistent-benchmark branch (the only change from persistent-benchmark branch is usage of non-persistent connections):

305.279757
294.4467745
305.1522905
302.4168719
307.5853562

Average is 302 seconds. Time on master branch is similar, by the way.

So persistent connections improve speed by ~3 times under conditions of this benchmark.

Benchmark 2 - localhost endpoint

I ran the same command 20 times against Report Portal server on my laptop.

Average using persistent connection - 12.8 seconds. Average using non-persistent connection - 11.5 seconds.

So persistent connections were 10% slower for some reason.