0

我想使用 Locust 测试一种算法的预测阶段的性能。

引擎 (REST API) 的查询类似于以下内容:

engine_client = predictionio.EngineClient(url="http://localhost:8003")
print engine_client.send_query({"items": ["10181"], "num": 50, "category": ["31","32"], "blackList":["10184"]})

使用 java 代码: 使用 Java 代码:

   @RequestMapping(value = "/bestSeller", method = RequestMethod.GET)

    public String getBestSellerProducts(

        Model model,

        @RequestParam(value = "categoryCode") String categoryCode,

        HttpServletRequest request, HttpServletResponse response)

        throws IOException {

    logger.info("getBestSellerProducts - blackList {}", blackList);

            ...

  }

谁能帮我这个?非常感谢。

4

1 回答 1

0

您需要的代码是这样的。

from locust import HttpLocust, TaskSet, task, events
from locust.stats import RequestStats

class UserBehavior(TaskSet):

def on_start(self):
    """
    Executes for each user at the start
    :return:
    """
    pass

@task
def full_cicle(self):
    """
    Full User cicle
    :return:
    """
    self.recommendation()

def recommendation(self):
    """
    Gets recommendations for user
    :return:
    """
    response = self.client.post(":8000/queries.json", json.dumps({"items": ["10"], "num": 10}),
                                headers={'Content-Type': 'application/json'},name="/recommendation")

class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait=10    # Min time between requests of each user
    max_wait=10    # Max time between requests of each user
    stop_timeout= 100  # Stopping time

并用类似的东西调用

sudo locust --host=http://test.com -f file.py 
于 2016-04-12T11:12:07.727 回答