Coder Social home page Coder Social logo

curl-benchmark's Introduction

curl-benchmark

Simple Python script that runs curl many times, telling it to report time metrics until you press Control+C. These metrics are printed in a colored fashion and then processed to extract average time spent in each phase (DNS lookup, TCP connection, TLS handshake, TTFB...).

Standard usage

Because it's just spawning curl, you can pass arbitrary options to curl by putting them after --. Here we're using --compressed --tcp-nodelay to resemble a browser more closely:

cURL options

The -r option can be used to hide the raw metrics and only produce the report, and is useful together with -n:

Report mode

Remember that if you pass options to curl, the URL must go last.

Usage

It's a Python script without dependencies. Just run it.
You need to have Python 3 and cURL installed.
Use -h or --help to get help.

Drawbacks

cURL has lots of options, and some of them significantly affect the time metrics:

  • --compressed allows the server to send a compressed version of the asset, reducing content download time in that case.

  • Having (and using) HTTP/2 support compiled in cURL can speed up TTFB and download sometimes.

  • --false-start is a feature of TLS that allows the handshake to 'complete' in 2RTT instead of the usual 3. So it speeds the handshake by 1RTT.

  • --tcp-nodelay supresses queuing of data to be sent, and significantly speeds up the TLS handshake and sometimes the TTFB.

Ideally, if you want to resemble a browser when it comes to time metrics, you should at least use the first three, and a lot of browsers also use the fourth. The problem is that ATM --false-start is not supported unless cURL was compiled with NSS. So you'll have to account for that when interpreting the metrics.

Fixes, improvements, requests

They're welcome! There isn't much code quality yet, though, however you're free to hack it to your needs.

curl-benchmark's People

Contributors

mildsunrise avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

curl-benchmark's Issues

Issue with proxies

It's not producing any result when passing proxy using -x,

โžœ  curl-benchmark git:(master) python3 curl-benchmark.py "http://example.com"                   
              DNS      TCP        SSL  Request          Content
     Code  lookup  connect  handshake     sent   TTFB  download
      200     4.0    225.0     -229.0    229.0  226.0       0.0
      200     4.0    235.0     -239.0    239.0  235.0       1.0
      200     4.0    232.0     -236.0    236.0  233.0       0.0
      200     4.0    241.0     -245.0    245.0  241.0       1.0

     min:     4.0    225.0     -245.0    229.0  226.0       0.0
     avg:     4.0    233.2     -237.2    237.2  233.8       0.5
     med:     4.0    235.0     -236.0    239.0  235.0       1.0
     max:     4.0    241.0     -229.0    245.0  241.0       1.0
     dev:    0.0%     2.5%      -2.4%     2.4%   2.3%    100.0%
            requests: 4    samples: 4    failures: 0           

โžœ  curl-benchmark git:(master) python3 curl-benchmark.py -- -x 0.0.0.0:8001 "http://example.com"
              DNS      TCP        SSL  Request          Content
     Code  lookup  connect  handshake     sent   TTFB  download
      200     0.0      0.0        0.0      0.0  BIG         0.0
      200     0.0      0.0        0.0      0.0  BIG         0.0
      200     0.0      0.0        0.0      0.0  BIG         0.0
      200     0.0      0.0        0.0      0.0  BIG         0.0
      200     0.0      0.0        0.0      0.0  BIG         0.0

     min:     0.0      0.0        0.0      0.0  BIG         0.0
     avg:     0.0      0.0        0.0      0.0  BIG         0.0
     med:     0.0      0.0        0.0      0.0  BIG         0.0
     max:     0.0      0.0        0.0      0.0  BIG         0.0
     dev:    0.0%     0.0%       0.0%     0.0%   0.8%      0.0%
            requests: 5    samples: 5    failures: 0           

The proxies are 100% okay,

โžœ  curl-benchmark git:(master) curl ifconfig.co
103.111.XX.XXX
โžœ  curl-benchmark git:(master) curl -x 0.0.0.0:8001 ifconfig.co
185.196.XXX.XXX
โžœ  curl-benchmark git:(master) curl -x 0.0.0.0:8002 ifconfig.co
194.32.XXX.XXX
โžœ  curl-benchmark git:(master) curl -x 104.XXX.XXX.XXX:1234 ifconfig.co
209.107.XXX.XXX
โžœ  curl-benchmark git:(master) curl --version   
curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 

Prompt for a password if "--user" without password is provided

The curl --user option either takes a string like "user:password", but also allows to just pass "user".

In that case, curl offers a prompt to the user to enter a password.

This has the benefit of not storing the credentials in the shell history.

curl-benchmark currently "hangs" if no password is provided (it hides the prompt and does not continue).

It would be great if curl-benchmark would ask once for the password at the beginning and use it for all requests.

Total duration

Great tool, thank you.

What do you think of having an extra column for the total duration of a request?

I'm not sure if that would be the same of the sum of all times (dns, tcp, ssl, request, ttfb, download), but I saw in the code that curl provides a total duration already.

It would be great if that value could be printed aswell.

Status 500 does not count as failure

I got a bunch of 500 code, but it failed to get that.

โžœ  curl-benchmark git:(master) python3 curl-benchmark.py localhost:8081
              DNS      TCP        SSL  Request           Content
     Code  lookup  connect  handshake     sent    TTFB  download
      200     4.0      0.0        0.0      0.0     1.0       0.0
      200     4.0      0.0        0.0      0.0     1.0       0.0
      200     4.0      0.0        0.0      0.0     1.0       0.0
      200     4.0      0.0        0.0      0.0     1.0       0.0
      500     4.0      0.0        0.0      0.0     1.0       0.0
      200     4.0      0.0        0.0      1.0    12.0       0.0
      500     4.0      0.0        0.0      0.0     1.0       0.0
      200     4.0      0.0        0.0      1.0     2.0       0.0
      500     4.0      0.0        0.0      0.0     1.0       0.0

     min:     4.0      0.0        0.0      0.0     1.0       0.0
     avg:     4.0      0.0        0.0      0.2     2.3       0.0
     med:     4.0      0.0        0.0      0.0     1.0       0.0
     max:     4.0      0.0        0.0      1.0    12.0       0.0
     dev:    0.0%     0.0%       0.0%   187.1%  147.1%      0.0%
            requests: 9    samples: 9    failures: 0 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.