Write it down while it’s hot for your future self
The foreword 0.
Recently, the project I was working on entered the stage of pressure test, and the student que who was occasionally tested said, “You can’t pass the interface pressure test index, please help to check it.” So, to put down the work at hand, to analyze the cause, analysis and analysis, the day has passed, it is time to leave, the main task is not finished, come on, start working overtime…
Although said that stress test is a test engineer job category, however, for the backend development students, on their own interface performance in advance with a rough touch bottom, and then according to the result of pressure test, targeted, logic, design, and so on in the code level optimization, not only can guarantee the smooth pressure measured by, can change passive to active, ensure project delivered more efficiently. After all, a developer who doesn’t focus on interface performance doesn’t grow into a good architect.
To do good work, you must first do good work. A good pressure measuring tool, will make our work twice the result with half the effort.
In fact, when it comes to pressure measuring tools, many people may think of Jmeter for the first time. Jmeter is a desktop pressure measuring tool based on Java, which is very powerful. However, because it is a desktop-level tool, there are problems with multi-user collaboration, such as environment installation, configuration file synchronization, local machine performance differences, and thread-based inability to truly simulate multi-user high concurrency.
So there was a need for a tool that could address these pain points, and the nGrinder was one of them.
1. What is the nGrinder
The nGrinder is an open source Web performance testing platform based on the Grinder, redesigned and refined by the development team of NHN Corporation, the largest Internet company in Korea. Features: Open source, easy to use, highly available, extensible (source)
The nGrinder consists of a controller and multiple agents connected to it. The user can manage and control the test through the Web interface and view the test report. The Controller will distribute the test to one or more agents for execution. Users can set up multiple processes and threads to execute the script concurrently, and to execute the test script repeatedly in the same thread to simulate many concurrent users.
The Agent can be deployed on multiple or multiple machines. All agents are connected to a single controller. The agent can be likened to a Kubernetes node, and the Controller to a master node
The testing for the nGrinder is based on a Python or Groovy test script. After the user writes the test script according to certain rules, the controller distributes the script and other files required to the Agent for execution. And in the execution process to collect the running status, response time, test target server running status, etc. And save this data to generate run reports for later review.
2. Install
Overview: This installation is based on the Ubuntu operating system. There are two virtual machines. Install the Controller on one of the virtual machines, and install an Agent on each of the two virtual machines
2.1 Environment Preparation
- The IP addresses of two virtual machines are:
192.168.0.1
和192.168.0.2
192.168.0.1
Can be achieved byssh key
Implement password-free login to192.168.0.2
On.- installed
docker
anddocker-compose
- installed
ansible
2.2 Necessary Documents
2.2.1 docker-compose-controller.yml
ngrinder-controller:
image: ngrinder/controller
container_name: ngrinder-controller
hostname: ngrinder-controller
ports:
- 40080:80
- 16001:16001
- 12000-12009:12000-12009
volumes:
- /data/workspace/docker-install/ngrinder/controller:/opt/ngrinder-controller
Copy the code
2.2.2 docker-compose-agent.yml
ngrinder-agent-1: image: ngrinder/agent container_name: ngrinder-agent-1 hostname: ngrinder-agent-1 volumes: - /data/workspace/docker-install/ngrinder/agent-1:/opt/ngrinder-agent command: - 192.168.0.1:40080 # Access the controller of the nGrinder through port 40080Copy the code
2.2.3 ngrinder-install-playbook.yml
- hosts: all remote_user: root tasks: - name: create ngrinder path shell: mkdir -p /data/workspace/docker-install/ngrinder/docker-compose - hosts: ngrinder-master remote_user: root tasks: - name: copy docker-compose controller yaml file copy: src=./docker-compose-controller.yml dest=/data/workspace/docker-install/ngrinder/ owner=root group=root - name: run ngrinder controller shell: docker-compose -f /data/workspace/docker-install/ngrinder/docker-compose-controller.yml up -d - hosts: ngrinder-nodes remote_user: root tasks: - name: copy docker-compose agent yaml file copy: src=./docker-compose-agent.yml dest=/data/workspace/docker-install/ngrinder/ owner=root group=root - name: Modify agent yML file # This is mainly to replace the hostname of each agent with the hostname of each virtual machine, because if the hostname of each agent is consistent, only the CPU occupied by one agent during pressure measurement can be seen on the WEB page. Shell: 'sed -i "s/hostname: ngrinder-agent-1/hostname: $(hostname)-1-ngrinder-agent/g" /data/workspace/docker-install/ngrinder/docker-compose-agent.yml' - name: run ngringer agent shell: docker-compose -f /data/workspace/docker-install/ngrinder/docker-compose-agent.yml up -dCopy the code
2.2.4 /etc/ansible/hosts
Edit /etc/ansible/hosts and add the following code:
[ngrinder-master] 192.168.0.1 [ngrinder- Nodes] 192.168.0.1 192.168.0.2Copy the code
2.3 One-Sentence Installation
Yml, ngrind-install-playbook. yml, and ngrind-install-playbook. yml in the same folder, go to this folder, run:
$ ansible-playbook ngrinder-install-playbook.yml
Copy the code
Returns:
PLAY [all] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *********************************************** TASK [Gathering Facts] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ok: [192.168.0.1] ok: [192.168.0.2] TASK [create ngrinder path] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ****************************** [WARNING]: Consider using the file module with state=directory rather than running mkdir. If you need to use command because file is insufficient you can add warn=False to this command task or set command_warnings=False in ansible.cfg to get rid of Changed: [192.168.0.1] changed: [192.168.0.2] PLAY [ngrinder - master] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *********************************** TASK [Gathering Facts] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *********************************** ok: [192.168.0.1] TASK [copy docker-compose controller yaml file] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ********** ok: [192.168.0.1] TASK [Run ngrinder Controller] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *************************** changed: [192.168.0.1] PLAY [ngrinder - nodes] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ************************************ TASK [Gathering Facts] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ok: [192.168.0.2] ok: [192.168.0.1] TASK [copy docker-compose agent yaml file] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * changed: [192.168.0.1] changed: [192.168.0.2] TASK [modify agent yML file] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ***************************** [WARNING]: Consider using the replace, lineinfile or template module rather than running sed. If you need to use command because replace, lineinfile or template is insufficient you can add warn=False to this command task or set command_warnings=False in CFG to get rid of this message. Changed: [192.168.0.1] changed: [192.168.0.2] TASK [Run ngringer agent] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * changed: [192.168.0.1] changed: [192.168.0.2] PLAY RECAP * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 192.168.0.1: ok = 9 changed = 5 unreachable = 0 failed = 0 192.168.0.2: ok=6 changed=4 unreachable=0 failed=0Copy the code
The installation is successful.