51
loading...
This website collects cookies to deliver better user experience
server.rb
:/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 do |config|
config.app_name = "ride-sharing-app"
config.server_address = "http://pyroscope:4040"
config.tags = {
"region": ENV["REGION"], # Tags the region based of the environment variable
}
end
vehicle
tag can be done inside our utility find_nearest_vehicle()
function using a Pyroscope.tag_wrapper
blockdef find_nearest_vehicle(n, vehicle)
Pyroscope.tag_wrapper({ "vehicle" => vehicle }) do
...code to find nearest vehicle
end
end
{ "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. 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.mutex_lock()
function is consuming almost 70% of CPU resources during this time period. mutex_lock()
function where it takes 23% of CPU during low-cpu times and 70% of CPU during high-cpu times.