应用程序负载均衡器
Frequently used terms in this article:
本文中的常用术语:
- server: a single server where our application is running (or) a setup with multiple servers where our application is running.
服务器: 运行我们的应用程序的单个服务器(或运行我们的应用程序的多个服务器的设置)。 - client: a server that is used for firing/sending requests to our application.
客户端: 用于向我们的应用触发/发送请求的服务器。
(Why Load testing?)
Load testing is the process of putting load (user requests) and then checking the response of your application(under test). It is performed to check the system’s behavior under defined load and the peak load conditions.
负载测试是以下过程:先放置负载(用户请求),然后检查应用程序的响应(被测)。 它用于检查系统在定义的负载和峰值负载条件下的行为。
This testing usually helps in identifying -
此测试通常有助于确定-
- The maximum operating capacity of an application.
- Determine whether the current infrastructure is sufficient to run the application.
- Sustainability of application for peak user load.
- Number of concurrent users that an application can support, and scalability to allow more users to access it.
(What problems does it help us solve?)
Prevent the slow performance or even shutdown of the website during a high load.
防止在高负载下网站性能下降甚至关闭。
(Long load time)
The load test tells you how long it takes the pages to load at different traffic levels. You will get metrics on website speed during normal, peak, and overwhelming traffic load.
负载测试会告诉您页面在不同流量级别加载需要多长时间。 您将在正常,高峰和压倒性的流量负载下获得有关网站速度的指标。
(Poor response time)
Response time is a time a system takes to respond to a user’s requests. Load testing will help you to establish what causes delays in response time and optimize your system accordingly.
响应时间是系统响应用户请求所花费的时间。 负载测试将帮助您确定导致响应时间延迟的原因并相应地优化系统。
(Poor scalability)
Scalability is the capacity of the app to perform different tasks at the same time. As the number of your users grows, your app must be capable of processing a larger number of requests rapidly, without slowing down the overall performance. Load testing helps you determine whether your application scales when a load grows.
可扩展性是应用程序同时执行不同任务的能力。 随着用户数量的增长,您的应用必须能够快速处理大量请求,而又不降低整体性能。 负载测试可帮助您确定负载增加时是否可扩展应用程序。
(Bottlenecks)
There are a lot of types of performance bottlenecks that occur during software development and maintenance. These bottlenecks could be
在软件开发和维护过程中会发生很多类型的性能瓶颈。 这些瓶颈可能是
- CPU utilization
- Memory utilization
- Network utilization
- Software limitation
- Disk usage
- Hardware configuration of the system
Load testing enables us in fixing these bottlenecks before the end-user faces them.
负载测试使我们能够在最终用户面对这些瓶颈之前解决这些瓶颈。
(Identify problems before the release)
- The maximum operating capacity of an application.
- Determine whether the current infrastructure is sufficient to run the application or not.
- Response time of transactions during peak load.
- Number of concurrent users that an application can support, and scalability to allow more users to access it.
- Performance of System components under various loads.
- Performance of Database components under different loads.
- Network delay between the client and the server.
- Software design issues (HLD)
- Server configuration issues like web server, application server, database server, etc.
- Hardware limitation issues like CPU maximization, memory limitations, network bottleneck, etc.
(Load testing metrics)
To estimate every aspect of your application’s performance and measure the success of load testing, the following metrics are used:
为了评估应用程序性能的各个方面并衡量负载测试的成功程度,使用了以下指标:
- Latency: the amount of time it takes to send information from one point to another. Measure 90th Percentile Response Time (Industry practices)
延迟: 从一个点到另一个点发送信息所花费的时间。 测量百分之九十的响应时间(行业惯例) - Request per second: number of requests sent to target server per second
每秒请求数:每秒发送到目标服务器的请求数 - Throughput: requests processed during the test (Requests per minute).
吞吐量:测试期间处理的请求(每分钟的请求数)。 - Errors percentage: percentage of errored requests compared to all requests.
错误百分比:错误请求相对于所有请求的百分比。 - CPU utilization: the sum of work handled by the CPU.
CPU利用率: CPU处理的总和。 - Memory utilization: the amount of RAM used by the application during testing.
内存利用率:测试期间应用程序使用的RAM数量。 - Network utilization: the amount of traffic on the network compared to the peak amount that the network can support.
网络利用率: 与网络可以支持的峰值数量相比的网络流量。 - Disk usage: the amount of storage needed for the application and its overall operation.
磁盘使用率:应用程序及其整体操作所需的存储量。
Let the testing begin.
让测试开始。
(Configuration of the client and server)
For the server, make a replica of your production environment:
对于服务器,制作生产环境的副本:
- Extrapolating load test results is a very risky business. If you run the test on a one-gigabyte machine with two cores then what will results look like on a two-gigabyte machine with four cores? It’s practically impossible to know.
- Therefore, you should replicate your production environment in every aspect: machine profile, configuration, database, network architecture, load balancer, firewalls, etc.
- One method is to create complete images of production machines to be duplicated in your test or staging environment.
For the client, you can have any micro instance.
对于客户端,您可以具有任何微实例。
(Tools for Load Testing)
I used Apache Bench for testing. You can use JMeter or any other tool in the market.
我使用Apache Bench进行测试。 您可以使用JMeter或市场上的任何其他工具。
Apache Bench — need to be installed on the client and it is used for sending requests to the server
Apache Bench —需要安装在客户端上,用于将请求发送到服务器
- Start by installing Apache Bench (AB)
install apache2-utils(or)
(要么)
yum install httpd-tools- Apache Bench (AB) usage -
ab [options] [http[s]://]hostname[:port]/pathab -n [number_of_requests_to_perform] -c [number_of_multiple_requests_to_make [http[s]://]hostname[:port]/path- Example -
ab -l -n 100 -c 10 -k -H “Accept-Encoding: gzip, deflate” http://www.example.com/- Sample Input -
- Sample output -
(Tools/commands used for measuring the server’s performance)
- top — command is used to show the Linux processes. It provides a dynamic real-time view of the running system.
top —命令用于显示Linux进程。 它提供了正在运行的系统的动态实时视图。 - htop — similar to top, but a little upgraded version.
htop-与top类似,但有一点升级。 - mpstat 1 — Used for processor related statistics and reports.
mpstat 1-用于处理器相关的统计信息和报告。 - iostat 1 — Used for CPU statistics, input/output statistics for the block devices, partitions, and generate reports.
iostat 1-用于CPU统计信息,块设备,分区的输入/输出统计信息以及生成报告。 - pidstat -G gunicorn 1 — Used for I/O, CPU, memory statistics for Linux processes and generates a report.
pidstat -G gunicorn 1-用于Linux进程的I / O,CPU,内存统计信息并生成报告。 - docker stats <docker_name>
docker统计信息<docker_name> - Metric beat — set it up on your servers and you see the visualizations on Kibana.
公制节拍 —在服务器上进行设置,然后在Kibana上看到可视化效果。
New Relic — used for measuring application performance or we can use any other APM tool.
New Relic-用于评估应用程序性能,或者我们可以使用任何其他APM工具。
You can get the following info -
您可以获得以下信息-
Response time of the api
Time spent in python (tested a python application)
Time spent in cache
Time spent in db
Time spent in external apisYou need to test with different combinations of APIs, read APIs, write APIs, etc.
您需要使用不同的API组合进行测试,读取API,写入API等。
(Load Testing Report)
A load testing report should describe these points.
负载测试报告应描述这些要点。
- Product KPIs met?
- Where is the bottleneck? Should provide areas where teams can invest to get better performance
- Is infrastructure sufficient?
- Further, invest in performance tuning? Whether to take action on the insights from bottleneck discovery should be done before the go-live or not.
(Things to discuss before the release)
I was not able to do the formatting as per my expectation, so I moved it to a gist.
我无法按照我的期望进行格式化,因此我将其移至要点。
My investigation was done on a python application with flask (framework), gunicorn (app server), nginx (webserver), MySQL (database) & everything was deployed on AWS.
我的调查是在具有Flask(框架),gunicorn(应用服务器),nginx(网络服务器),MySQL(数据库)的python应用程序上完成的,所有内容均部署在AWS上。
After working through these points and taking the necessary steps, we can say that our load testing was a success.
在完成这些要点并采取必要的步骤之后,我们可以说我们的负载测试是成功的。
翻译自: https:///swlh/how-to-load-test-your-application-c154a72968e2
应用程序负载均衡器
















