Use Jmeter to do stress testing of java code

Purpose: Test java code performance
Project build: maven 3
IDE: IDEA 2016.3
JDK: 1.7
Add jmeter dependency:
<dependency>
    <groupId>org.apache.jmeter</groupId>
    <artifactId>ApacheJMeter</artifactId>
    <version>3.1</version>
</dependency>

<dependency>
    <groupId>org.apache.jmeter</groupId>
    <artifactId>ApacheJMeter_core</artifactId>
    <version>3.1</version>
</dependency>

<dependency>
    <groupId>org.apache.jmeter</groupId>
    <artifactId>ApacheJMeter_java</artifactId>
    <version>3.1</version>
</dependency>


When testing, other third-party dependencies required by jmeter need to be placed in a separate place because there are many, so add in maven:
<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

Copy all the third-party jars that the project depends on to the lib directory.
Then run the maven package, get the jar of the project itself, and copy all the third-party jars to the lib directory,
then modify jmeter.properties, and add the following configuration (search for the configuration items and configure them to the original location)
#represents the test class to search for jmeter in this path
search_paths=D:/workspace/prev/log4j2-demo/target


# means search for third-party jars in this path
user.classpath=D:/workspace/prev/log4j2-demo/target/lib


If there are many third-party dependent jars, it is likely to cause jmeter memory overflow, so modify jmeter.bat, in
if %current_minor% LEQ "8" (
...
...
)

below, add
set PERM=-XX:PermSize=256m -XX:MaxPermSize=512m


Finally, double-click jmeter.bat to start building a test plan for testing.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326530835&siteId=291194637