Created
June 24, 2025 15:21
-
-
Save polarnik/f0ec3dae7e81796755c7f90d2f28a469 to your computer and use it in GitHub Desktop.
ConcurrentLinkedQueue in Gatling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Slf4j | |
| public class CreateOneUser extends Simulation { | |
| { | |
| final ConcurrentLinkedQueue<Pair<String, String>> tokens = new ConcurrentLinkedQueue<>(); | |
| final int userCount = Integer.parseInt(System.getProperty("users", "1000000")); | |
| final double parallel_threads = Double.parseDouble(System.getProperty("parallel_threads", "10")); | |
| setUp( | |
| (new UserCreator().users(tokens, userCount, parallel_threads)).andThen( | |
| new TokenSaver(tokens).tokensEnd() | |
| ), | |
| new TokenSaver(tokens).tokens(userCount, parallel_threads) | |
| ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.jetbrains.youtrack.perftest.scenario.createUser; | |
| import io.gatling.http.client.util.Pair; | |
| import io.gatling.javaapi.core.CoreDsl; | |
| import io.gatling.javaapi.core.PopulationBuilder; | |
| import io.gatling.javaapi.core.ScenarioBuilder; | |
| import io.gatling.javaapi.core.Session; | |
| import lombok.extern.slf4j.Slf4j; | |
| import java.io.*; | |
| import java.time.Duration; | |
| import java.util.concurrent.ConcurrentLinkedQueue; | |
| import java.util.function.Function; | |
| import static io.gatling.javaapi.core.CoreDsl.exec; | |
| @Slf4j | |
| public class TokenSaver { | |
| private ConcurrentLinkedQueue<Pair<String, String>> tokens; | |
| private Function<Session, Session> saveTokens = session -> { | |
| log.info("Check tokens"); | |
| if(tokens!= null && !tokens.isEmpty()) { | |
| // ... | |
| } | |
| return session.set("token_queue_is_not_empty", (tokens != null) && !tokens.isEmpty()); | |
| }; | |
| public TokenSaver(ConcurrentLinkedQueue<Pair<String, String>> tokens) { | |
| this.tokens = tokens; | |
| } | |
| private ScenarioBuilder tokenSaver() { | |
| return CoreDsl.scenario("TokenSaver") | |
| .exec(saveTokens) | |
| ; | |
| } | |
| public PopulationBuilder tokens(Integer count, double parallel_threads) { | |
| return tokenSaver() | |
| .injectOpen(CoreDsl.rampUsers( | |
| Math.max(1, count / 200) | |
| ).during(Duration.ofSeconds(Math.max(1, Math.round(count / parallel_threads - 30))))) | |
| ; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment