locust 執行一段時間,使用者數沒減少,但是 RPS 逐漸減少,最後沒有請求

凍檸樂發表於2020-11-26

用的locust 1.3.2,也有下載最新的1.4.1都是相同的結果,檢視到使用者數一直都200,但是執行大約一個小時後,就基本沒有請求
也沒有報錯,檢視都沒有報錯,看起來就像是LOCUST使用者突然就不工作了。
看程式碼沒看出什麼問題,有大佬可以幫忙看看嗎?

# -*- coding=utf-8 -*-

import queue
from locust import HttpUser, between, TaskSet, task
from common.api_base import locust_http_client, get_now_time, create_order_id_62, current_issue, decrypt_aes_ecb, \
get_info


class ChannelTask(TaskSet):
# tasks = {GameTasks: 1, TradeTasks: 2, TerminalTasks: 1} # 其他任務,已註釋

@task(1)
def update_heartbeat_time(self):
"""對終端心跳時間進行修改"""
url = "/self/terminal/info/updateHeartbeatTime"
params = {}
locust_http_client(self, url, params, self._header, self.key)

@task(20)
def bet(self):
"""投注"""
url = "/trade/bet"
game_id = "3"
bet_info = {"betNum": "1|2|2|", "betSN": 1, "multiTimes": 1, "playTypeID": 2010, "wagerMode": 1}
t = get_now_time()
issue = self.new_issue[game_id]
order_id = create_order_id_62(self.terminal_info[1])

if not self.order_list.full():
self.order_list.put_nowait(order_id)
params = {
"betInfoList": [bet_info],
"betMoney": 200, # 投注金額,單位為分
"betTime": t, # 投注時間
"channelType": "1",
"gameId": game_id, # 遊戲編號
"issueNum": issue, # 遊戲期數,預設從資料庫獲取最新的期數
"lastIssueNum": issue, # 連續銷售多期時最後一期期號
"multiIssue": 1, # 多期期數
"operatorId": "",
"orderId": order_id, # 訂單編號
"payType": "1", # 支付方式
"userId": '',
"vip": "" # 積分卡號
}
locust_http_client(self, url, params, self._header, self.key)

@task(8)
def reverse(self):
order_id = self.order_list.get()
url = '/trade/reverse'
params = {
"operatorId": "", # 操作員
"orderId": order_id, # 訂單編號
"rollbackType": 0, # 衝正型別(0:地方衝正 1:中心衝正)
}
locust_http_client(self, url, params, self._header, self.key)

def on_start(self):
self.terminal_info = self.user.terminal_list.get()
# self.terminal_info = next(self.query_sql)
self._header = {"Content-Type": "application/json;charset=UTF-8",
'stationCode': self.terminal_info[0],
'terminalCode': self.terminal_info[1],
'uniqueId': self.terminal_info[2],
'certCode': self.terminal_info[3]}
self.order_list = queue.Queue(maxsize=5)
self.new_issue = current_issue()
header = {"Content-Type": "application/json;charset=UTF-8"}
url = "/terminal/info/getPriKey" # 獲取私鑰
params = {"stationCode": self.terminal_info[0], "terminalCode": self.terminal_info[1]}
with self.client.post(url, json=params, headers=header, verify=False, catch_response=True) as response:
re_result = response.json()
if response.status_code == 200 and re_result['code'] == 0:
response.success()
else:
response.failure("%s,%s" % (self.terminal_info[1], re_result))
self.key = decrypt_aes_ecb(re_result) # 只返回key

url = "/self/terminal/info/terminalLogin" # 登陸
params = {"terminalCertId": self.terminal_info[3], "uniqueId": self.terminal_info[2]}
locust_http_client(self, url, params, self._header, self.key)

url = "/self/terminal/info/syncTime" # 同步時間
params = {}
locust_http_client(self, url, params, self._header, self.key)


class ChannelUser(HttpUser):
wait_time = between(0.5, 1)
host = "https://10.13.1.80:9999"
tasks = [ChannelTask]
terminal_list = queue.Queue()
query_sql = get_info('terminal_cert_40130900.yaml')
for i in query_sql['info']:
terminal_list.put_nowait(i)

相關文章