Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds rideshare memory leak #2641

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions examples/golang-push/rideshare/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ services:
environment:
- REGION=us-east
- PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040
- PARAMETERS_POOL_SIZE=1000
- PARAMETERS_POOL_BUFFER_SIZE_KB=1000
- PARAMETERS_POOL_SIZE=10000
- PARAMETERS_POOL_BUFFER_SIZE_KB=10000
Comment on lines +9 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusting the sizes here will work when running locally, but in order to get these to reflect in sedemo, you'll need to update them here. There's additional knobs to tune there as well. The memory limit is 64Mi per pod, so using sizes this big would OOM those pods right away.

Of course, if this is just intended to be shown with a local version of the rideshare demo then adjusting these settings will but 👌

build:
context: .

Expand Down Expand Up @@ -35,6 +35,35 @@ services:
ports:
- '4040:4040'

us-east-ruby:
ports:
- 5000
environment:
- REGION=us-east
- COMPRESSION=low
build:
context: ./rideshare_rails
links:
- 'pyroscope'

eu-north-ruby:
ports:
- 5000
environment:
- REGION=eu-north
build:
context: ./rideshare_rails

ap-south-ruby:
ports:
- 5000
environment:
- REGION=ap-south
- COMPRESSION=high
build:
context: ./rideshare_rails


load-generator:
build:
context: .
Expand Down
3 changes: 3 additions & 0 deletions examples/golang-push/rideshare/loadgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func main() {
"us-east",
"eu-north",
"ap-south",
"us-east-ruby",
"eu-north-ruby",
"ap-south-ruby",
}
}

Expand Down
12 changes: 12 additions & 0 deletions examples/golang-push/rideshare/rideshare-mem/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ruby:3.0.1

WORKDIR /opt/app

COPY Gemfile ./Gemfile
COPY Gemfile.lock ./Gemfile.lock
# RUN bundle config set --local deployment true
RUN bundle install

COPY lib ./lib

CMD [ "ruby", "lib/server.rb" ]
12 changes: 12 additions & 0 deletions examples/golang-push/rideshare/rideshare-mem/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# gem "rails"

gem "pyroscope"
gem "sinatra", "~> 2.1"

gem "thin", "~> 1.8"
44 changes: 44 additions & 0 deletions examples/golang-push/rideshare/rideshare-mem/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
GEM
remote: https://rubygems.org/
specs:
daemons (1.4.1)
eventmachine (1.2.7)
ffi (1.16.3)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
pyroscope (0.5.10)
ffi
pyroscope (0.5.10-aarch64-linux)
ffi
pyroscope (0.5.10-arm64-darwin)
ffi
pyroscope (0.5.10-x86_64-linux)
ffi
rack (2.2.3)
rack-protection (2.1.0)
rack
ruby2_keywords (0.0.5)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.2)
rack-protection (= 2.1.0)
tilt (~> 2.0)
thin (1.8.1)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
tilt (2.0.10)

PLATFORMS
aarch64-linux
arm64-darwin-22
arm64-linux
x86_64-linux

DEPENDENCIES
pyroscope
sinatra (~> 2.1)
thin (~> 1.8)

BUNDLED WITH
2.2.22
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative '../utility/utility'

def order_bike(search_radius)
find_nearest_vehicle(search_radius, "bike")
end
5 changes: 5 additions & 0 deletions examples/golang-push/rideshare/rideshare-mem/lib/car/car.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative '../utility/utility'

def order_car(search_radius)
find_nearest_vehicle(search_radius, "car")
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative '../utility/utility'

def order_scooter(search_radius)
find_nearest_vehicle(search_radius, "scooter")
end
36 changes: 36 additions & 0 deletions examples/golang-push/rideshare/rideshare-mem/lib/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require "sinatra"
require "thin"
require "pyroscope"
require_relative 'scooter/scooter'
require_relative 'bike/bike'
require_relative 'car/car'


Pyroscope.configure do |config|
config.application_name = "ride-sharing-app-ruby"
config.server_address = "http://pyroscope:4040"
config.tags = {
"region": ENV["REGION"],
}
end

get "/bike" do
order_bike(0.4)
"<p>Bike ordered</p>"
end

get "/scooter" do
order_scooter(0.6)
"<p>Scooter ordered</p>"
end

get "/car" do
order_car(0.8)
"<p>Car ordered</p>"
end


set :bind, '0.0.0.0'
set :port, 5000

run Sinatra::Application.run!
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require "pyroscope"

def mutex_lock(n)
i = 0
start_time = Time.new
while Time.new - start_time < n * 10 do
i += 1
end
end

def check_driver_availability(n)
i = 0
start_time = Time.new
while Time.new - start_time < n / 2 do
i += 1
end

# Every 4 minutes this will artificially create make requests in eu-north region slow
# this is just for demonstration purposes to show how performance impacts show up in the
# flamegraph
current_time = Time.now
current_minute = current_time.strftime('%M').to_i
force_mutex_lock = (current_minute * 4 % 8) == 0

mutex_lock(n) if ENV["REGION"] == "eu-north" and force_mutex_lock
end

def find_nearest_vehicle(n, vehicle)
Pyroscope.tag_wrapper({ "vehicle" => vehicle }) do
i = 0
start_time = Time.new
while Time.new - start_time < n do
i += 1
end

check_driver_availability(n) if vehicle == "car"
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See https://git-scm.com/docs/gitattributes for more about git attribute files.

# Mark the database schema as having been generated.
db/schema.rb linguist-generated

# Mark any vendored files as having been vendored.
vendor/* linguist-vendored
31 changes: 31 additions & 0 deletions examples/golang-push/rideshare/rideshare_rails/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-*

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep


/public/assets

# Ignore master key for decrypting credentials and more.
/config/master.key

_git
43 changes: 43 additions & 0 deletions examples/golang-push/rideshare/rideshare_rails/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM ruby:3.1.4

# RUN apk add --no-cache --update \
# build-base \
# linux-headers \
# git \
# postgresql-dev \
# nodejs \
# yarn \
# tzdata \
# graphviz \
# gmp-dev

# RUN apk add --no-cache --update \
# sqlite-dev

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

ENV RAILS_ENV production
ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_LOG_TO_STDOUT true

COPY Gemfile /usr/src/app/
COPY Gemfile.lock /usr/src/app/

RUN bundle config --global frozen 1
RUN bundle install --without development test

COPY app /usr/src/app/app
COPY bin /usr/src/app/bin
COPY config /usr/src/app/config
COPY public /usr/src/app/public

COPY Rakefile /usr/src/app/
COPY config.ru /usr/src/app/

EXPOSE 5000

RUN rm -f tmp/pids/server.pid

CMD ["rails", "s", "-b", "0.0.0.0", "-p", "5000"]

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM golang:1.19


COPY loadgen.go ./loadgen.go
RUN go build -o /loadgen loadgen.go
CMD [ "/loadgen" ]
37 changes: 37 additions & 0 deletions examples/golang-push/rideshare/rideshare_rails/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.2", ">= 7.0.2.3"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

gem "brotli"

gem "pyroscope"

gem "pyroscope-otel"
gem 'opentelemetry-sdk', "~> 1.2.0"
gem 'opentelemetry-exporter-jaeger', '~> 0.22.0'
gem 'opentelemetry-instrumentation-rails' # it's top span is "http get" which is not super usefull for demo


# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end
Loading
Loading