好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Jmerte分布式压测及分布式压测配置教程

1.本地基于jmeter创建压测项目

(1)pom中依赖jmeter包:

?

1

2

3

4

5

<dependency>

            <groupId>org.apache.jmeter</groupId>

            <artifactId>ApacheJMeter_java</artifactId>

             <version> 5.2 . 1 </version>

       </dependency>

(2)pom中增加打包方式

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

<build>

     <plugins>

         <plugin>

             <groupId>org.apache.maven.plugins</groupId>

             <artifactId>maven-compiler-plugin</artifactId>

             <configuration>

                 <source> 1.8 </source>

                 <target> 1.8 </target>

                 <fork> true </fork>

                 <verbose> true </verbose>

                 <encoding>UTF- 8 </encoding>

                 <compilerArguments>

                     <extdirs>${project.basedir}/lib</extdirs>

                 </compilerArguments>

             </configuration>

         </plugin>

         <plugin>

             <groupId>org.apache.maven.plugins</groupId>

             <artifactId>maven-war-plugin</artifactId>

             <configuration>

                 <webResources>

                     <resource>

                         <!--配置本地jar包在项目中的存放路径-->

                         <directory>${project.basedir}/lib</directory>

                         <!--配置打包时jar包的存放路径-->

                         <targetPath>${project.basedir}/lib</targetPath>

                         <includes>

                             <include>**/*.jar</include>

                         </includes>

                     </resource>

                 </webResources>

             </configuration>

         </plugin>

         <plugin>

             <groupId>org.apache.maven.plugins</groupId>

             <artifactId>maven-surefire-plugin</artifactId>

             <configuration>

                 <!-- 忽略测试 -->

                 <skip> false </skip>

             </configuration>

         </plugin>

         <plugin>

             <groupId>org.apache.maven.plugins</groupId>

             <artifactId>maven-jar-plugin</artifactId>

             <configuration>

                 <archive>

                     <manifestEntries>

                         <Rose>*</Rose>

                     </manifestEntries>

                 </archive>

             </configuration>

         </plugin>

         <plugin>

             <groupId>org.apache.maven.plugins</groupId>

             <artifactId>maven-dependency-plugin</artifactId>

             <executions>

                 <execution>

                     <id>copy-dependencies</id>

                     <phase>prepare- package </phase>

                     <goals>

                         <goal>copy-dependencies</goal>

                     </goals>

                     <configuration>

                         <outputDirectory>${project.build.directory}/lib</outputDirectory>

                         <overWriteReleases> false </overWriteReleases>

                         <overWriteSnapshots> false </overWriteSnapshots>

                         <overWriteIfNewer> true </overWriteIfNewer>

                     </configuration>

                 </execution>

             </executions>

         </plugin>

         <plugin>

             <groupId>org.apache.maven.plugins</groupId>

             <artifactId>maven-assembly-plugin</artifactId>

             <version> 2.5 . 5 </version>

             <configuration>

                 <descriptorRefs>

                     <descriptorRef>jar-with-dependencies</descriptorRef>

                 </descriptorRefs>

             </configuration>

         </plugin>

     </plugins>

</build>

(3)编写压测脚本:

继承AbstractJavaSamplerClient,并实现runTest方法。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

public class StessTest extends AbstractJavaSamplerClient {

     @Override

     public void setupTest(JavaSamplerContext javaSamplerContext) {

     }

     @Override

     @SneakyThrows

     public SampleResult runTest(JavaSamplerContext javaSamplerContext) {

         SampleResult sampleResult = new SampleResult();

         try {

             sampleResult.sampleStart();

             String result= 请求接口;

             sampleResult.setResponseData(result, "UTF-8" );

             sampleResult.setSuccessful( false );

             TimeUnit.SECONDS.sleep(1L);

         } catch (Exception e) {

             e.printStackTrace();

             sampleResult.setResponseData(e.getLocalizedMessage(), "UTF-8" );

             sampleResult.setResponseCode(e.getMessage());

             sampleResult.setSuccessful( false );

         } finally {

             sampleResult.sampleEnd();

         }

         return sampleResult;

     }

     @Override

     public void teardownTest(JavaSamplerContext javaSamplerContext) {

             super .teardownTest(javaSamplerContext);

     }

     @Override

     public Arguments getDefaultParameters() {

         return null ;

     }

2.将项目打包

将本地maven测试项目打成jar包:

?

1

mvn -U clean insall package

打包完后,有两个地方的包:target\lib、target下面的包

首先本地调试压测脚本是否生效

(1) 创建一个线程组:

 这里可以配置线程组名称,线程数,准备时长、循环次数,调度器等参数

(2)创建java请求

 选好测试的方法,本地执行一下,看可以跑通后,去远程机器压测。

确定好Master和Slave机器,及被压测服务所在的机器。且master机器 及slave机器上都配置相同版本的jmeter。

将项目依赖的jar包都放到slave机器 jmeter\lib\ext路径下面。

3.Master配置

编辑$JMETER_HOME/bin/jmeter.properties文件

分别配置remote_hosts,和server.rmi.ssl.disable,端口号

?

1

2

3

4

server.rmi.ssl.disable= true

server.rmi.localport=1099

server_port=1099

remote_hosts=ip1,ip2,ip3,ip4,ip5,ip6

4.Slave配置

(1)所有的slave机器上对应修改 $JMETER_HOME/bin/jmeter.properties文件

?

1

server.rmi.ssl.disable= true

(2)所有的slave机器需要在$JMETER_HOME/lib/ext下放压测脚本依赖的jar包

5.启动Slave

每台slave机器上都启动jmeter

直接启动

?

1

$JMETER_HOME /bin/jmeter-server

或者指定机器的ip启动(建议指定ip启动)

jmeter-server -Djava.rmi.server.hostname=xxx (机器的ip地址)

6.master启动压测

onlinePressTest.jmx 是用界面版jmeter生成的一个线程组,保存下来,放到master机器上

运行压测脚本:

?

1

jmeter -n -r -t onlinePressTest.jmx -l stressTest.jtl -e -o webStressTest

7查看报告

stressTest.jtl 是压测结果,可以导出到本地,使用jmeter打开,获取报告

到此这篇关于Jmerte分布式压测,及分布式压测配置的文章就介绍到这了,更多相关Jmerte分布式压测内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

原文链接:https://blog.csdn.net/sarah0619/article/details/124481032

查看更多关于Jmerte分布式压测及分布式压测配置教程的详细内容...

  阅读:20次