24
loading...
This website collects cookies to deliver better user experience
server.py
:/bike
: calls the order_bike(search_radius)
function to order a bike/car
: calls the order_car(search_radius)
function to order a car/scooter
: calls the order_scooter(search_radius)
function to order a scooterregion
: statically tags the region of the server running the codevehicle
: dynamically tags the endpoint (similar to how one might tag a controller rails)region
, can be done in the initialization code in the config.tags
variable:pyroscope.configure(
app_name = "ride-sharing-app",
server_address = "http://pyroscope:4040",
tags = {
"region": f'{os.getenv("REGION")}', # Tags the region based off the environment variable
}
)
vehicle
tag can be done inside our utility find_nearest_vehicle()
function using a with pyroscope.tag_wrapper()
blockdef find_nearest_vehicle(n, vehicle):
with pyroscope.tag_wrapper({ "vehicle": vehicle}):
i = 0
start_time = time.time()
while time.time() - start_time < n:
i += 1
{ "vehicle" => "car" }
find_nearest_vehicle()
function{ "vehicle" => "car" }
from the application since that block is complete# Pull latest pyroscope image:
docker pull pyroscope/pyroscope:latest
# Run the example project:
docker-compose up --build
# Reset the database (if needed):
# docker-compose down
ride-sharing-app.cpu
from the dropdown, you should see a flamegraph that looks like this (below). After we give 20-30 seconds for the flamegraph to update and then click the refresh button we see our 3 functions at the bottom of the flamegraph taking CPU resources proportional to the size of their respective search_radius
parameters.order_car
function. order_car()
function is problematic. Tagging both region
and vehicle
allows us to test two good hypotheses:/car
endpoint codeorder_car()
function we automatically select that tag. Then, after inspecting multiple region
tags, it becomes clear by looking at the timeline that there is an issue with the us-west-1
region, where it alternates between high-cpu times and low-cpu times.