似乎无法使用 Clarifai 为 Locust 设置任务 API
Can't seem to set the tasks for Locust with Clarifai API
a我正在尝试使用 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
我做错了什么?
在 ClarifaiLocust 上添加 abstract = True
,否则 Locust 也会尝试 运行 它。
所以:
class ClarifaiLocust(HttpUser):
abstract = True
....
a我正在尝试使用 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
我做错了什么?
在 ClarifaiLocust 上添加 abstract = True
,否则 Locust 也会尝试 运行 它。
所以:
class ClarifaiLocust(HttpUser):
abstract = True
....