github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/examples/python/rideshare/django/load-generator.py (about)

     1  import random
     2  import requests
     3  import time
     4  
     5  HOSTS = [
     6      'us-east',
     7      'eu-north',
     8      'ap-south',
     9  ]
    10  
    11  VEHICLES = [
    12      'bike',
    13      'scooter',
    14      'car',
    15  ]
    16  
    17  if __name__ == "__main__":
    18      print(f"starting load generator")
    19      time.sleep(15)
    20      print('done sleeping')
    21      while True:
    22          host = HOSTS[random.randint(0, len(HOSTS) - 1)]
    23          vehicle = VEHICLES[random.randint(0, len(VEHICLES) - 1)]
    24          print(f"requesting {vehicle} from {host}")
    25          try:
    26              resp = requests.get(f'http://{host}:5000/{vehicle}')
    27              resp.raise_for_status()
    28              print(f"received {resp}")
    29          except BaseException as e:
    30              print (f"http error {e}")
    31  
    32          time.sleep(random.uniform(0.2, 0.4))