我正在尝试使用Locust对使用Clarifai API创建的模型进行压力测试。我似乎大部分工作都在工作,但似乎无法使任务分配的语法正常工作。 UI在起作用,蝗虫群在起作用,我可以在csv中获取统计信息,但是它没有执行此处定义的任务,这是对自定义模型的预测。
这是我进行实际通话的功能。
import gevent
from gevent import monkey
monkey.patch_all()
from clarifai.rest import ClarifaiApp, Workflow
import random
from locust import task, TaskSet, between, User
import app_settings. #contains some hardcoded values as a script.
from locust_utils import ClarifaiLocust, locust_call
class ApiUser(ClarifaiLocust):
min_wait = 1000
max_wait = 3000
wait_time = between(2,5)
def on_start(self):
# self.small_model = self.client.get_app('model-specialization-demo-pt2').workflows.get('locust-vehicle-det')
self.small_model = self.client.get_app('app_id').workflows.get('locust-vehicle-det')
@task
def predict_small_model(self):
locust_call(
self.small_model.predict_by_url,
'predict to Public Vehicle Detector',
url=random.choice(app_settings.small_app_urls)
)
下面称为ClarifaiLocust和locust_call的函数
def locust_call(func, name, *args, **kwargs):
start_time = time.time()
try:
func(*args, **kwargs) # Don't really care about results for stress test
except ApiError as e:
total_time = int((time.time() - start_time) * 1000)
events.request_failure.fire(
request_type='Client', name=name, response_time=total_time, exception=e)
else:
total_time = int((time.time() - start_time) * 1000)
events.request_success.fire(
request_type='Client', name=name, response_time=total_time, response_length=0)
class ClarifaiLocust(HttpUser):
test_app = None
search_app = None
wait_time = between(2,5)
def __init__(self, *args, **kwargs):
# Locust.__init__(self, *args, **kwargs)
User.__init__(self, *args, **kwargs)
#super(ClarifaiLocust, self).__init__(*args, **kwargs)
self.client = ClarifaiUser(self.host)
但我一直收到此错误。
raise Exception("No tasks defined. use the @task decorator or set the tasks property of the User")
Exception: No tasks defined. use the @task decorator or set the tasks property of the User
我在做什么错了?
答案 0 :(得分:0)
在ClarifaiLocust上添加abstract = True
,否则Locust也会尝试运行它。
所以:
class ClarifaiLocust(HttpUser):
abstract = True
....