Skip to content
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
16 changes: 0 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read
services:
redis:
image: redis # zizmor: ignore[unpinned-images] -- version tag is fine for service containers
ports:
- 6379:6379
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Install packages
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y libsqlite3-0 sqlite3 libvips curl ffmpeg
Expand All @@ -111,8 +105,6 @@ jobs:

- name: Set up Ruby
uses: ruby/setup-ruby@f9c4492e86def3e644ab32a0ef185eda5b0c20d0 # v1.342.0
env:
REDIS_URL: redis://localhost:6379/0
with:
ruby-version: .ruby-version
bundler-cache: true
Expand All @@ -127,12 +119,6 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read
services:
redis:
image: redis # zizmor: ignore[unpinned-images] -- version tag is fine for service containers
ports:
- 6379:6379
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Install packages
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y libsqlite3-0 sqlite3 libvips curl ffmpeg
Expand All @@ -144,8 +130,6 @@ jobs:

- name: Set up Ruby
uses: ruby/setup-ruby@f9c4492e86def3e644ab32a0ef185eda5b0c20d0 # v1.342.0
env:
REDIS_URL: redis://localhost:6379/0
with:
ruby-version: .ruby-version
bundler-cache: true
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WORKDIR /rails

# Install base packages
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 libvips libjemalloc2 ffmpeg redis && \
apt-get install --no-install-recommends -y curl libsqlite3-0 libvips libjemalloc2 ffmpeg && \
ln -s /usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2 /usr/local/lib/libjemalloc.so && \
rm -rf /var/lib/apt/lists /var/cache/apt/archive

Expand Down
9 changes: 5 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ gem "benchmark"

# Drivers
gem "sqlite3"
gem "redis", "~> 5.4"

# Caching
gem "solid_cache", "~> 1.0.10"

# Deployment
gem "puma", "~> 8.0"

# Jobs
gem "resque", "~> 2.7.0"
gem "resque-pool", "~> 0.7.1"
gem "solid_queue", "~> 1.7.2"

# Assets
gem "propshaft", github: "rails/propshaft"
Expand All @@ -25,6 +26,7 @@ gem "importmap-rails", github: "rails/importmap-rails"
# Hotwire
gem "turbo-rails", github: "hotwired/turbo-rails"
gem "stimulus-rails"
gem "solid_cable", "~> 4.1"

# Rich text
gem "lexxy", "~> 0.9.24"
Expand All @@ -44,7 +46,6 @@ gem "rails_autolink"
gem "geared_pagination"
gem "jbuilder"
gem "surfguard", github: "basecamp/surfguard" # The SSRF address policy behind RestrictedHTTP
gem "kredis"
gem "platform_agent"
gem "thruster"

Expand Down
63 changes: 25 additions & 38 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,18 @@ GEM
drb (2.2.3)
erb (6.0.7)
erubi (1.13.1)
et-orbi (1.4.2)
tzinfo
faker (3.8.0)
i18n (>= 1.8.11, < 2)
ffi (1.17.2)
ffi (1.17.2-aarch64-linux-gnu)
ffi (1.17.2-arm64-darwin)
ffi (1.17.2-x86_64-darwin)
ffi (1.17.2-x86_64-linux-gnu)
fugit (1.14.0)
et-orbi (~> 1.4)
raabro (~> 1.4)
geared_pagination (1.2.0)
activesupport (>= 5.0)
addressable (>= 2.5.0)
Expand Down Expand Up @@ -209,10 +214,6 @@ GEM
json (2.21.2)
jwt (3.2.0)
base64
kredis (1.8.0)
activemodel (>= 6.0.0)
activesupport (>= 6.0.0)
redis (>= 4.2, < 6)
language_server-protocol (3.17.0.5)
lexxy (0.9.24)
rails (>= 8.0.2)
Expand All @@ -237,10 +238,6 @@ GEM
prism (~> 1.5)
mocha (3.1.0)
ruby2_keywords (>= 0.0.5)
mono_logger (1.1.2)
multi_json (1.17.0)
mustermann (3.0.4)
ruby2_keywords (~> 0.0.1)
net-imap (0.6.7)
date
net-protocol
Expand Down Expand Up @@ -278,12 +275,9 @@ GEM
public_suffix (6.0.2)
puma (8.0.3)
nio4r (~> 2.0)
raabro (1.5.0)
racc (1.8.1)
rack (3.2.8)
rack-protection (4.2.1)
base64 (>= 0.1.0)
logger (>= 1.6.0)
rack (>= 3.0.0, < 4)
rack-session (2.1.2)
base64 (>= 0.1.0)
rack (>= 3.0.0)
Expand Down Expand Up @@ -314,23 +308,9 @@ GEM
prism (>= 1.6.0)
rbs (>= 4.0.0)
tsort
redis (5.4.1)
redis-client (>= 0.22.0)
redis-client (0.30.1)
connection_pool
redis-namespace (1.11.0)
redis (>= 4)
regexp_parser (2.11.2)
reline (0.7.0)
io-console (~> 0.5)
resque (2.7.0)
mono_logger (~> 1)
multi_json (~> 1.0)
redis-namespace (~> 1.6)
sinatra (>= 0.9.2)
resque-pool (0.7.1)
rake (>= 10.0, < 14.0)
resque (>= 1.22, < 3)
rexml (3.4.4)
rqrcode (3.2.0)
chunky_png (~> 1.0)
Expand Down Expand Up @@ -383,13 +363,22 @@ GEM
sentry-ruby (5.26.0)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
sinatra (4.2.1)
logger (>= 1.6.0)
mustermann (~> 3.0)
rack (>= 3.0.0, < 4)
rack-protection (= 4.2.1)
rack-session (>= 2.0.0, < 3)
tilt (~> 2.0)
solid_cable (4.1.0)
actioncable (>= 7.2)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
solid_cache (1.0.10)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
solid_queue (1.7.2)
activejob (>= 7.1)
activerecord (>= 7.1)
concurrent-ruby (>= 1.3.1)
fugit (~> 1.11)
railties (>= 7.1)
thor (>= 1.3.1)
sqlite3 (2.10.2-aarch64-linux-gnu)
sqlite3 (2.10.2-arm64-darwin)
sqlite3 (2.10.2-x86_64-darwin)
Expand All @@ -402,7 +391,6 @@ GEM
thruster (0.1.27-arm64-darwin)
thruster (0.1.27-x86_64-darwin)
thruster (0.1.27-x86_64-linux)
tilt (2.6.1)
timeout (0.6.1)
tsort (0.2.0)
tzinfo (2.0.6)
Expand Down Expand Up @@ -446,7 +434,6 @@ DEPENDENCIES
image_processing (>= 1.2)
importmap-rails!
jbuilder
kredis
lexxy (~> 0.9.24)
mocha
ostruct
Expand All @@ -455,14 +442,14 @@ DEPENDENCIES
puma (~> 8.0)
rails!
rails_autolink
redis (~> 5.4)
resque (~> 2.7.0)
resque-pool (~> 0.7.1)
rqrcode
rubocop-rails-omakase
selenium-webdriver
sentry-rails
sentry-ruby
solid_cable (~> 4.1)
solid_cache (~> 1.0.10)
solid_queue (~> 1.7.2)
sqlite3
stimulus-rails
surfguard!
Expand Down
3 changes: 1 addition & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
web: bundle exec thrust bin/start-app
redis: redis-server config/redis.conf
workers: FORK_PER_JOB=false INTERVAL=0.1 bundle exec resque-pool
workers: bundle exec bin/jobs
2 changes: 1 addition & 1 deletion app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def destroy_later

# Deleting the memberships skips the reset that revoking one does, so the former members get it here, all at once,
# before the messages go: their connections stop receiving the room's streams. It's done in the job, not the
# request, because it costs a Redis round trip per member.
# request, because it costs a broadcast per member.
def reset_remote_connections_of(user_ids)
User.where(id: user_ids).find_each(&:reset_remote_connections)
end
Expand Down
3 changes: 2 additions & 1 deletion bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ ruby bench/compare_http.rb --baseline PATH --seed SEED --paths sidebar,search --

Both drivers alternate before/after order and reset fixture storage for each run.
Results default to ignored `tmp/rails-optimization/results/`; override with `--output PATH`.
Use `--image` to override `campfire-reference:app`, and `--cpus` to override server CPUs
Use `--image` to override `campfire-reference:app`, `--baseline-image` when the baseline needs
another bundle, and `--cpus` to override server CPUs
`8-11`. HTTP clients use CPUs `12-15` by default (`--client-cpus`). `--help` lists options.

The rendering probe checks exact response bodies, selected headers and unread payloads,
Expand Down
2 changes: 1 addition & 1 deletion bench/compare_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
command.concat environment(RAILS_ENV: "production", SECRET_KEY_BASE: "isolated-benchmark-fixture-key", DISABLE_SSL: true,
SKIP_TELEMETRY: true, RAILS_LOG_LEVEL: "fatal", WEB_CONCURRENCY: 1, JOB_CONCURRENCY: 1, RAILS_MAX_THREADS: 5,
REDIS_URL: "redis://#{redis}:6379/0")
command.concat [ options[:image], "bundle", "exec", "puma", "-C", "config/puma.rb" ]
command.concat [ options[side == "before" ? :baseline_image : :image], "sh", "-c", "bin/rails db:prepare && exec bundle exec puma -C config/puma.rb" ]
run(*command)
deadline = clock + 45
until client.ready?
Expand Down
2 changes: 1 addition & 1 deletion bench/compare_message_hot_paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
File.join(options[:seed], "labels.json") => "/bench-labels.json")
command.concat environment(RAILS_ENV: "production", SECRET_KEY_BASE: "isolated-benchmark-fixture-key", DISABLE_SSL: true,
SKIP_TELEMETRY: true, RAILS_LOG_LEVEL: "fatal", BENCH_LABELS: "/bench-labels.json")
command.concat [ options[:image], "bundle", "exec", "ruby", "-r", "/rails/config/environment.rb", "/bench/message_hot_paths.rb" ]
command.concat [ options[side == "before" ? :baseline_image : :image], "bundle", "exec", "ruby", "-r", "/rails/config/environment.rb", "/bench/message_hot_paths.rb" ]
data = JSON.parse(run(*command))
runs[side] << data
write_json(File.join(options[:output], "#{side}-#{iteration + 1}.json"), data)
Expand Down
3 changes: 2 additions & 1 deletion bench/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module BenchmarkSupport
WORK = File.join(ROOT, "tmp/rails-optimization")

def parse_options(description, defaults)
options = { baseline: nil, seed: nil, image: "campfire-reference:app", cpus: "8-11", rounds: 2 }.merge(defaults)
options = { baseline: nil, seed: nil, image: "campfire-reference:app", baseline_image: nil, cpus: "8-11", rounds: 2 }.merge(defaults)
parser = OptionParser.new do |parser|
parser.banner = "Usage: ruby #{$PROGRAM_NAME} --baseline PATH --seed PATH [options]\n#{description}"
options.each do |name, default|
Expand All @@ -26,6 +26,7 @@ def parse_options(description, defaults)
raise OptionParser::MissingArgument, "--baseline and --seed are required" unless options[:baseline] && options[:seed]
raise OptionParser::InvalidArgument, "--rounds must be even and at least 2" unless options[:rounds] >= 2 && options[:rounds].even?
%i[baseline seed output].each { |name| options[name] = File.expand_path(options.fetch(name)) }
options[:baseline_image] ||= options[:image]
options
rescue OptionParser::ParseError => error
abort "#{error.message}\n#{parser}"
Expand Down
1 change: 1 addition & 0 deletions bin/boot
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ class MonitoredProcess
end
end

system "bin/rails db:prepare", exception: true
ProcessMonitor.new("Procfile")
6 changes: 6 additions & 0 deletions bin/jobs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby

require_relative "../config/environment"
require "solid_queue/cli"

SolidQueue::Cli.start(ARGV)
22 changes: 0 additions & 22 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ app_root="$(
)"
export PATH="$app_root/bin:$PATH"

REDIS_PORT=6379
REDIS_HOST=localhost

if [ "$RAILS_ENV" = "production" ]; then
echo "RAILS_ENV is production; bailing out"
exit 1
Expand Down Expand Up @@ -45,10 +42,6 @@ step() {
return $exit_code
}

redis_running() {
nc -z "$REDIS_HOST" "$REDIS_PORT" 2>/dev/null
}

echo
gum style --foreground 214 " ) "
gum style --foreground 208 " ) \\ campfire"
Expand Down Expand Up @@ -88,21 +81,6 @@ if [[ $* == *--reset* ]]; then
fi
step "Preparing the database" rails db:prepare

# Start Redis if not running
if ! redis_running; then
if command -v docker &>/dev/null; then
if docker ps -aq -f name=campfire-redis | grep -q .; then
step "Starting Redis" docker start campfire-redis
else
step "Setting up Redis" docker run -d --name campfire-redis -p "$REDIS_PORT:$REDIS_PORT" redis:7
fi
else
echo "Couldn't start Redis"
echo "Install either docker or redis and then run this command again"
exit 1
fi
fi

# Install GitHub Actions linting tools
for tool in actionlint shellcheck zizmor; do
if ! command -v "$tool" &> /dev/null; then
Expand Down
1 change: 0 additions & 1 deletion bin/start-app
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash -e

rm -f tmp/pids/server.pid
./bin/rails db:prepare
./bin/rails server
5 changes: 0 additions & 5 deletions config/bundler-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@

ignore:
- CVE-THAT-DOES-NOT-APPLY
# resque-web advisories. Campfire doesn't mount resque-web. Remove when we move to resque 3.
- GHSA-5r7x-x5pm-94xj
- GHSA-m39q-9jm7-xp4q
- GHSA-r23w-h6cg-h95q
- GHSA-r5h4-xh93-f339
13 changes: 8 additions & 5 deletions config/cable.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
default: &default
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379" } %>
adapter: solid_cable
connects_to:
database:
writing: cable
polling_interval: 0.1.seconds
message_retention: 1.day
writer_batch_size: 4
writer_batch_delay: 0.001.seconds

development:
<<: *default
channel_prefix: campfire_development

test:
adapter: test

performance:
<<: *default
channel_prefix: campfire_performance

production:
<<: *default
channel_prefix: campfire_production
Loading