This repository was archived by the owner on Mar 24, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11source 'https://rubygems.org'
22
3- gem 'trilogy' , '~> 2.9'
43gem 'activerecord' , '~> 8.1.0' , :require => 'active_record'
54gem 'grape' , '~> 3.0'
5+ gem 'pg'
66gem 'json' , '~> 2.9'
77
88group :iodine , optional : true do
Original file line number Diff line number Diff line change 6363 mustermann-grape (1.1.0 )
6464 mustermann (>= 1.0.0 )
6565 nio4r (2.7.4 )
66+ pg (1.6.3 )
67+ pg (1.6.3-x86_64-darwin )
68+ pg (1.6.3-x86_64-linux )
6669 puma (7.1.0 )
6770 nio4r (~> 2.0 )
6871 rack (3.2.4 )
6972 ruby2_keywords (0.0.5 )
7073 securerandom (0.4.1 )
7174 timeout (0.4.4 )
72- trilogy (2.9.0 )
7375 tzinfo (2.0.6 )
7476 concurrent-ruby (~> 1.0 )
7577 uri (1.1.1 )
@@ -85,8 +87,8 @@ DEPENDENCIES
8587 grape (~> 3.0 )
8688 iodine (~> 0.7 )
8789 json (~> 2.9 )
90+ pg
8891 puma (~> 7.1 )
89- trilogy (~> 2.9 )
9092
9193BUNDLED WITH
9294 4.0.3
Original file line number Diff line number Diff line change 1010 "port" : 8080 ,
1111 "approach" : " Realistic" ,
1212 "classification" : " Micro" ,
13- "database" : " MySQL " ,
13+ "database" : " Postgres " ,
1414 "framework" : " grape" ,
1515 "language" : " Ruby" ,
1616 "orm" : " Full" ,
3131 "port" : 8080 ,
3232 "approach" : " Realistic" ,
3333 "classification" : " Micro" ,
34- "database" : " MySQL " ,
34+ "database" : " Postgres " ,
3535 "framework" : " grape" ,
3636 "language" : " Ruby" ,
3737 "orm" : " Full" ,
Original file line number Diff line number Diff line change 1- require_relative 'boot'
1+ # frozen_string_literal: true
2+
3+ require_relative 'hello_world'
4+
25run Acme ::API
Original file line number Diff line number Diff line change 11production :
2- adapter : trilogy
2+ adapter : postgresql
33 encoding : utf8
44 host : tfb-database
55 database : hello_world
66 username : benchmarkdbuser
77 password : benchmarkdbpass
88 pool : <%= ENV.fetch('MAX_THREADS') %>
99 timeout : 5000
10- ssl : true
11- ssl_mode : 4 <%# Trilogy::SSL_PREFERRED_NOVERIFY %>
12- tls_min_version : 3 <%# Trilogy::TLS_VERSION_12 %>
10+ encoding : unicode
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require 'erb'
4+ require 'active_record'
5+ require 'yaml'
6+
7+ db_config = YAML . load ( ERB . new ( File . read ( 'config/database.yml' ) ) . result ) [ ENV [ 'RACK_ENV' ] ]
8+ ActiveRecord ::Base . establish_connection ( db_config )
9+
10+ class World < ActiveRecord ::Base
11+ self . table_name = 'World'
12+
13+ alias_attribute ( :randomNumber , :randomnumber ) \
14+ if connection . adapter_name . downcase . start_with? ( 'postgres' )
15+ end
16+
Original file line number Diff line number Diff line change 1- require 'erb'
2- require 'active_record'
3- require 'yaml'
4-
5- MAX_PK = 10_000
6- ID_RANGE = ( 1 ..MAX_PK ) . freeze
7- ALL_IDS = ID_RANGE . to_a
8- QUERIES_MIN = 1
9- QUERIES_MAX = 500
10-
1+ require 'bundler/setup'
112Bundler . require :default
123
13- db_config = YAML . load ( ERB . new ( File . read ( 'config/database.yml' ) ) . result ) [ ENV [ 'RACK_ENV' ] ]
14- ActiveRecord ::Base . establish_connection ( db_config )
15-
16- class World < ActiveRecord ::Base
17- self . table_name = 'World'
18- end
4+ require_relative 'db'
195
206module Acme
7+ MAX_PK = 10_000
8+ ID_RANGE = ( 1 ..MAX_PK ) . freeze
9+ ALL_IDS = ID_RANGE . to_a
10+ QUERIES_MIN = 1
11+ QUERIES_MAX = 500
12+
2113 class HelloWorld < Grape ::API
2214 get '/json' do
2315 { message :'Hello, World!' }
@@ -62,16 +54,21 @@ def rand1
6254 end
6355
6456 get '/updates' do
65- worlds =
66- ActiveRecord ::Base . with_connection do
67- ALL_IDS . sample ( bounded_queries ) . map do |id |
68- world = World . find ( id )
69- new_value = rand1
70- new_value = rand1 while new_value == world . randomNumber
71- world . update_columns ( randomNumber : new_value )
72- world
73- end
57+ worlds = nil
58+ ids = ALL_IDS . sample ( bounded_queries )
59+ ActiveRecord ::Base . with_connection do
60+ worlds = ids . map do |id |
61+ world = World . find ( id )
62+ new_value = rand1
63+ new_value = rand1 until new_value != world . randomNumber
64+ { id : id , randomnumber : new_value }
7465 end
66+ end
67+ worlds . sort_by! { _1 [ :id ] }
68+ ActiveRecord ::Base . with_connection do
69+ World . upsert_all ( worlds )
70+ end
71+ worlds
7572 end
7673 end
7774
You can’t perform that action at this time.
0 commit comments