@@ -110,114 +110,225 @@ You can setup PgBench locally through PgCat:
110
110
pgbench -h 127.0.0.1 -p 6432 -i
111
111
```
112
112
113
- Coincidenly, this uses ` COPY ` so you can test if that works.
113
+ Coincidenly, this uses ` COPY ` so you can test if that works. Additionally, we'll be running the following PgBench configurations:
114
+
115
+ 1 . 16 clients, 2 threads
116
+ 2 . 32 clients, 2 threads
117
+ 3 . 64 clients, 2 threads
118
+ 4 . 128 clients, 2 threads
119
+
120
+ All queries will be ` SELECT ` only (` -S ` ) just so disks don't get in the way, since the dataset will be effectively all in RAM.
114
121
115
122
### PgBouncer
116
123
124
+ #### Config
125
+
126
+ ``` ini
127
+ [databases]
128
+ shard0 = host =localhost port =5432 user =sharding_user password =sharding_user
129
+
130
+ pool_mode = transaction
131
+ max_client_conn = 1000
132
+ ```
133
+
134
+ #### Runs
135
+
136
+
117
137
```
118
- $ pgbench -i -h 127.0.0.1 -p 6432 && pgbench -t 1000 -p 6432 -h 127.0.0.1 --protocol simple && pgbench -t 1000 -p 6432 -h 127.0.0.1 --protocol extended
119
- dropping old tables...
120
- creating tables...
121
- generating data...
122
- 100000 of 100000 tuples (100%) done (elapsed 0.01 s, remaining 0.00 s)
123
- vacuuming...
124
- creating primary keys...
125
- done.
138
+ $ pgbench -t 1000 -c 16 -j 2 -p 6432 -h 127.0.0.1 -S --protocol extended shard0
139
+
126
140
starting vacuum...end.
127
- transaction type: <builtin: TPC-B (sort of) >
141
+ transaction type: <builtin: select only >
128
142
scaling factor: 1
129
- query mode: simple
130
- number of clients: 1
131
- number of threads: 1
143
+ query mode: extended
144
+ number of clients: 16
145
+ number of threads: 2
132
146
number of transactions per client: 1000
133
- number of transactions actually processed: 1000/1000
134
- latency average = 1.089 ms
135
- tps = 918.687098 (including connections establishing)
136
- tps = 918.847790 (excluding connections establishing)
147
+ number of transactions actually processed: 16000/16000
148
+ latency average = 0.155 ms
149
+ tps = 103417.377469 (including connections establishing)
150
+ tps = 103510.639935 (excluding connections establishing)
151
+
152
+
153
+ $ pgbench -t 1000 -c 32 -j 2 -p 6432 -h 127.0.0.1 -S --protocol extended shard0
154
+
137
155
starting vacuum...end.
138
- transaction type: <builtin: TPC-B (sort of) >
156
+ transaction type: <builtin: select only >
139
157
scaling factor: 1
140
158
query mode: extended
141
- number of clients: 1
142
- number of threads: 1
159
+ number of clients: 32
160
+ number of threads: 2
143
161
number of transactions per client: 1000
144
- number of transactions actually processed: 1000/1000
145
- latency average = 1.136 ms
146
- tps = 880.622009 (including connections establishing)
147
- tps = 880.769550 (excluding connections establishing)
162
+ number of transactions actually processed: 32000/32000
163
+ latency average = 0.290 ms
164
+ tps = 110325.939785 (including connections establishing)
165
+ tps = 110386.513435 (excluding connections establishing)
166
+
167
+
168
+ $ pgbench -t 1000 -c 64 -j 2 -p 6432 -h 127.0.0.1 -S --protocol extended shard0
169
+
170
+ starting vacuum...end.
171
+ transaction type: <builtin: select only>
172
+ scaling factor: 1
173
+ query mode: extended
174
+ number of clients: 64
175
+ number of threads: 2
176
+ number of transactions per client: 1000
177
+ number of transactions actually processed: 64000/64000
178
+ latency average = 0.692 ms
179
+ tps = 92470.427412 (including connections establishing)
180
+ tps = 92618.389350 (excluding connections establishing)
181
+
182
+ $ pgbench -t 1000 -c 128 -j 2 -p 6432 -h 127.0.0.1 -S --protocol extended shard0
183
+
184
+ starting vacuum...end.
185
+ transaction type: <builtin: select only>
186
+ scaling factor: 1
187
+ query mode: extended
188
+ number of clients: 128
189
+ number of threads: 2
190
+ number of transactions per client: 1000
191
+ number of transactions actually processed: 128000/128000
192
+ latency average = 1.406 ms
193
+ tps = 91013.429985 (including connections establishing)
194
+ tps = 91067.583928 (excluding connections establishing)
148
195
```
149
196
150
197
### PgCat
151
198
199
+ #### Config
200
+
201
+ The only thing that matters here is the number of workers in the Tokio pool. Make sure to set it to < than the number of your CPU cores.
202
+ Also account for hyper-threading, so if you have that, take the number you got above and divide it by two, that way only "real" cores serving
203
+ requests.
204
+
205
+ My setup is 16 threads, 8 cores (` htop ` shows as 16 CPUs), so I set the ` max_workers ` in Tokio to 4. Too many, and it starts conflicting with PgBench
206
+ which is also running on the same system.
207
+
208
+ #### Runs
209
+
152
210
153
211
```
154
- $ pgbench -i -h 127.0.0.1 -p 6432 && pgbench -t 1000 -p 6432 -h 127.0.0.1 --protocol simple && pgbench -t 1000 -p 6432 -h 127.0.0.1 --protocol extended
155
- dropping old tables...
156
- creating tables...
157
- generating data...
158
- 100000 of 100000 tuples (100%) done (elapsed 0.01 s, remaining 0.00 s)
159
- vacuuming...
160
- creating primary keys...
161
- done.
212
+ $ pgbench -t 1000 -c 16 -j 2 -p 6432 -h 127.0.0.1 -S --protocol extended
162
213
starting vacuum...end.
163
- transaction type: <builtin: TPC-B (sort of) >
214
+ transaction type: <builtin: select only >
164
215
scaling factor: 1
165
- query mode: simple
166
- number of clients: 1
167
- number of threads: 1
216
+ query mode: extended
217
+ number of clients: 16
218
+ number of threads: 2
168
219
number of transactions per client: 1000
169
- number of transactions actually processed: 1000/1000
170
- latency average = 1.142 ms
171
- tps = 875.645437 (including connections establishing)
172
- tps = 875.799995 (excluding connections establishing)
220
+ number of transactions actually processed: 16000/16000
221
+ latency average = 0.164 ms
222
+ tps = 97705.088232 (including connections establishing)
223
+ tps = 97872.216045 (excluding connections establishing)
224
+
225
+
226
+ $ pgbench -t 1000 -c 32 -j 2 -p 6432 -h 127.0.0.1 -S --protocol extended
227
+
228
+ starting vacuum...end.
229
+ transaction type: <builtin: select only>
230
+ scaling factor: 1
231
+ query mode: extended
232
+ number of clients: 32
233
+ number of threads: 2
234
+ number of transactions per client: 1000
235
+ number of transactions actually processed: 32000/32000
236
+ latency average = 0.288 ms
237
+ tps = 111300.488119 (including connections establishing)
238
+ tps = 111413.107800 (excluding connections establishing)
239
+
240
+
241
+ $ pgbench -t 1000 -c 64 -j 2 -p 6432 -h 127.0.0.1 -S --protocol extended
242
+
243
+ starting vacuum...end.
244
+ transaction type: <builtin: select only>
245
+ scaling factor: 1
246
+ query mode: extended
247
+ number of clients: 64
248
+ number of threads: 2
249
+ number of transactions per client: 1000
250
+ number of transactions actually processed: 64000/64000
251
+ latency average = 0.556 ms
252
+ tps = 115190.496139 (including connections establishing)
253
+ tps = 115247.521295 (excluding connections establishing)
254
+
255
+ $ pgbench -t 1000 -c 128 -j 2 -p 6432 -h 127.0.0.1 -S --protocol extended
256
+
173
257
starting vacuum...end.
174
- transaction type: <builtin: TPC-B (sort of) >
258
+ transaction type: <builtin: select only >
175
259
scaling factor: 1
176
260
query mode: extended
177
- number of clients: 1
178
- number of threads: 1
261
+ number of clients: 128
262
+ number of threads: 2
179
263
number of transactions per client: 1000
180
- number of transactions actually processed: 1000/1000
181
- latency average = 1.181 ms
182
- tps = 846.539176 (including connections establishing)
183
- tps = 846.713636 (excluding connections establishing)
264
+ number of transactions actually processed: 128000/128000
265
+ latency average = 1.135 ms
266
+ tps = 112770.562239 (including connections establishing)
267
+ tps = 112796.502381 (excluding connections establishing)
184
268
```
185
269
186
270
### Direct Postgres
187
271
272
+ Always good to have a base line. Note, at 128 clients, having our pooler ends up being faster.
273
+
274
+ #### Runs
275
+
188
276
```
189
- $ pgbench -i -h 127.0.0.1 -p 5432 && pgbench -t 1000 -p 5432 -h 127.0.0.1 --protocol simple && pgbench -t 1000 -p
190
- 5432 -h 127.0.0.1 --protocol extended
191
- Password:
192
- dropping old tables...
193
- creating tables...
194
- generating data...
195
- 100000 of 100000 tuples (100%) done (elapsed 0.01 s, remaining 0.00 s)
196
- vacuuming...
197
- creating primary keys...
198
- done.
199
- Password:
277
+ $ pgbench -t 1000 -c 16 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0
278
+ Password:
200
279
starting vacuum...end.
201
- transaction type: <builtin: TPC-B (sort of) >
280
+ transaction type: <builtin: select only >
202
281
scaling factor: 1
203
- query mode: simple
204
- number of clients: 1
205
- number of threads: 1
282
+ query mode: extended
283
+ number of clients: 16
284
+ number of threads: 2
206
285
number of transactions per client: 1000
207
- number of transactions actually processed: 1000/1000
208
- latency average = 0.902 ms
209
- tps = 1109.014867 (including connections establishing)
210
- tps = 1112.318595 (excluding connections establishing)
211
- Password:
286
+ number of transactions actually processed: 16000/16000
287
+ latency average = 0.115 ms
288
+ tps = 139443.955722 (including connections establishing)
289
+ tps = 142314.859075 (excluding connections establishing)
290
+
291
+ $ pgbench -t 1000 -c 32 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0
292
+ Password:
293
+ starting vacuum...end.
294
+ transaction type: <builtin: select only>
295
+ scaling factor: 1
296
+ query mode: extended
297
+ number of clients: 32
298
+ number of threads: 2
299
+ number of transactions per client: 1000
300
+ number of transactions actually processed: 32000/32000
301
+ latency average = 0.212 ms
302
+ tps = 150644.840891 (including connections establishing)
303
+ tps = 152218.499430 (excluding connections establishing)
304
+
305
+ $ pgbench -t 1000 -c 64 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0
306
+ Password:
307
+ starting vacuum...end.
308
+ transaction type: <builtin: select only>
309
+ scaling factor: 1
310
+ query mode: extended
311
+ number of clients: 64
312
+ number of threads: 2
313
+ number of transactions per client: 1000
314
+ number of transactions actually processed: 64000/64000
315
+ latency average = 0.420 ms
316
+ tps = 152517.663404 (including connections establishing)
317
+ tps = 153319.188482 (excluding connections establishing)
318
+
319
+ $ pgbench -t 1000 -c 128 -j 2 -p 5432 -h 127.0.0.1 -S --protocol extended shard0
320
+ Password:
212
321
starting vacuum...end.
213
- transaction type: <builtin: TPC-B (sort of)>
322
+ pgbench: error: connection to database "shard0" failed: FATAL: sorry, too many clients already
323
+ FATAL: sorry, too many clients already
324
+ transaction type: <builtin: select only>
214
325
scaling factor: 1
215
326
query mode: extended
216
- number of clients: 1
217
- number of threads: 1
327
+ number of clients: 128
328
+ number of threads: 2
218
329
number of transactions per client: 1000
219
- number of transactions actually processed: 1000/1000
220
- latency average = 0.931 ms
221
- tps = 1074.017747 (including connections establishing)
222
- tps = 1077.121752 (excluding connections establishing)
330
+ number of transactions actually processed: 64000/128000
331
+ latency average = 1.324 ms
332
+ tps = 96692.385260 (including connections establishing)
333
+ tps = 96854.431104 (excluding connections establishing)
223
334
```
0 commit comments