Skip to content

Commit fa2f0a6

Browse files
committed
[ruby/rack-sequel] Use with_pk instead of contants for queries
rack-sequel has connection pools timeouts, unlike roda-sequel and sinatra-sequel: rack-sequel: 2025-09-13 11:30:07 +0000 Rack app ("GET /queries?queries=10" - (10.0.1.3)): #<Sequel::PoolTimeout: timeout: 10.0> https://tfb-status.techempower.com/unzip/results.2025-09-18-05-29-59-113.zip/results/20250910230442/rack-sequel/run/rack-sequel.log The only difference appears to be the prepared statements. Let's see if this fixes things.
1 parent ea7463a commit fa2f0a6

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

frameworks/Ruby/rack-sequel/boot.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,11 @@ def connect(dbtype)
4141

4242
# Define ORM models
4343
class World < Sequel::Model(:World)
44-
BY_ID = naked.where(id: :$id).prepare(:first, :world_by_id)
45-
UPDATE = where(id: :$id).prepare(:update, :world_update, randomnumber: :$randomnumber)
46-
4744
def_column_alias(:randomnumber, :randomNumber) if DB.database_type == :mysql
4845

4946
def self.batch_update(worlds)
5047
if DB.database_type == :mysql
51-
worlds.each do |world|
52-
UPDATE.(id: world[:id], randomnumber: world[:randomnumber])
53-
end
48+
worlds.map(&:save_changes)
5449
else
5550
ids = []
5651
sql = String.new("UPDATE world SET randomnumber = CASE id ")

frameworks/Ruby/rack-sequel/hello_world.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def rand1
3030
end
3131

3232
def db
33-
World::BY_ID.(id: rand1)
33+
World.with_pk(rand1).values
3434
end
3535

3636
def queries(env)
3737
ids = ALL_IDS.sample(bounded_queries(env))
3838
DB.synchronize do
3939
ids.map do |id|
40-
World::BY_ID.(id: id)
40+
World.with_pk(id).values
4141
end
4242
end
4343
end
@@ -84,17 +84,20 @@ def fortunes
8484
end
8585

8686
def updates(env)
87+
worlds = []
8788
ids = ALL_IDS.sample(bounded_queries(env))
8889
DB.synchronize do
8990
worlds =
9091
ids.map do |id|
91-
world = World::BY_ID.(id: id)
92-
world[:randomnumber] = rand1
92+
world = World.with_pk(id)
93+
new_value = rand1
94+
new_value = rand1 while new_value == world.randomnumber
95+
world.randomnumber = new_value
9396
world
9497
end
9598
World.batch_update(worlds)
96-
worlds
9799
end
100+
worlds.map!(&:values)
98101
end
99102

100103
def call(env)

0 commit comments

Comments
 (0)