Are you ready for a Goose Attack?
Tags: performance, tutorial, testing, rust
Published: 2021-03-30 16:52:03

<!-- wp:paragraph -->
<p>Recently I stumbled upon a new load testing tool called Goose. Immediately I took it up for a spin and this blog post helps you to get started with Goose in IntelliJ IDEA. Let us get started. Before you read further, please check out my <a href="https://www.youtube.com/playlist?list=PLJ9A48W0kpRKMCzJARCObgJs3SinOewp5" target="_blank" rel="noreferrer noopener">latest video series about Locust</a> which will be very helpful for you in case if you are going to pursue Goose.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="h-what-is-goose">What is Goose?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Goose is a load testing tool written in Rust. It is inspired from <a href="https://locust.io/" target="_blank" rel="noreferrer noopener">Locust</a>. If you want to get started with Goose, I recommend you to understand how <a href="https://www.youtube.com/playlist?list=PLJ9A48W0kpRKMCzJARCObgJs3SinOewp5" target="_blank" rel="noreferrer noopener">Locust</a> works from my video series for free.</p>
<!-- /wp:paragraph -->

<!-- wp:buttons {"contentJustification":"center"} -->
<div class="wp-block-buttons is-content-justification-center"><!-- wp:button {"gradient":"luminous-vivid-orange-to-vivid-red"} -->
<div class="wp-block-button"><a class="wp-block-button__link has-luminous-vivid-orange-to-vivid-red-gradient-background has-background" href="https://github.com/tag1consulting/goose" target="_blank" rel="noreferrer noopener">Goose Repo</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->

<!-- wp:paragraph -->
<p>Goose has been developed by Tag1 Consulting from past 10 months. The current version of Goose at this time of writing is 0.10.9. You can check out the latest release from <a href="https://github.com/tag1consulting/goose/releases" target="_blank" rel="noreferrer noopener">here</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="h-getting-started-with-goose">Getting Started with Goose</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Before you start installing and scripting in Goose, I recommend two things to learn: Rust and <a href="https://www.youtube.com/playlist?list=PLJ9A48W0kpRKMCzJARCObgJs3SinOewp5" target="_blank" rel="noreferrer noopener">Locust</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To get started with <a href="https://www.rust-lang.org" target="_blank" rel="noreferrer noopener">Rust</a>, you can check out the <a href="https://www.rust-lang.org/learn" target="_blank" rel="noreferrer noopener">documentation in here</a>; also, there are a lot of tutorials available on the internet.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 id="h-prerequisites">Prerequisites</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Following are the prerequisites required to get started with Goose:</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Rust</li><li>IntelliJ IDEA or your favorite IDE</li><li>Rust plugin for IntelliJ IDEA</li><li>Cargo - package manager for Rust</li><li>Goose</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>To download and install Rust and Cargo, <a href="https://doc.rust-lang.org/cargo/getting-started/installation.html" target="_blank" rel="noreferrer noopener">please click here</a> to follow the instructions.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I am going to use IntelliJ IDE for Goose. There is a plugin available for Rust in <a href="https://www.jetbrains.com/idea/download/" target="_blank" rel="noreferrer noopener nofollow">IntelliJ IDEA</a>, to install the Rust plugin, launch IntelliJ, go to File &gt; Settings &gt; Plugins, search for Rust  to install and enable.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8276,"sizeSlug":"large","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2021/03/image-11.png"><img src="https://qainsights.com/wp-content/uploads/2021/03/image-11.png" alt="Getting Started with Goose - Install Rust in IntelliJ IDEA" class="wp-image-8276"/></a><figcaption>Getting Started with Goose - Install Rust in IntelliJ IDEA</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3 id="h-hello-world-in-goose">Hello World in Goose</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Now, let us create our first Goose project in IntelliJ IDEA. Launch IntelliJ IDEA, click on <strong>New Project</strong>, select <strong>Rust </strong>as shown below. Select <strong>Binary </strong>as <strong>Project template</strong>. Click on <strong>Next </strong>button.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8277,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image size-large"><a href="https://qainsights.com/wp-content/uploads/2021/03/image-12.png"><img src="https://qainsights.com/wp-content/uploads/2021/03/image-12.png" alt="Create Rust Project in IntelliJ IDEA" class="wp-image-8277"/></a><figcaption>Create Rust Project in IntelliJ IDEA</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Enter a project name as <code>hello-world</code> as shown below. Click on <strong>Finish</strong> button. This will create a new Rust project, not Goose. After creating a project, wait for a minute. IntelliJ will download the Rust macros. </p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8279,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image size-large"><a href="https://qainsights.com/wp-content/uploads/2021/03/image-14.png"><img src="https://qainsights.com/wp-content/uploads/2021/03/image-14.png" alt="Hello World" class="wp-image-8279"/></a><figcaption>Hello World</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>By default, IntelliJ IDEA will create a <code>main.rs</code> file with the below code. Rust file has the extension <code>*.rs</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>fn main() {
    println!("Hello, world!");
}
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Now, it is time to install the Goose as a dependency. Open <code>Cargo.toml</code> file from the project folder and enter <code>goose = "0.10.9"</code> under <code>dependencies</code> as shown below. This will download the goose crates.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8281,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image size-large"><a href="https://qainsights.com/wp-content/uploads/2021/03/image-16.png"><img src="https://qainsights.com/wp-content/uploads/2021/03/image-16-1024x242.png" alt="Cargo.toml" class="wp-image-8281"/></a><figcaption>Cargo.toml</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Let us write our first Hello World in Rust for Goose. Open <code>main.rs</code> and enter the below code. It is totally fine, if you are not getting the code. I will explain it in my next post.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>use goose::prelude::*;

async fn hello_world(user: &amp;GooseUser) -&gt; GooseTaskResult {
    let _goose_metrics = user.get("/").await?;

    Ok(())
}

fn main() -&gt; Result&lt;(), GooseError&gt; {
    GooseAttack::initialize()?
        .register_taskset(taskset!("T00_HomePage")
            .register_task(task!(hello_world))
        )
        .execute()?
        .print();

    Ok(())
}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>It is time to smoke load test the <code>main.rs</code>. Press Alt + F12 to open the terminal pane. cd into <code>src</code> folder, because that is where our main.rs file resides. Enter the below command and hit enter. This will compile your rust code and attack the host https://example.com</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>cargo run -- --host https://example.com
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Please do not run your test for more than few seconds. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Goose will display the below details in the terminal window. If you observe the last line, it will show <strong>All 4 users hatched ...</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Why 4 users? We never mentioned the number of users in our command line nor in the code. By default, Goose spins the number of users based on number of CPU cores of your system. My laptop has 2 CPU cores with the 4 logical processors, hence it is hatched 4 users. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>During the execution, it displays per task metrics and per request metrics. We do have only one task called <strong>T00_HomePage </strong>with one request.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8283,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image size-large"><a href="https://qainsights.com/wp-content/uploads/2021/03/image-18.png"><img src="https://qainsights.com/wp-content/uploads/2021/03/image-18.png" alt="cargo run" class="wp-image-8283"/></a><figcaption>cargo run</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Press Ctrl + C, to terminate the execution. Once it is terminated, you can see the final stats as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8284,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image size-large"><a href="https://qainsights.com/wp-content/uploads/2021/03/image-19.png"><img src="https://qainsights.com/wp-content/uploads/2021/03/image-19.png" alt="" class="wp-image-8284"/></a><figcaption>terminating the test</figcaption></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2 id="h-useful-goose-commands">Useful Goose Commands</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Below are some of the useful commands for Goose.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Goose help options:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>cargo run -- -h
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>To validate the Goose version:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>cargo run -- -V</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>To see the tasks and exit</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>cargo run -- -l</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Runtime options to run with 1 user (-u) in 1 second (-r) for 5 seconds (-t)</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>cargo run -- --host https://example.com -u 1 -r 1 -t 5s</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>To generate HTML report:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>cargo run -- --host https://example.com -u 1 -r 1 -t 5s -R Run1.html
</code></pre>
<!-- /wp:code -->

<!-- wp:image {"id":8285,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image size-large"><a href="https://qainsights.com/wp-content/uploads/2021/03/image-20.png"><img src="https://qainsights.com/wp-content/uploads/2021/03/image-20-1024x570.png" alt="" class="wp-image-8285"/></a><figcaption>Sample Goose HTML Report</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>To generate detailed log file:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>cargo run -- --host https://example.com -u 1 -r 1 -t 5s -gg -L mylog.log
</code></pre>
<!-- /wp:code -->

<!-- wp:heading -->
<h2 id="h-my-experience-with-goose">My experience with Goose</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>From past one week I have been learning Rust and Goose, as a performance engineer, you may be feeling overwhelming while working in Goose. Because of the steep learning curve. You need to learn one more language Rust and then it would be added advantage if you know Locust. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Goose is heavily inspired from Locust but it addresses the disadvantage of Locust. Mainly because of Python is slower than the other language. Goose developers claims that the Locust (Python) requires more resources for the high volume test than the Goose. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>My take is Goose is a good candidate only if you have a team of Rust developers with the performance knowledge. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Goose also has a feature called Gaggle, distributed load testing in Goose. Excellent candidate for CI/CD due to its command line nature.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In GitHub, it has over 100+ stars and with <a href="https://github.com/tag1consulting/goose/graphs/contributors" target="_blank" rel="noreferrer noopener">5+ contributors</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>On the down side, Goose doesn't seen a major release yet. At this time, there are 20+ open issues. Most of them are enhancements. Also, there are no quite Goose examples available yet to explore.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 id="h-conclusion">Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Goose is a new tool in the performance town. If you love Rust, you will love Goose. As a performance engineer, I always look for a new tool to learn and try. Goose is one of the instrument in my swiss army knife. I will wait for the right opportunity to use this tool. Meanwhile I will be happy with the current set of instruments.</p>
<!-- /wp:paragraph -->