简体   繁体   中英

Gatling: How to ramp up users in the after{} hook?

I'm an absolute Gatling beginner, and have mostly written my simulations by copying bits and pieces of other simulations in my org's code. I searched around a bunch, and didn't see a similar question (and couldn't find anything in the gatling docs), so now I'm here.

I know Gatling has an after{} hook that will run code after the simulation finishes. I need to know how to multi-thread the after{} hook the same way the simulation is multi-threaded. Basically, can I ramp up users within the after{} hook?

My issue is: My simulation ramps up 100 users, logs them into a random account (from a list of 1000 possible accounts), and then creates 500 projects within that account. This is to test the performance of a project creation endpoint.

The problem is that we have another simulation that tests the performance of an endpoint that counts the number of projects in a given account. That test is starting to suffer because of the sheer volume of projects in these accounts (they're WAYYY more loaded than even our largest real-world account -- by orders of magnitude), so I want my "project creation" simulation to clean up the accounts when it's done.

Ideally, the after would do something like this:

after {
   //ramp up 1000 users
   //each user should then....
       //log into an account
       // delete all but N projects (where N is a # of projects close to our largest user account)
}

I have the log in code, and I can write the delete code... but how do I ramp up users within the after {} hook?

Is that even doable? Every example I've seen of the after{} hook (very few) has been something simple like printing text that the test is complete or something.

Thanks in advance!

You can use a global ConcurrentHashMap to store data from exec(session => session) blocks.

Then, you would be able to access this data from an after hook. But then, as explained in the doc, you won't be able to use the Gatling DSL in there. If you're dealing with REST APIs, you can directly use AsyncHttpClient, which Gatling is built upon.

Some people would also log in a file instead of in memory, and delete from a second simulation that would use this file as a feeder.

Anyway, I agree this is a bit cumbersome, but we don't currently consider that setting/cleaning up the system under test is the responsibility of the load test tool.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM