简体   繁体   English

似乎无法使用 Clarifai API 为 Locust 设置任务

[英]Can't seem to set the tasks for Locust with Clarifai API

aI am trying to use Locust to do stress testing for a model I made with Clarifai's API.我正在尝试使用 Locust 对我使用 Clarifai 的 API 制作的模型进行压力测试。 I seem to have most of the stuff working but I can't seem to get the syntax of task assignment to work properly.我似乎让大部分东西都在工作,但我似乎无法让任务分配的语法正常工作。 The UI is working, the locust swarm works, I can get the stats in a csv but it isn't executing the task defined here which is the prediction being made to a custom model. UI 工作正常,蝗虫群工作,我可以在 csv 中获取统计信息,但它没有执行此处定义的任务,即对自定义模型进行的预测。

This is my function that is making the actual call.这是我进行实际调用的函数。

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)

        )

The functions being referred as ClarifaiLocust and locust_call are below被称为 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)

but I keep getting this error.但我不断收到此错误。

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

What am I doing wrong here?我在这里做错了什么?

Add abstract = True on ClarifaiLocust, otherwise Locust will try to run it as well.在 ClarifaiLocust 上添加abstract = True ,否则 Locust 也会尝试运行它。

So:所以:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM