aI am trying to use Locust to do stress testing for a model I made with Clarifai's 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.
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
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.So: