Search code examples
performance-testingpredictioniolocust

Test performance of predictionio


I would like to test performance of prediction phase of one algorithm using Locust.

The query of engine (REST API) looks similar to this:

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

And with java code: And with Java code:

   @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);

            ...

  }

Can anyone help me with this? Thank you very much.


Solution

  • the code you need is something like this.

    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
    

    And invoke with something like

    sudo locust --host=http://test.com -f file.py