Giter Club home page Giter Club logo

Comments (3)

FutureSharks avatar FutureSharks commented on May 28, 2024 1

Hi @sribatchu,

it always seem to ignore the LoadTestShape and just uses the num_users and spawn_rate from the event payload

Hmmm, I see.

I've just thought about it and even if we do manage to find and use the LoadTestShape class, it still won't work because it counts the time since the load test started. This will never work on Lambda in its current implementation as the counter would be restarted for every lambda invocation.

The only way it could theoretically work is if invokust saved the start time externally and then counted the time using this external record. This would require a custom LoadTestShape class just for invokust though. PRs welcome 🙂

from invokust.

FutureSharks avatar FutureSharks commented on May 28, 2024

There's no reason why not

from invokust.

sribatchu avatar sribatchu commented on May 28, 2024

when running it as lambda, it always seem to ignore the LoadTestShape and just uses the num_users and spawn_rate from the event payload. If I don't pass num_users or spawn_rate as part of my event payload, I get Locust exception Exception('configuration error, attribute not set: num_users')

lambda.py

def lambda_handler(event, context=None):
    try:
        if event:
            settings = create_settings(**event)
        else:
            settings = create_settings(from_environment=True)

        loadtest = LocustLoadTest(settings)
        loadtest.run()
    except Exception as e:
        logging.error("Locust exception {0}".format(repr(e)))

    else:
        locust_stats = loadtest.stats()
        lambda_runtime_info = get_lambda_runtime_info(context)
        loadtest_results = locust_stats.copy()
        loadtest_results.update(lambda_runtime_info)
        json_results = json.dumps(loadtest_results)

        logging.info(json_results)
        return json_results

locustfile.py

class LoadTest(HttpUser):
    wait_time = between(0, 1)
    @task
    def query(self):
        self.client.get("/api")

class StagesShapeWithCustomUsers(LoadTestShape):
    stages = [
        {"duration": 10, "users": 100, "spawn_rate": 10, "user_classes": [LoadTest]},
        {"duration": 20, "users": 150, "spawn_rate": 10, "user_classes": [LoadTest]},
        {"duration": 30, "users": 200, "spawn_rate": 10, "user_classes": [LoadTest]}
    ]

    def tick(self):
        run_time = self.get_run_time()
        for stage in self.stages:
            if run_time < stage["duration"]:
                try:
                    tick_data = (stage["users"], stage["spawn_rate"], stage["user_classes"])
                except KeyError:
                    tick_data = (stage["users"], stage["spawn_rate"])
                return tick_data
        return None

from invokust.

Related Issues (20)

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.