File size: 3,158 Bytes
597500e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
Sonix-ML Performance Testing Suite
----------------------------------
This module defines the load testing scenarios for the Sonix-ML API 
hosted on Hugging Face. It simulates concurrent user behavior to 
measure system latency (P50, P90, P95) across recommendation and 
interaction endpoints.
"""

import random
from locust import HttpUser, task, between

class SonixMlTester(HttpUser):
    """
    Simulates a running shoe enthusiast interacting with the Sonix-ML ecosystem.
    
    Attributes:
        wait_time (callable): Simulates user 'think time' between 1 to 3 seconds.
        host (str): The target production environment on Hugging Face Spaces.
    """
    
    wait_time = between(1, 3)
    host = "https://sonix-ml-37851640508.asia-southeast2.run.app/"

    @task(2)
    def test_recommend_road(self):
        """
        Benchmarks the Road Recommendation endpoint.
        
        Tests the heuristic mapping logic (CC: 9) for road running preferences.
        Payload includes pace, arch type, and stability needs.
        """
        payload = {
            "pace": "Fast",
            "arch_type": "Normal",
            "strike_pattern": "Mid",
            "foot_width": "Regular",
            "season": "Summer",
            "orthotic_usage": "No",
            "running_purpose": "Race",
            "cushion_preferences": "Firm",
            "stability_need": "Neutral"
        }
        self.client.post("/recommend/road", json=payload, name="POST /recommend/road")

    @task(2)
    def test_recommend_trail(self):
        """
        Benchmarks the Trail Recommendation endpoint.
        
        This is the most computationally expensive task due to high cyclomatic 
        complexity (CC: 10) in the pre-processing logic. It validates 
        vectorization performance for complex terrain and protection features.
        """
        payload = {
            "pace": "Steady",
            "arch_type": "Flat",
            "strike_pattern": "Heel",
            "foot_width": "Wide",
            "season": "Spring & Fall",
            "orthotic_usage": "Yes",
            "terrain": "Mixed",
            "rock_sensitive": "Yes",
            "water_resistance": "Waterproof"
        }
        self.client.post("/recommend/trail", json=payload, name="POST /recommend/trail")

    @task(2)
    def test_interact(self):
        """
        Benchmarks the Interaction Logging endpoint.
        
        Simulates real-time user feedback (likes/dislikes) to evaluate 
        write-operation latency and database logging performance.
        """
        payload = {
            "user_id": 2,
            "shoe_id": "R050",
            "action_type": "like",
            "value": 1
        }
        self.client.post("/interact", json=payload, name="POST /interact")

    @task(1)
    def test_recommend_feed(self):
        """
        Benchmarks the Collaborative Filtering Home Feed.
        
        Evaluates the latency of the Neural Collaborative Filtering (NCF) 
        pipeline for generating personalized shoe feeds based on User ID.
        """
        self.client.get("/recommend/feed/2", name="GET /recommend/feed/[id]")