github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/examples/ruby/rideshare/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(3)
    20      while True:
    21          host = HOSTS[random.randint(0, len(HOSTS) - 1)]
    22          vehicle = VEHICLES[random.randint(0, len(VEHICLES) - 1)]
    23          print(f"requesting {vehicle} from {host}")
    24          try:
    25              resp = requests.get(f'http://{host}:5000/{vehicle}')
    26              resp.raise_for_status()
    27              print(f"received {resp}")
    28          except BaseException as e:
    29              print (f"http error {e}")
    30  
    31          time.sleep(random.uniform(0.2, 0.4))