您可以使用locust.io从虚拟机访问文件并对此文件执行负载测试

时间:2018-01-21 18:22:42

标签: python locust

我第一次使用locust.io。我想从我在locust.io中使用get请求创建的虚拟机访问文件。我想为此请求模拟多个用户。这可以使用locust.io吗?

基本上下面的代码是我想用多个用户使用locust.io复制的代码。 这是我使用套接字的单个客户端和服务器的代码。

#server.py
import socket

port = 3335
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#host = socket.gethostname()
s.bind(('',port))
s.listen(5)

print("server Ready")

while True:
    conn,addr = s.accept()
    print("connection received from ",addr)
    data = conn.recv(2048)
    #print("server received",repr(data))
    filename=data.decode()
    f=open(filename,'rb')
    l=f.read(1024)
    while(l):
        conn.send(l)
        print('sent',repr(l))
        l=f.read(1024)
    f.close()
    print('done sending')
    #conn.send('thankyou'.encode())
    conn.close()


#client.py
import socket

port = 3335
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host = input("Enter the ip address of server")
s.connect((host,port))
file = input("Enter the filename")
s.send(file.encode())

while True:
    print("receiving data")
    data = s.recv(1024)
    print("data = ",(data))
    if not data:
        break
print("successful")
s.close()
print("connection closed")

0 个答案:

没有答案
相关问题