【问题标题】:Can't seem to set the tasks for Locust with Clarifai API似乎无法使用 Clarifai API 为 Locust 设置任务
【发布时间】:2021-01-30 14:16:38
【问题描述】:

我正在尝试使用 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

我在这里做错了什么?

【问题讨论】:

    标签: python stress-testing locust


    【解决方案1】:

    在 ClarifaiLocust 上添加 abstract = True,否则 Locust 也会尝试运行它。

    所以:

    class ClarifaiLocust(HttpUser):
        abstract = True
        ....
    

    【讨论】:

    • 这样说 class ClarifaiLocust(HttpUser, abstract=True):
    • 我应该在哪里添加 abstract =True?
    • 它是类的一个属性。更新了我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-11
    • 2013-10-09
    • 2012-03-11
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 2020-02-06
    相关资源
    最近更新 更多