一些留念。
Gatling - Simulation
A simulation is a description of the load test. It describes how, possibly several, user populations will run: which scenario they will execute and how new virtual users will be injected.
A Simulation is a real Scala class containing 4 different parts:
- The HTTP protocol configuration
- The headers definition
- The scenario definition
- The simulation definition
Can see the demo there: Recoder Demo
Hooks
Gatling provides two hooks:
- before
for executing some code before the simulation actually runs - after
for executing some code after the simulation actually runs
Spring Boot - 更换banner
Spring boot 有自己的banner, 但是也可以设置使用自定制的, 只要在自己的项目中新加:/springboot/src/main/resources/banner.txt。
利用这个网站生成字符Patorjk,我们可以利用生成的字符串放入这个banner.txt文件。
Spring Boot - 介绍和环境搭建
介绍
Spring Boot简化了基于Spring的应用开发,你只需要”run”就能创建一个独立的,产品级别的Spring应用。话不多说,直接参见官网Spring Boot
环境
安装JDK
java -version
- 检查Java安装
安装后添加环境变量。安装Maven
我的是Windows,方法如下:
Adding to PATH: Add the unpacked distribution’s bin directory to your user PATH environment variable by opening up the system properties (WinKey + Pause), selecting the “Advanced” tab, and the “Environment Variables” button, then adding or selecting the PATH variable in the user variables with the value C:\Program Files\apache-maven-3.5.0\bin. The same dialog can be used to set JAVA_HOME to the location of your JDK, e.g. C:\Program Files\Java\jdk1.7.0_51
Open a new command prompt (Winkey + R then type cmd) and run mvn -v to verify the installation.新建文件夹作为Project根目录,创建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<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>myFirstproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!-- Add Spring repositories -->
<!-- (you don't need this if you are using a .RELEASE version) -->
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>
Gatling - install & start
基于Scala 开发的开源免费性能压测工具。主要用于测量基于HTTP的服务器,比如Web应用程序,RESTful服务等。
方方面面的原因,准备用Gatling做性能测试,对这个工具做一个简单的研究。
Install
去官网下载: http://gatling.io/download/
下载之后,解压到相应的目录中去。
- bin 目录下有2个脚本,gatling和recorder, gatling用来运行测试, recorder用来启动录制脚本的UI的。
- conf 目录是关于Gatling自身的一些配置。
- lib 目录是Gatling自身依赖的库文件。
- results 目录用来存放测试报告的。
- target
- user-files
- bodies
- data 数据目录,csv参数文件存放在这里
- simulations 测试脚本(所有的脚本都在这里)
Recorder
运行bin目录下的’recorder.bat’,打开Recorder Window。
录制之前要先设置浏览器用Gatling Recorder’s proxy,录制之后,保存脚本。录制一个搜索:
1 | package default |
录制功能应该一般都不太会用到。
Uploading a file using python requests
List here just for a reminder:
1 | url = "http://34.207.223.236" |
requests will send a multi-part form POST body with the upload_file field set to the contents of the a.csv file.
python json dump/load/dumps/loads
load
从外部JSON文件变成dict字典(外部文件一定要是json格式)json.load(open('a.json',"r"))
dump
把dict字典变成json格式,生成到外部文件里面json.dump(dict,open('a.json',"w"))
dumps
Convert Python Object (Dict) to JSON
1 | import json |
loads
To convert JSON to a Python dict use this:
1 | import json |