Browse Source

[ruby/rack] Use regular json serializer (#9394)

The regular json serializer should be about as fast as OJ, after some
recent performance improvements:
https://github.com/ruby/json/blob/master/CHANGES.md
Petrik de Heus 8 months ago
parent
commit
efef7969a0

+ 14 - 6
frameworks/Ruby/rack-sequel/Gemfile

@@ -1,13 +1,8 @@
 source 'https://rubygems.org'
 
-gem 'base64' # required by passenger on Ruby 3.4
-gem 'json', '~> 2.0'
-gem 'oj', '~> 3.14', platforms: %i[ruby mswin]
-gem 'passenger', '~> 6.0', platforms: [:ruby, :mswin], require: false
-gem 'puma', '~> 6.4', require: false
+gem 'json', '~> 2.8'
 gem 'sequel', '~> 5.0'
 gem 'rack', '~> 3.0'
-gem 'unicorn', '~> 6.1', platforms: [:ruby, :mswin], require: false
 
 group :mysql do
   gem 'jdbc-mysql', '~> 5.1', platforms: :jruby, require: 'jdbc/mysql'
@@ -19,3 +14,16 @@ group :postgresql do
   gem 'pg', '~> 1.5', platforms: [:ruby, :mswin]
   gem 'sequel_pg', '~> 1.6', platforms: :ruby, require: false
 end
+
+group :passenger do
+  gem 'base64' # required by passenger on Ruby 3.4
+  gem 'passenger', '~> 6.0', platforms: [:ruby, :mswin], require: false
+end
+
+group :puma do
+  gem 'puma', '~> 6.4', require: false
+end
+
+group :unicorn do
+  gem 'unicorn', '~> 6.1', platforms: [:ruby, :mswin], require: false
+end

+ 0 - 3
frameworks/Ruby/rack-sequel/hello_world.rb

@@ -1,8 +1,5 @@
 # frozen_string_literal: true
 
-require 'oj'
-Oj.mimic_JSON
-
 # Our Rack application to be executed by rackup
 class HelloWorld
   DEFAULT_HEADERS = {}.tap do |h|

+ 1 - 0
frameworks/Ruby/rack-sequel/rack-sequel-passenger-mri.dockerfile

@@ -11,6 +11,7 @@ RUN apt-get update && \
     apt-get install -y --no-install-recommends libjemalloc2
 ENV LD_PRELOAD=libjemalloc.so.2
 
+RUN bundle config set without 'postgresql puma unicorn'
 RUN bundle install --jobs=4 --gemfile=/rack-sequel/Gemfile
 
 # TODO: https://github.com/phusion/passenger/issues/1916

+ 1 - 0
frameworks/Ruby/rack-sequel/rack-sequel-postgres-passenger-mri.dockerfile

@@ -11,6 +11,7 @@ RUN apt-get update && \
     apt-get install -y --no-install-recommends libjemalloc2
 ENV LD_PRELOAD=libjemalloc.so.2
 
+RUN bundle config set without 'mysql puma unicorn'
 RUN bundle install --jobs=4 --gemfile=/rack-sequel/Gemfile
 
 # TODO: https://github.com/phusion/passenger/issues/1916

+ 1 - 0
frameworks/Ruby/rack-sequel/rack-sequel-postgres-unicorn-mri.dockerfile

@@ -11,6 +11,7 @@ RUN apt-get update && \
     apt-get install -y --no-install-recommends libjemalloc2
 ENV LD_PRELOAD=libjemalloc.so.2
 
+RUN bundle config set without 'mysql passenger puma'
 RUN bundle install --jobs=4 --gemfile=/rack-sequel/Gemfile
 
 ENV DBTYPE=postgresql

+ 1 - 0
frameworks/Ruby/rack-sequel/rack-sequel-postgres.dockerfile

@@ -11,6 +11,7 @@ RUN apt-get update && \
     apt-get install -y --no-install-recommends libjemalloc2
 ENV LD_PRELOAD=libjemalloc.so.2
 
+RUN bundle config set without 'mysql passenger unicorn'
 RUN bundle install --jobs=4 --gemfile=/rack-sequel/Gemfile
 
 ENV DBTYPE=postgresql

+ 1 - 0
frameworks/Ruby/rack-sequel/rack-sequel-unicorn-mri.dockerfile

@@ -11,6 +11,7 @@ RUN apt-get update && \
     apt-get install -y --no-install-recommends libjemalloc2
 ENV LD_PRELOAD=libjemalloc.so.2
 
+RUN bundle config set without 'postgresql passenger puma'
 RUN bundle install --jobs=4 --gemfile=/rack-sequel/Gemfile
 
 ENV DBTYPE=mysql

+ 1 - 0
frameworks/Ruby/rack-sequel/rack-sequel.dockerfile

@@ -11,6 +11,7 @@ RUN apt-get update && \
     apt-get install -y --no-install-recommends libjemalloc2
 ENV LD_PRELOAD=libjemalloc.so.2
 
+RUN bundle config set without 'postgresql passenger unicorn'
 RUN bundle install --jobs=4 --gemfile=/rack-sequel/Gemfile
 
 ENV DBTYPE=mysql

+ 1 - 2
frameworks/Ruby/rack/Gemfile

@@ -5,8 +5,7 @@ source 'https://rubygems.org'
 gem 'rack', '~> 3.0'
 gem 'connection_pool', '~> 2.4'
 gem 'jdbc-postgres', '~> 42.2', platforms: :jruby, require: 'jdbc/postgres'
-gem 'json', '~> 2.6', platforms: :jruby
-gem 'oj', '~> 3.14', platforms: %i[ruby mswin]
+gem 'json', '~> 2.8'
 gem 'pg', '~> 1.5', platforms: %i[ruby mswin]
 gem 'sequel'
 gem 'sequel_pg', platforms: %i[ruby mswin]

+ 49 - 49
frameworks/Ruby/rack/Gemfile.lock

@@ -2,119 +2,120 @@ GEM
   remote: https://rubygems.org/
   specs:
     ast (2.4.2)
-    async (2.12.1)
-      console (~> 1.25, >= 1.25.2)
+    async (2.20.0)
+      console (~> 1.29)
       fiber-annotation
       io-event (~> 1.6, >= 1.6.5)
-    async-container (0.18.2)
+    async-container (0.18.3)
       async (~> 2.10)
-    async-http (0.69.0)
+    async-http (0.83.1)
       async (>= 2.10.2)
-      async-pool (~> 0.7)
-      io-endpoint (~> 0.11)
-      io-stream (~> 0.4)
-      protocol-http (~> 0.26)
-      protocol-http1 (~> 0.19)
-      protocol-http2 (~> 0.18)
-      traces (>= 0.10)
-    async-http-cache (0.4.3)
+      async-pool (~> 0.9)
+      io-endpoint (~> 0.14)
+      io-stream (~> 0.6)
+      metrics (~> 0.12)
+      protocol-http (~> 0.43)
+      protocol-http1 (>= 0.28.1)
+      protocol-http2 (~> 0.19)
+      traces (~> 0.10)
+    async-http-cache (0.4.4)
       async-http (~> 0.56)
-    async-pool (0.7.0)
+    async-pool (0.10.1)
       async (>= 1.25)
+      traces
     async-service (0.12.0)
       async
       async-container (~> 0.16)
     bigdecimal (3.1.8)
-    concurrent-ruby (1.3.3)
+    concurrent-ruby (1.3.4)
     connection_pool (2.4.1)
-    console (1.25.2)
+    console (1.29.0)
       fiber-annotation
       fiber-local (~> 1.1)
       json
-    falcon (0.47.7)
+    falcon (0.48.3)
       async
       async-container (~> 0.18)
-      async-http (~> 0.66, >= 0.66.3)
-      async-http-cache (~> 0.4.0)
+      async-http (~> 0.75)
+      async-http-cache (~> 0.4)
       async-service (~> 0.10)
       bundler
       localhost (~> 1.1)
       openssl (~> 3.0)
-      process-metrics (~> 0.2.0)
-      protocol-rack (~> 0.5)
+      process-metrics (~> 0.2)
+      protocol-http (~> 0.31)
+      protocol-rack (~> 0.7)
       samovar (~> 2.3)
     fiber-annotation (0.2.0)
     fiber-local (1.1.0)
       fiber-storage
-    fiber-storage (0.1.2)
-    io-endpoint (0.11.0)
-    io-event (1.6.5)
-    io-stream (0.4.0)
+    fiber-storage (1.0.0)
+    io-endpoint (0.14.0)
+    io-event (1.7.3)
+    io-stream (0.6.1)
     json (2.8.2)
     kgio (2.11.4)
     language_server-protocol (3.17.0.3)
     localhost (1.3.1)
     mapping (1.1.1)
+    metrics (0.12.1)
     nio4r (2.7.4)
-    oj (3.16.4)
-      bigdecimal (>= 3.0)
     openssl (3.2.0)
-    parallel (1.25.1)
-    parser (3.3.3.0)
+    parallel (1.26.3)
+    parser (3.3.6.0)
       ast (~> 2.4.1)
       racc
-    pg (1.5.6)
-    process-metrics (0.2.1)
+    pg (1.5.9)
+    process-metrics (0.3.0)
       console (~> 1.8)
+      json (~> 2)
       samovar (~> 2.1)
-    protocol-hpack (1.4.3)
-    protocol-http (0.26.6)
-    protocol-http1 (0.19.1)
+    protocol-hpack (1.5.1)
+    protocol-http (0.43.0)
+    protocol-http1 (0.28.1)
       protocol-http (~> 0.22)
-    protocol-http2 (0.18.0)
+    protocol-http2 (0.20.0)
       protocol-hpack (~> 1.4)
       protocol-http (~> 0.18)
-    protocol-rack (0.6.0)
-      protocol-http (~> 0.23)
+    protocol-rack (0.11.0)
+      protocol-http (~> 0.43)
       rack (>= 1.0)
     puma (6.5.0)
       nio4r (~> 2.0)
-    racc (1.8.0)
-    rack (3.1.6)
+    racc (1.8.1)
+    rack (3.1.8)
     rack-test (2.1.0)
       rack (>= 1.3)
     rainbow (3.1.1)
     raindrops (0.20.1)
     regexp_parser (2.9.2)
-    rexml (3.3.9)
-    rubocop (1.64.1)
+    rubocop (1.68.0)
       json (~> 2.3)
       language_server-protocol (>= 3.17.0)
       parallel (~> 1.10)
       parser (>= 3.3.0.2)
       rainbow (>= 2.2.2, < 4.0)
-      regexp_parser (>= 1.8, < 3.0)
-      rexml (>= 3.2.5, < 4.0)
-      rubocop-ast (>= 1.31.1, < 2.0)
+      regexp_parser (>= 2.4, < 3.0)
+      rubocop-ast (>= 1.32.2, < 2.0)
       ruby-progressbar (~> 1.7)
       unicode-display_width (>= 2.4.0, < 3.0)
-    rubocop-ast (1.31.3)
+    rubocop-ast (1.35.0)
       parser (>= 3.3.1.0)
     ruby-progressbar (1.13.0)
     samovar (2.3.0)
       console (~> 1.0)
       mapping (~> 1.0)
-    sequel (5.82.0)
+    sequel (5.86.0)
       bigdecimal
     sequel_pg (1.17.1)
       pg (>= 0.18.0, != 1.2.0)
       sequel (>= 4.38.0)
-    traces (0.11.1)
+    traces (0.14.1)
     tzinfo (2.0.6)
       concurrent-ruby (~> 1.0)
     tzinfo-data (1.2023.3)
       tzinfo (>= 1.0.0)
-    unicode-display_width (2.5.0)
+    unicode-display_width (2.6.0)
     unicorn (6.1.0)
       kgio (~> 2.6)
       raindrops (~> 0.7)
@@ -127,8 +128,7 @@ DEPENDENCIES
   connection_pool (~> 2.4)
   falcon (~> 0.47)
   jdbc-postgres (~> 42.2)
-  json (~> 2.6)
-  oj (~> 3.14)
+  json (~> 2.8)
   pg (~> 1.5)
   puma (~> 6.4)
   rack (~> 3.0)

+ 1 - 3
frameworks/Ruby/rack/hello_world.rb

@@ -5,13 +5,11 @@
 require_relative 'pg_db'
 require_relative 'config/auto_tune'
 require 'rack'
+require 'json'
 
 if RUBY_PLATFORM == 'java'
-  require 'json'
   DEFAULT_DATABASE_URL = 'jdbc:postgresql://tfb-database/hello_world?user=benchmarkdbuser&password=benchmarkdbpass'
 else
-  require 'oj'
-  Oj.mimic_JSON
   DEFAULT_DATABASE_URL = 'postgresql://tfb-database/hello_world?user=benchmarkdbuser&password=benchmarkdbpass'
 end