| 
7 | 7 | require 'rack'  | 
8 | 8 | 
 
  | 
9 | 9 | $pool = ConnectionPool.new(size: 1, timeout: 5) do  | 
10 |  | -          PG::Connection.new({  | 
11 |  | -                                 dbname:   'hello_world',  | 
12 |  | -                                 host:     'tfb-database',  | 
13 |  | -                                 user:     'benchmarkdbuser',  | 
14 |  | -                                 password: 'benchmarkdbpass'  | 
15 |  | -                             })  | 
16 |  | -        end  | 
 | 10 | +  conn = PG::Connection.new({  | 
 | 11 | +    dbname:   'hello_world',  | 
 | 12 | +    host:     'tfb-database',  | 
 | 13 | +    user:     'benchmarkdbuser',  | 
 | 14 | +    password: 'benchmarkdbpass'  | 
 | 15 | +  })  | 
 | 16 | +  conn.set_error_verbosity(PG::PQERRORS_VERBOSE)  | 
 | 17 | +  conn.prepare('select_world', 'SELECT * FROM world WHERE id = $1')  | 
 | 18 | +  conn.prepare('select_fortune', 'SELECT id, message FROM fortune')  | 
 | 19 | +  conn  | 
 | 20 | +end  | 
17 | 21 | 
 
  | 
18 | 22 | QUERY_RANGE = (1..10_000).freeze  | 
19 | 23 | ALL_IDS = QUERY_RANGE.to_a  | 
@@ -43,11 +47,7 @@ def self.get_one_random_number  | 
43 | 47 | 
 
  | 
44 | 48 |   def self.get_one_record(id = get_one_random_number)  | 
45 | 49 |     $pool.with do |conn|  | 
46 |  | -      conn.exec_params(<<-SQL, [id]).first  | 
47 |  | -
  | 
48 |  | -        SELECT * FROM world WHERE id = $1  | 
49 |  | -
  | 
50 |  | -      SQL  | 
 | 50 | +      conn.exec_prepared('select_world', [id]).first  | 
51 | 51 |     end  | 
52 | 52 |   end  | 
53 | 53 | 
 
  | 
@@ -114,15 +114,12 @@ def self.call(_req)  | 
114 | 114 |   end  | 
115 | 115 | end  | 
116 | 116 | 
 
  | 
 | 117 | + | 
117 | 118 | class FortunesHandler < BaseHandler  | 
118 | 119 |   def self.call(_req)  | 
119 | 120 |     f_1 = $pool.with do |conn|  | 
120 |  | -            conn.exec(<<-SQL)  | 
121 |  | -
  | 
122 |  | -              SELECT id, message FROM fortune  | 
123 |  | -
  | 
124 |  | -            SQL  | 
125 |  | -          end  | 
 | 121 | +      conn.exec_prepared('select_fortune', [])  | 
 | 122 | +    end  | 
126 | 123 | 
 
  | 
127 | 124 |     f_2 = f_1.map(&:to_h).  | 
128 | 125 |             append({ 'id' => '0', 'message' => 'Additional fortune added at request time.' }).  | 
@@ -192,21 +189,20 @@ def self.call(req)  | 
192 | 189 | end  | 
193 | 190 | 
 
  | 
194 | 191 | Agoo::Log.configure({  | 
195 |  | -                        classic:  true,  | 
196 |  | -                        colorize: true,  | 
197 |  | -                        console:  true,  | 
198 |  | -                        dir:      '',  | 
199 |  | -                        states:   {  | 
200 |  | -                            DEBUG:    false,  | 
201 |  | -                            INFO:     false,  | 
202 |  | - | 
203 |  | -                            connect:  false,  | 
204 |  | -                            eval:     false,  | 
205 |  | -                            push:     false,  | 
206 |  | -                            request:  false,  | 
207 |  | -                            response: false  | 
208 |  | -                        }  | 
209 |  | -                    })  | 
 | 192 | +  classic:  true,  | 
 | 193 | +  colorize: true,  | 
 | 194 | +  console:  true,  | 
 | 195 | +  dir:      '',  | 
 | 196 | +  states:   {  | 
 | 197 | +    DEBUG:    false,  | 
 | 198 | +    INFO:     false,  | 
 | 199 | +    connect:  false,  | 
 | 200 | +    eval:     false,  | 
 | 201 | +    push:     false,  | 
 | 202 | +    request:  false,  | 
 | 203 | +    response: false  | 
 | 204 | +  }  | 
 | 205 | +})  | 
210 | 206 | 
 
  | 
211 | 207 | worker_count = 4  | 
212 | 208 | worker_count = ENV['AGOO_WORKER_COUNT'].to_i if ENV.key?('AGOO_WORKER_COUNT')  | 
 | 
0 commit comments