| 12
 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
 
 | # locust v1.0+版本依赖python3.6from locust import HttpUser, task, constant
 import queue
 # from multiprocessing import Queue
 
 def get_txt_data():
 with open("/mnt/locust/md5sha1.txt", "r") as f:
 #data = f.read()
 data = f.readlines()
 return data
 
 def queue_data():
 queue_data = queue.Queue()  # 默认为先进先出  该队列为task_set共享
 # queue.LifoQueue(),后进先出
 lines = get_txt_data()
 for i in  lines:
 queue_data.put_nowait(i)  # put_nowait 不阻塞
 return queue_data
 
 class QuickstartUser(HttpUser):
 # 接口地址
 host="http://xxxx:8360"
 
 # 单个并发内调用间隔
 wait_time = constant(0)
 #queue_data = queue_data()
 data_q = queue_data()
 
 # @task(1)
 # def baidu_index(self):
 #     self.client.get("/")
 
 @task(1)
 def ping(self):
 #self.client.get("/ping")
 try:
 keys  = self.data_q.get()
 print(keys)
 d = {'keys': keys, 'scanner': 'AVAST,QVM,BITDEFENDER,KASPERSKY,QEX,AVE,AVIRA'}
 except queue.Empty:
 print('queue_data is empty')
 exit(0)
 r = self.client.post("/http_scanhash/scanhash.php",
 data=d)
 self.data_q.put_nowait(keys)
 print(keys,r.text)
 assert r.status_code == 200
 
 |