> ## Documentation Index
> Fetch the complete documentation index at: https://docs.loadforge.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Enhancing Test Performance with FastHTTP

> Leverage the FastHttpUser class to optimize load test throughput on LoadForge.

## Introduction

By default, LoadForge harnesses the capabilities of the `HttpUser` class, an interface built atop Python's renowned `requests` library. While this provides vast opportunities to tailor your test, it may sometimes offer more than you need.

For those eyeing improved throughput, LoadForge introduces `FastHttpUser`—a class that promises to amplify your test capacity by 4-5x, facilitating a greater number of requests per second compared to the default `HttpUser`.

<Warning title="For Advanced Users">
  Please proceed cautiously: `FastHttpUser` is an advanced feature. While it offers speed, it sacrifices some of the functionalities inherent to the `HttpUser` class. It may not suit every user or every use case.
</Warning>

## Sample Test with FastHttpUser

Here's a succinct test showcasing the usage of `FastHttpUser`. This test has no `wait_time` and is designed to deliver the maximum number of requests for each virtual user.

```python theme={null}
from locust import task, FastHttpUser

class MyUser(FastHttpUser):
    @task(1)
    def index(self):
        response = self.client.get("/")
```

***

## Advanced Test with FastHttpUser

Suppose you have an e-commerce site and want to test the performance of various pages: the homepage, product listings, and individual product pages. The following test simulates these scenarios using `FastHttpUser`:

### Code

```python theme={null}
from locust import task, FastHttpUser, between
import random

class EcommerceUser(FastHttpUser):
    wait_time = between(1, 5)  # simulates user thinking time between 1 to 5 seconds

    @task(3)  # 3 times more likely to visit the homepage than other pages
    def visit_home(self):
        self.client.get("/")

    @task(2)
    def browse_products(self):
        self.client.get("/products")

    @task(1)
    def view_single_product(self):
        # this function would return a random product ID
        product_id = self.random_product_id()  
        self.client.get(f"/products/{product_id}")

    def random_product_id(self):        
        # assuming there are 1000 products
        return random.randint(1, 1000) 

```

### Weights & Endpoints

In this advanced example, you'll notice the `@task` decorators are given different weights. These weights dictate the likelihood of a particular endpoint being hit. A higher weight means the task will be executed more frequently. This simulates real-world scenarios where users are more likely to visit some pages (like the homepage) than others.

***

Remember, while `FastHttpUser` accelerates the request throughput, you might miss out on some of the functionalities offered by the standard `HttpUser`. Always make sure to weigh the pros and cons based on the specific requirements of your testing scenario.

***

<Note title="Harness the Power of Locust">
  LoadForge is built on the sturdy foundation of `locust.io`, an open-source load testing framework. If you're already a user of `locust.io`, this script will look familiar. Interested in escalating your testing game? Import your `locust.io` script into [LoadForge](https://loadforge.com) and tap into a world of enhanced testing!
</Note>
