HUB
Sign inSign up
fortio.fcurl logo

fortio/fortio.fcurl

By fortio

•Updated almost 4 years ago

Fortio curl replacement debugging http client

Image
0

5.4K

fortio/fortio.fcurl repository overview

⁠Fortio

Awesome Go CII Best Practices Go Report Card GoDoc codecov CircleCI Docker Pulls

Fortio (Φορτίο) started as, and is, Istio⁠'s load testing tool and later (2018) graduated to be its own project.

Fortio is also used by, among others, Meshery⁠.

Fortio runs at a specified query per second (qps) and records an histogram of execution time and calculates percentiles (e.g. p99 ie the response time such as 99% of the requests take less than that number (in seconds, SI unit)). It can run for a set duration, for a fixed number of calls, or until interrupted (at a constant target QPS, or max speed/load per connection/thread).

The name fortio comes from greek φορτίο⁠ which means load/burden.

Fortio is a fast, small (4Mb docker image, minimal dependencies), reusable, embeddable go library as well as a command line tool and server process, the server includes a simple web UI and REST API to trigger run and see graphical representation of the results (both a single latency graph and a multiple results comparative min, max, avg, qps and percentiles graphs).

Fortio also includes a set of server side features (similar to httpbin) to help debugging and testing: request echo back including headers, adding latency or error codes with a probability distribution, tcp echoing, tcp proxying, http fan out/scatter and gather proxy server, GRPC echo/health in addition to http, etc...

Fortio is quite mature and very stable with no known major bugs (lots of possible improvements if you want to contribute though!), and when bugs are found they are fixed quickly, so after 1 year of development and 42 incremental releases, we reached 1.0 in June 2018.

Fortio components can be used a library even for unrelated projects, for instance the stats, or fhttp utilities both client and server. A recent addition is the new jrpc JSON Remote Procedure Calls library package (docs⁠).

We also have moved some of the library to their own toplevel package, like:

If you want to connect to fortio using https and fortio to provide real TLS certificates, or to multiplex grpc and regular http behind a single port, check out Fortio Proxy⁠.

If you want fortio to generate detailed Open Telemetry traces use Fortiotel⁠.

⁠Installation

We publish a multi architecture docker image (linux/amd64, linux/arm64, linux/ppc64le, linux/s390x) fortio/fortio.

For instance:

docker run -p 8080:8080 -p 8079:8079 fortio/fortio server & # For the server
docker run fortio/fortio load http://www.google.com/ # For a test run

You can install from source:

  1. Install go⁠ (golang 1.18 or later)
  2. go install fortio.org/fortio@latest
  3. you can now run fortio (from your gopath bin/ directory, usually ~/go/bin)

The releases⁠ page has binaries for many OS/architecture combinations (see assets):

curl -L https://github.com/fortio/fortio/releases/download/v1.41.0/fortio-linux_amd64-1.41.0.tgz \
 | sudo tar -C / -xvzpf -
# or the debian package
wget https://github.com/fortio/fortio/releases/download/v1.41.0/fortio_1.41.0_amd64.deb
dpkg -i fortio_1.41.0_amd64.deb
# or the rpm
rpm -i https://github.com/fortio/fortio/releases/download/v1.41.0/fortio-1.41.0-1.x86_64.rpm
# and more, see assets in release page

On a MacOS you can also install Fortio using Homebrew⁠:

brew install fortio

On Windows, download https://github.com/fortio/fortio/releases/download/v1.41.0/fortio_win_1.41.0.zip⁠ and extract fortio.exe to any location, then using the Windows Command Prompt:

fortio.exe server

(at the prompt, allow the windows firewall to let connections in)

Once fortio server is running, you can visit its web UI at http://localhost:8080/fortio/⁠

You can get a preview of the reporting/graphing UI at https://demo.fortio.org⁠

⁠Command line arguments

Fortio can be an http or grpc load generator, gathering statistics using the load subcommand, or start simple http and grpc ping servers, as well as a basic web UI, result graphing, tcp/udp echo, proxies, https redirector, with the server command or issue grpc ping messages using the grpcping command. It can also fetch a single URL's for debugging when using the curl command (or the -curl flag to the load command). Likewise you can establish a single TCP (or unix domain or UDP (use udp:// prefix)) connection using the nc command (like the standalone netcat package). You can run just the redirector with redirect or just the tcp echo with tcp-echo. If you saved JSON results (using the web UI or directly from the command line), you can browse and graph those results using the report command. The version command will print version and build information, fortio version -s just the version. Lastly, you can learn which flags are available using help command.

Most important flags for http load generation:

FlagDescription, example
-qps rateTotal Queries Per Seconds across all connections/threads or 0 for no wait/max qps
-nocatchupDo not try to reach the target qps by going faster when the service falls behind and then recovers. Makes QPS an absolute ceiling even if the service has some spikes in latency, fortio will not compensate (but also won't stress the target more than the set qps). Recommended to use jointly with -uniform.
-c connectionsNumber of parallel simultaneous connections (and matching go routine)
-t durationHow long to run the test (for instance -t 30m for 30 minutes) or 0 to run until ^C, example (default 5s)
-n numcallsRun for exactly this number of calls instead of duration. Default (0) is to use duration (-t).
-payload str or -payload-file fnameSwitch to using POST with the given payload (see also -payload-size for random payload)
-uniformSpread the calls in time across threads for a more uniform call distribution. Works even better in conjunction with -nocatchup.
-r resolutionResolution of the histogram lowest buckets in seconds (default 0.001 i.e 1ms), use 1/10th of your expected typical latency
-H "header: value"Can be specified multiple times to add headers (including Host:)
-aAutomatically save JSON result with filename based on labels and timestamp
-json filenameFilename or - for stdout to output json result (relative to -data-dir by default, should end with .json if you want fortio report to show them; using -a is typicallly a better option)
-labels "l1 l2 ..."Additional config data/labels to add to the resulting JSON, defaults to target URL and hostname
-h2Client calls will attempt to negotiate http/2.0 instead of http1.1, implies -stdclient

You can switch from http GET queries to POST by setting -content-type or passing one of the -payload-* option.

Full list of command line flags (fortio help):

Φορτίο 1.41.0 usage:
    fortio command [flags] target
where command is one of: load (load testing), server (starts ui, rest api,
 http-echo, redirect, proxies, tcp-echo, udp-echo and grpc ping servers),
 tcp-echo (only the tcp-echo server), udp-echo (only udp-echo server),
 report (report only UI server), redirect (only the redirect server),
 proxies (only the -M and -P configured proxies), grpcping (grpc client),
 or curl (single URL debug), or nc (single tcp or udp:// connection),
 or version (prints the full version and build details).
where target is a url (http load tests) or host:port (grpc health test),
 or tcp://host:port (tcp load test), or udp://host:port (udp load test).
flags are:
  -H key:value
        Additional http header(s) or grpc metadata. Multiple key:value pairs
can be passed using multiple -H.
  -L    Follow redirects (implies -std-client) - do not use for load test
  -M value
        Http multi proxy to run, e.g -M "localport1 baseDestURL1 baseDestURL2"
-M ...
  -P value
        Tcp proxies to run, e.g -P "localport1 dest_host1:dest_port1" -P
"[::1]:0 www.google.com:443" ...
  -a    Automatically save JSON result with filename based on labels & timestamp
  -abort-on code
        Http code that if encountered aborts the run. e.g. 503 or -1 for socket
errors.
  -access-log-file path
        file path to log all requests to. Maybe have performance impacts
  -access-log-format format
        format for access log. Supported values: [json, influx] (default "json")
  -allow-initial-errors
        Allow and don't abort on initial warmup errors
  -base-url URL
        base URL used as prefix for data/index.tsv generation. (when empty, the
url from the first request is used)
  -c int
        Number of connections/goroutine/threads (default 4)
  -cacert Path
        Path to a custom CA certificate file to be used for the TLS client
connections, if empty, use https:// prefix for standard internet/system CAs
  -calc-qps
        Calculate the qps based on number of requests (-n) and duration (-t)
  -cert Path
        Path to the certificate file to be used for client or server TLS
  -compression
        Enable http compression
  -config path
        Config directory path to watch for changes of dynamic flags (empty for
no watch)
  -connection-reuse min:max
        Range min:max for the max number of connections to reuse for each
thread, default to unlimited. e.g. 10:30 means randomly choose a max connection
reuse threshold between 10 and 30 requests.
  -content-type string
        Sets http content type. Setting this value switches the request method
from GET to POST.
  -curl
        Just fetch the content once
  -curl-stdout-headers
        Restore pre 1.22 behavior where http headers of the fast client are
output to stdout in curl mode. now stderr by default.
  -data-dir Directory
        Directory where JSON results are stored/read (default ".")
  -dns-method method
        When a name resolves to multiple ip, which method to pick: cached-rr
for cached round robin, rnd for random, first for first answer (pre 1.30
behavior), rr for round robin. (default cached-rr)
  -echo-debug-path URI
        http echo server URI for debug, empty turns off that part (more secure)
(default "/debug")
  -echo-server-default-params value
        Default parameters/querystring to use if there isn't one provided
explicitly. E.g "status=404&delay=3s"
  -gomaxprocs int
        Setting for runtime.GOMAXPROCS, <1 doesn't change the default
  -grpc
        Use GRPC (health check by default, add -ping for ping) for load testing
  -grpc-max-streams uint
        MaxConcurrentStreams for the grpc server. Default (0) is to leave the
option unset.
  -grpc-ping-delay duration
        grpc ping delay in response
  -grpc-port port
        grpc server port. Can be in the form of host:port, ip:port or port or
/unix/domain/path or "disabled" to not start the grpc server. (default "8079")
  -h    Print usage/help on stdout
  -h2
        Attempt to use http2.0 / h2 (instead of http 1.1) with stdclient and TLS
  -halfclose
        When not keepalive, whether to half close the connection (only for fast
http)
  -health
        grpc ping client mode: use health instead of ping
  -healthservice string
        which service string to pass to health check
  -http-port port
        http echo server port. Can be in the form of host:port, ip:port, port
or /unix/domain/path or "disabled". (default "8080")
  -http1.0
        Use http1.0 (instead of http 1.1)
  -httpbufferkb kbytes
        Size of the buffer (max data size) for the optimized http client in
kbytes (default 128)
  -httpccch
        Check for Connection: Close Header
  -https-insecure
        Long form of the -k flag
  -jitter
        set to true to de-synchronize parallel clients' by 10%
  -json path
        Json output to provided file path or '-' for stdout (empty = no json
output, unless -a is used)
  -k    Do not verify certs in https/tls/grpc connections
  -keepalive
        Keep connection alive (only for fast http 1.1) (default true)
  -key Path
        Path to the key file matching the -cert
  -labels string
        Additional config data/labels to add to the resulting JSON, defaults to
target URL and hostname
  -log-errors
        Log http non 2xx/418 error codes as they occur (default true)
  -loglevel level
        log level, one of [Debug Verbose Info Warning Error Critical Fatal]
(default Info)
  -max-echo-delay value
        Maximum sleep time for delay= echo server parameter. dynamic flag.
(default 1.5s)
  -maxpayloadsizekb Kbytes
        MaxPayloadSize is the maximum size of payload to be generated by the
EchoHandler size= argument. In Kbytes. (default 256)
  -multi-mirror-origin
        Mirror the request url to the target for multi proxies (-M) (default
true)
  -multi-serial-mode
        Multi server (-M) requests one at a time instead of parallel mode
  -n int
        Run for exactly this number of calls instead of duration. Default (0)
is to use duration (-t). Default is 1 when used as grpc ping count.
  -nc-dont-stop-on-eof
        in netcat (nc) mode, don't abort as soon as remote side closes
  -no-reresolve
        Keep the initial DNS resolution and don't re-resolve when making new
connections (because of error or reuse limit reached)
  -nocatchup
        set to exact fixed qps and prevent fortio from trying to catchup when
the target fails to keep up temporarily
  -offset duration
        Offset of the histogram data
  -p string
        List of pXX to calculate (default "50,75,90,99,99.9")
  -payload string
        Payload string to send along
  -payload-file path
        File path to be use as payload (POST for http), replaces -payload when
set.
  -payload-size int
        Additional random payload size, replaces -payload when set > 0, must be
smaller than -maxpayloadsizekb. Setting this switches http to POST.
  -ping
        grpc load test: use ping instead of health
  -profile file
        write .cpu and .mem profiles to file
  -proxy-all-headers
        Determines if only tracing or all headers (and cookies) are copied from
request on the fetch2 ui/server endpoint (default true)
  -qps float
        Queries Per Seconds or 0 for no wait/max qps (default 8)
  -quiet
        Quiet mode: sets the loglevel to Error and reduces the output.
  -r float
        Resolution of the histogram lowest buckets in seconds (default 0.001)
  -redirect-port port
        Redirect all incoming traffic to https URL (need ingress to work
properly). Can be in the form of host:port, ip:port, port or "disabled" to
disable the feature. (default "8081")
  -resolve IP
        Resolve host name to this IP
  -resolve-ip-type type
        Resolve type: ip4 for ipv4, ip6 for ipv6 only, use ip for both (default
ip4)
  -runid int
        Optional RunID to add to json result and auto save filename, to match
server mode
  -s int
        Number of streams per grpc connection (default 1)
  -sequential-warmup
        http(s) runner warmup done in parallel instead of sequentially. When
set, restores pre 1.21 behavior
  -server-idle-timeout value
        Default IdleTimeout for servers (default 30s)
  -static-dir path
        Deprecated/unused path.
  -stdclient
        Use the slower net/http standard client (slower but supports h2)
  -sync URL
        index.tsv or s3/gcs bucket xml URL to fetch at startup for server modes.
  -sync-interval duration
        Refresh the url every given interval (default, no refresh)
  -t duration
        How long to run the test or 0 to run until ^C (default 5s)
  -tcp-port port
        tcp echo server port. Can be in the form of host:port, ip:port, port or
/unix/domain/path or "disabled". (default "8078")
  -timeout duration
        Connection and read timeout value (for http) (default 3s)
  -udp-async
        if true, udp echo server will use separate go routine to reply
  -udp-port port
        udp echo server port. Can be in the form of host:port, ip:port, port or
"disabled". (default "8078")
  -udp-timeout duration
        Udp timeout (default 750ms)
  -ui-path URI
        http server URI for UI, empty turns off that part (more secure)
(default "/fortio/")
  -uniform
        set to true to de-synchronize parallel clients' requests uniformly
  -unix-socket path
        Unix domain socket path to use for physical connection
  -user user:password
        User credentials for basic authentication (for http). Input data format
should be user:password

See also the FAQ entry about fortio flags for best results⁠.

⁠Server URLs and features

Fortio server has the following feature for the http listening on 8080 (all paths and ports are configurable through flags above):

  • A simple echo server which will echo back posted data (for any path not mentioned below).

    For instance curl -d abcdef http://localhost:8080/ returns abcdef back. It supports the following optional query argument parameters:

ParameterUsage, example
delayduration to delay the response by. Can be a single value or a comma separated list of probabilities, e.g delay=150us:10,2ms:5,0.5s:1 for 10% of chance of a 150 us delay, 5% of a 2ms delay and 1% of a 1/2 second delay
statushttp status to return instead of 200. Can be a single value or a comma separated list of probabilities, e.g status=404:10,503:5,429:1 for 10% of chance of a 404 status, 5% of a 503 status and 1% of a 429 status
sizesize of the payload to reply instead of echoing input. Also works as probabilities list. size=1024:10,512:5 10% of response will be 1k and 5% will be 512 bytes payload and the rest defaults to echoing back.
closeclose the socket after answering e.g close=true to close after all requests or close=5.3 to close after approximately 5.3% of requests
headerheader(s) to add to the reply e.g. &header=Foo:Bar&header=X:Y
gzipIf Accept-Encoding: gzip is passed in headers by the caller/client; and gzip=true is in the query args, all response will be gzipped; or if gzip=42.7 is passed, approximately 42.7% will

delay, close and header query arguments are also supported for the debug endpoint which echoes back the request (gzip is always done if Accept-Encoding: gzip is present, status is always 200, and the payload is the echo back debug information).

You can set a default value for all these by passing -echo-server-default-params to the server command line, for instance: fortio server -echo-server-default-params="delay=0.5s:50,1s:40&status=418" will make the server respond with http 418 and a delay of either 0.5s half of the time, 1s 40% and no delay in 10% of the calls; unless any ? query args is passed by the client. Note that the quotes (") are for the shell to escape the ampersand (&) but should not be put in a yaml nor the dynamicflag url for instance.

  • /debug will echo back the request in plain text for human debugging.

  • /fortio/ A UI to

    • Run/Trigger tests and graph the results.
    • A UI to browse saved results and single graph or multi graph them (comparative graph of min,avg, median, p75, p99, p99.9 and max).
    • Proxy/fetch other URLs.
    • /fortio/data/index.tsv an tab separated value file conforming to Google cloud storage URL list data transfer format⁠ so you can export/backup local results to the cloud.
    • Download/sync peer to peer JSON results files from other Fortio servers (using their index.tsv URLs).
    • Download/sync from an Amazon S3 or Google Cloud compatible bucket listings XML URLs⁠.
  • API to trigger and cancel runs from the running server (like the form ui but more directly and with async=on option)

    • /fortio/rest/run starts a run; the arguments are either from the command line or from POSTed JSON; jsonPath can be provided to look for in a subset of the json object, for instance jsonPath=metadata allows to use the flagger webhook meta data for fortio run parameters (see Remote Triggered load test section below⁠).
    • /fortio/rest/stop stops all current run or by run id (passing runid= query argument).
    • /fortio/rest/status lists the current runs (or the options of a single one if runid is passed).

The report mode is a readonly subset of the above directly on /.

There is also the GRPC health and ping servers, as well as the http->https redirector.

⁠Example use and output

⁠Start the internal servers
$ fortio server &
Fortio X.Y.Z tcp-echo server listening on tcp [::]:8078
Fortio X.Y.Z udp-echo server listening on udp [::]:8078
Fortio X.Y.Z grpc 'ping' server listening on tcp [::]:8079
Fortio X.Y.Z https redirector server listening on tcp [::]:8081
Fortio X.Y.Z http-echo server listening on tcp [::]:8080
Data directory is /Users/ldemailly/dev/fortio
REST API on /fortio/rest/run, /fortio/rest/status, /fortio/rest/stop
	 UI started - visit:
		http://localhost:8080/fortio/
	 (or any host/ip reachable on this server)
I fortio_main.go:285> Note: not using dynamic flag watching (use -config to set watch directory)
I fortio_main.go:293> All fortio X.Y.Z  goM.m.p arm64 darwin servers started!
⁠Sample of the graphing UI

With the 2 histograms - total and errors overlayed:

Graphical result

⁠Change the port / binding address

By default, Fortio's web/echo servers listen on port 8080 on all interfaces. Use the -http-port flag to change this behavior:

$ fortio server -http-port 10.10.10.10:8088
UI starting - visit:
http://10.10.10.10:8088/fortio/
Https redirector running on :8081
Fortio X.Y.Z grpc ping server listening on port :8079
Fortio X.Y.Z echo server listening on port 10.10.10.10:8088
⁠Unix domain sockets

You can use unix domain socket for any server/client:

$ fortio server --http-port /tmp/fortio-uds-http &
Fortio X.Y.Z grpc 'ping' server listening on [::]:8079
Fortio X.Y.Z https redirector server listening on [::]:8081
Fortio X.Y.Z echo server listening on /tmp/fortio-uds-http
UI started - visit:
fortio curl -unix-socket=/tmp/fortio-uds-http http://localhost/fortio/
14:58:45 I fortio_main.go:217> All fortio X.Y.Z unknown goM.m.p servers started!
$ fortio curl -unix-socket=/tmp/fortio-uds-http http://foo.bar/debug
15:00:48 I http_client.go:428> Using unix domain socket /tmp/fortio-uds-http instead of foo.bar http
HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Date: Wed, 08 Aug 2018 22:00:48 GMT
Content-Length: 231

Φορτίο version X.Y.Z unknown goM.m.p echo debug server up for 2m3.4s on ldemailly-macbookpro - request from

GET /debug HTTP/1.1

headers:

Host: foo.bar
User-Agent: fortio.org/fortio-X.Y.Z

body:
⁠TCP

Start the echo-server alone and run a load (use tcp:// prefix for the load test to be for tcp echo server):

$ fortio tcp-echo &
Fortio X.Y.Z tcp-echo TCP server listening on [::]:8078
19:45:30 I fortio_main.go:238> All fortio X.Y.Z release goM.m.p servers started!
$ fortio load -qps -1 -n 
Tag summary
Recent tags
Content type
Image
Digest
sha256:cc62b5a4a…
Size
2.6 MB
Last updated
almost 4 years ago
docker pull fortio/fortio.fcurl:latest