Sign inSign up

jpalpant/chromedp-load-agent

By jpalpant

•Updated over 6 years ago

A load agent using github.com/chromedp/chromedp to drive simulated web traffic.

Image
0

1.1K

jpalpant/chromedp-load-agent repository overview

⁠Overview

Go Report Card Docker Pulls

This project will be a simple golang agent to render web pages headlessly using github.com/chromedp/chromedp⁠, and to use that in my infrastructure to simulate additional load on my websites.

The goal is to provide a way to load my websites that resembles constant user traffic at a roughly configurable QPS. To do this, it must support authentication, custom headers, and TLS, because most of my websites require authentication. It should support trawling a variety of URLs from a single agent, as well as a configurable concurrency to allow one load agent to simulate multiple users.

It is not a goal to replace 3rd-party load-testing tools (like flood.io⁠, which I've used before and like), but it may be possible to do so for simple cases. Those tools generate massive distributed bursts of load from many regions, and are hugely scalable. If this tool scales horizontally that's great, but burstiness and ramp up are not the goals. I need something instead to provide constant background noise that is scalable and headless.

Note: this tool is not as efficient as excellent load-generating tools like wrk⁠, or even cURL⁠, when it comes to making requests to a single URL. You can expect perhaps tens of page loads per second per core, maximum. Instead, this tool is meant to stress the entire visiting experience. The way I use this tool is to add additional load to a Grafana instance, where fetching the single HTTP request that defines a dashboard would induce relatively small load, but loading the full page and executing the corresponding queries stresses the complete system.

⁠Getting Started

⁠Usage

$ ./chromedp-load-agent --help
CLI to use chromedp as a long-running load agent against one or more URLs

Usage:
  chromedp-load-agent [command]

Available Commands:
  completion  Generates bash completion scripts
  help        Help about any command
  run         Visit to each URL continuously
  test        One-time visit to each URL to validate configuration

Flags:
  -h, --help                help for chromedp-load-agent
      --log-format string   specify output (text or json) (default "text")
      --log-level string    one of debug, info, warn, error, or fatal (default "info")
  -v, --version             version for chromedp-load-agent

Use "chromedp-load-agent [command] --help" for more information about a command.
⁠test
$ ./chromedp-load-agent test --help
Visit each URL one time.

Use this to validate configuration and environment, such as authentication, screenshot, and connectivity.

Does not use load-related flags, because each URL is visited one time. Does not run any long-running server processes.

Exits 0 if all URLs are visited with successful HTTP status codes (2xx), or non-zero if any URLs fail or time out.

Usage:
  chromedp-load-agent test [flags]

Flags:
  -c, --concurrency uint            Number of tabs to use to visit URLs in parallel. (default 1)
  -H, --headers stringToString      HTTP headers to use for all requests. (default [])
  -h, --help                        help for test
      --load-only                   Only wait for page load event, not network idle event. This increases the likelihood that the page is not completely loaded when a screenshot is taken.
      --navigate-timeout duration   Maximum time to wait for page load and networkIdle events. (default 30s)
      --screenshot                  Take screenshots of visited URLs. Note: this has a significant performance cost. Retains one screenshot per URL, overwriting when URL is revisited.
      --screenshot-dir string       Directory in which to save screenshots. Defaults to CWD.
      --tls-skip-verify             Skip TLS verification when browsing all URLs.
  -u, --url strings                 URLs to visit. Specify once with commas separating URLs, or provide the flag multiple times.
      --url-file string             File containing line-delimited list of URLs, to replace repeated uses of --url
      --window-height int           Width of the Chrome window in pixels. (default 1080)
      --window-width int            Width of the Chrome window in pixels. (default 1920)

Global Flags:
      --log-format string   specify output (text or json) (default "text")
      --log-level string    one of debug, info, warn, error, or fatal (default "info")
⁠run
$ ./chromedp-load-agent run --help
Visit each URL provided.

Does not exit, but runs continuously. Use --concurrency to specify a number of
browser tabs to use in parallel as a way of modifying generated load.

Usage:
  chromedp-load-agent run [flags]

Flags:
  -c, --concurrency uint            Number of tabs to use to visit URLs in parallel. (default 1)
  -H, --headers stringToString      HTTP headers to use for all requests. (default [])
  -h, --help                        help for run
      --load-only                   Only wait for page load event, not network idle event. This increases the likelihood that the page is not completely loaded when a screenshot is taken.
      --navigate-timeout duration   Maximum time to wait for page load and networkIdle events. (default 30s)
      --screenshot                  Take screenshots of visited URLs. Note: this has a significant performance cost. Retains one screenshot per URL, overwriting when URL is revisited.
      --screenshot-dir string       Directory in which to save screenshots. Defaults to CWD.
      --tls-skip-verify             Skip TLS verification when browsing all URLs.
  -u, --url strings                 URLs to visit. Specify once with commas separating URLs, or provide the flag multiple times.
      --url-file string             File containing line-delimited list of URLs, to replace repeated uses of --url
      --window-height int           Width of the Chrome window in pixels. (default 1080)
      --window-width int            Width of the Chrome window in pixels. (default 1920)

Global Flags:
      --log-format string   specify output (text or json) (default "text")
      --log-level string    one of debug, info, warn, error, or fatal (default "info")

⁠Build & Test

Test coverage is non-existent right now. To build, just go build . or, to build the Docker image, docker build -t chromedp-load-agent:local ..

⁠Deploy

⁠Binary

If using a local binary, chromedp will attempt to local a suitable Google Chrome installation and connect to it or launch a new browser on start-up.

⁠Image

A Dockerfile is available in the repo, and published to quay.io/jpalpant/chromedp-load-agent⁠ as well as jpalpant/chromedp-load-agent⁠ on DockerHub.

The Docker image is built from chromedp/headless-shell⁠, and which includes Chrome, so the image has no external dependencies.

⁠Caveats

This tool simulates a complete browser, which means it's very resource intensive! I find that a single instance running with one tab and a Docker CPU limit of 1 core can experience CPU throttling, depending on the websites visited and if screenshots are being collected. However, Chrome's parallelization is fairly clever, so allocating multiple tabs with the same CPU limit does not lead to timeouts, and in spite of throttling, does lead to increase QPS.

Note that QPS generated by this tool depends not only on the --concurrency argument, but the total time it takes to load the pages being visited.

Additionally, headless chrome can freeze if unable to access sufficient shared memory. Shared memory is usually allocated via /dev/shm, and Docker containers restrict the size of this to 64MiB, by default. When using Docker, pass --shm-size 1Gi to increase the limit; using Kubernetes, mount a tmpfs volume to /dev/shm to allow shared memory to use the pod's allocated memory.

⁠Goals

⁠Main goals

  • Run indefinitely
  • One or multple URLs (via CLI or a config file)
  • Traffic resembles and incurs the load that a user would incur
  • Configurable QPS and parallelization
  • Support for TLS, custom headers, possible custom cookies
  • Docker image
  • Detect and handle web page load errors

⁠Fun add-ons

  • Liveness check endpoint (HTTP server)
  • Prometheus metrics (Some interesting metrics could be: Counter for fetches, probably with labels for HTTP status, domain, URL; Gauge for last-successful-fetch; Histogram for page load latency)
  • Screenshots
  • Displaying screenshots from an endpoint

⁠Non-goals

  • (x) Configurable ramp or load patterns
  • (x) Web-page content or performance testing

⁠Assorted TODOs

  • Automated testing
  • Rewrite visiting logic into a better library, not lumped all into test.go

⁠Versions

See CHANGELOG⁠ for more details on versions.

Tag summary

Content type

Image

Digest

Size

115.7 MB

Last updated

over 6 years ago

docker pull jpalpant/chromedp-load-agent