测试性能的预测

时间:2015-12-24 03:56:33

标签: performance-testing predictionio locust

我想使用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);

            ...

  }

任何人都可以帮我吗? 非常感谢你。

1 个答案:

答案 0 :(得分: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