diff --git a/frameworks/rack-agoo/Dockerfile b/frameworks/rack-agoo/Dockerfile new file mode 100644 index 000000000..cbcea2d8d --- /dev/null +++ b/frameworks/rack-agoo/Dockerfile @@ -0,0 +1,27 @@ +FROM ruby:4.0.6-slim + +RUN apt-get update && \ + apt-get install -y --no-install-recommends build-essential libpq-dev libjemalloc2 && \ + rm -rf /var/lib/apt/lists/* + +# Use Jemalloc +ENV LD_PRELOAD=libjemalloc.so.2 + +ENV RUBY_YJIT_ENABLE=1 +ENV RUBY_MN_THREADS=1 +ENV RACK_ENV=production +# Negative values are fractions of CPU cores +ENV WORKERS=-1 +ENV THREADS=1 + +WORKDIR /app + +COPY Gemfile* . +RUN bundle config set deployment 'true' +RUN bundle install --jobs=$(nproc) + +COPY . . + +EXPOSE 8080 + +CMD ["ruby", "app.rb"] diff --git a/frameworks/rack-agoo/Gemfile b/frameworks/rack-agoo/Gemfile new file mode 100644 index 000000000..81f76c9be --- /dev/null +++ b/frameworks/rack-agoo/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'agoo' +gem 'rack' diff --git a/frameworks/rack-agoo/Gemfile.lock b/frameworks/rack-agoo/Gemfile.lock new file mode 100644 index 000000000..b75f105de --- /dev/null +++ b/frameworks/rack-agoo/Gemfile.lock @@ -0,0 +1,20 @@ +GEM + remote: https://rubygems.org/ + specs: + agoo (2.15.15) + rack (3.2.7) + +PLATFORMS + arm64-darwin-24 + ruby + +DEPENDENCIES + agoo + rack + +CHECKSUMS + agoo (2.15.15) sha256=5781d0894c1b8edf622988a2211874439724b2ae1661ff7a3979a3ac66770421 + rack (3.2.7) sha256=93e13e1c24f93556671d85d2d79fa228c3485815c50d7e2f265b5330c6528fb7 + +BUNDLED WITH + 4.0.8 diff --git a/frameworks/rack-agoo/app.rb b/frameworks/rack-agoo/app.rb new file mode 100644 index 000000000..542e1e751 --- /dev/null +++ b/frameworks/rack-agoo/app.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'bundler/setup' +Bundler.require(:default) # Load core modules + +require 'uri' + +class BaseHandler + CONTENT_TYPE = 'Content-Type' + PLAINTEXT_TYPE = 'text/plain' + + private + + def render_plain(body) + [200, {CONTENT_TYPE => PLAINTEXT_TYPE}, [body]] + end +end + +class PipelineHandler < BaseHandler + def call(env) + render_plain 'ok' + end +end + +class Baseline11Handler < BaseHandler + def call(env) + params = URI.decode_www_form(env['QUERY_STRING']).to_h + total = params['a'].to_i + params['b'].to_i + if env['REQUEST_METHOD'] == 'POST' + body = env["rack.input"]&.read + total += body.to_i + end + render_plain total.to_s + end +end + +class Baseline2Handler < BaseHandler + def call(env) + params = URI.decode_www_form(env['QUERY_STRING']).to_h + total = params['a'].to_i + params['b'].to_i + render_plain total.to_s + end +end + +# Disable logging +Agoo::Log.configure( + console: false, + dir: '', + states: { + ERROR: false, + WARN: false, + INFO: false, + DEBUG: false, + connect: false, + request: false, + response: false, + eval: false, + push: false + } +) + +Agoo::Server.init(8080, '.', thread_count: 0) + +Agoo::Server.handle :GET, '/pipeline', PipelineHandler.new +Agoo::Server.handle :GET, '/baseline11', Baseline11Handler.new +Agoo::Server.handle :POST, '/baseline11', Baseline11Handler.new +Agoo::Server.handle :GET, '/baseline2', Baseline2Handler.new + +Agoo::Server.start diff --git a/frameworks/rack-agoo/meta.json b/frameworks/rack-agoo/meta.json new file mode 100644 index 000000000..eebf9948d --- /dev/null +++ b/frameworks/rack-agoo/meta.json @@ -0,0 +1,17 @@ +{ + "display_name": "agoo", + "language": "Ruby", + "type": "engine", + "engine": "agoo", + "description": "A High Performance HTTP Server for Ruby", + "repo": "https://github.com/ohler55/agoo", + "enabled": true, + "tests": [ + "baseline", + "latency-1m", + "latency-10k", + "pipelined", + "limited-conn" + ], + "maintainers": ["p8"] +}