locust 做web测试
# -*- coding:utf-8 -*-
# @Time : 2021/1/12 9:34
# @Author : liu_w
# @File : web_testing
# @Function : 业务说明
from locust import HttpUser, task, between
# http://localhost:8089/
class QuickstartUser(HttpUser):
wait_time = between(1, 2)
host = 'http://127.0.0.1:10001/'
@task(1)
def hello_world(self):
self.client.get("/")
# if __name__ == '__main__':
# os.system("locust -f locusttest.py")
命令行 locust -f locusttest.py
打开 http://localhost:8089/
即可 看到测试页面
填入信息即可开始测试
nginx如何实现负载均衡
1、Nginx的负载分发策略 Nginx 的 upstream目前支持的分配算法:
1)、轮询 ——1:1 轮流处理请求(默认) 每个请求按时间顺序逐一分配到不同的应用服务器,如果应用服务器down掉,自动剔除,剩下的继续轮询。
2)、权重 ——you can you up
通过配置权重,指定轮询几率,权重和访问比率成正比,用于应用服务器性能不均的情况。
3)、ip_哈希算法
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个应用服务器,可以解决session共享的问题。
upstream tomcatserver1 {
server 192.168.72.49:8080 weight=3;
server 192.168.72.49:8081;
}
server {
listen 80;
server_name 8080.max.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcatserver1;
index index.html index.htm;
}
}
https://www.jianshu.com/p/4c250c1cd6cd
worker_processes 1;
events {
worker_connections 1024;}
http {
upstream dalaoyang-server {
server localhost:10001;
server localhost:10002;
}
server {
listen 10000;
server_name localhost;
location / {
proxy_pass http://dalaoyang-server;
proxy_redirect default;
}
}
}
依赖
pip3 install pipreqs
pipreqs ./ --encoding=utf-8
https://blog.csdn.net/dingfei8574/article/details/101900326?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control
asyncio.set_event_loop(uvloop.new_event_loop())
server = app.create_server(host=“0.0.0.0”, port=8000)
loop = asyncio.get_event_loop()
loop.set_task_factory(context.task_factory)
task = asyncio.ensure_future(server)
try:
loop.run_forever()
except:
loop.stop()
https://www.cnblogs.com/ljc-0923/p/10392092.html