4
4
<refmeta>
5
5
<refentrytitle><application>pg_test_timing</application></refentrytitle>
6
6
<manvolnum>1</manvolnum>
7
+ <!--
7
8
<refmiscinfo>Application</refmiscinfo>
9
+ -->
10
+ <refmiscinfo>应用</refmiscinfo>
8
11
</refmeta>
9
12
10
13
<refnamediv>
11
14
<refname>pg_test_timing</refname>
15
+ <!--
12
16
<refpurpose>measure timing overhead</refpurpose>
17
+ -->
18
+ <refpurpose>测量时间开销</refpurpose>
13
19
</refnamediv>
14
20
15
21
<indexterm zone="pgtesttiming">
24
30
</refsynopsisdiv>
25
31
26
32
<refsect1>
33
+ <!--
27
34
<title>Description</title>
35
+ -->
36
+ <title>描述</title>
28
37
29
- <para>
38
+ <!--
39
+ <para>
30
40
<application>pg_test_timing</> is a tool to measure the timing overhead
31
41
on your system and confirm that the system time never moves backwards.
32
42
Systems that are slow to collect timing data can give less accurate
33
43
<command>EXPLAIN ANALYZE</command> results.
34
44
</para>
45
+ -->
46
+ <para>
47
+ <application>pg_test_timing</>是一个在你的系统上测量时间开销的工具,
48
+ 并确认系统时间从不向后移动。缓慢的收集时间数据的系统会给出较小精度的
49
+ <command>EXPLAIN ANALYZE</command>结果。
50
+ </para>
35
51
</refsect1>
36
52
37
53
<refsect1>
54
+ <!--
38
55
<title>Options</title>
56
+ -->
57
+ <title>选项</title>
39
58
40
59
<para>
41
- <application>pg_test_timing</application> accepts the following
60
+ <!--
61
+ <application>pg_test_timing</application> accepts the following
42
62
command-line options:
63
+ -->
64
+ <application>pg_test_timing</application>接受下列的命令行选项:
43
65
44
66
<variablelist>
45
67
48
70
<term><option>--duration=<replaceable class="parameter">duration</replaceable></option></term>
49
71
<listitem>
50
72
<para>
51
- Specifies the test duration, in seconds. Longer durations
73
+ <!--
74
+ Specifies the test duration, in seconds. Longer durations
52
75
give slightly better accuracy, and are more likely to discover
53
76
problems with the system clock moving backwards. The default
54
77
test duration is 3 seconds.
78
+ -->
79
+ 声明测试持续时间,以秒计。较长的持续时间给出稍微较好的精度,
80
+ 并且更有可能发现系统时钟向后移动的问题。缺省的测试持续时间是3秒。
55
81
</para>
56
82
</listitem>
57
83
</varlistentry>
61
87
<term><option>--version</></term>
62
88
<listitem>
63
89
<para>
64
- Print the <application>pg_test_timing</application> version and exit.
90
+ <!--
91
+ Print the <application>pg_test_timing</application> version and exit.
92
+ -->
93
+ 输出<application>pg_test_timing</application>版本并退出。
65
94
</para>
66
95
</listitem>
67
96
</varlistentry>
71
100
<term><option>--help</></term>
72
101
<listitem>
73
102
<para>
74
- Show help about <application>pg_test_timing</application> command line
103
+ <!--
104
+ Show help about <application>pg_test_timing</application> command line
75
105
arguments, and exit.
106
+ -->
107
+ 显示关于<application>pg_test_timing</application>命令行参数的帮助,并退出。
76
108
</para>
77
109
</listitem>
78
110
</varlistentry>
83
115
</refsect1>
84
116
85
117
<refsect1>
118
+ <!--
86
119
<title>Usage</title>
120
+ -->
121
+ <title>用法</title>
87
122
88
123
<refsect2>
124
+ <!--
89
125
<title>Interpreting results</title>
126
+ -->
127
+ <title>解释结果</title>
90
128
91
129
<para>
92
- Good results will show most (>90%) individual timing calls take less than
130
+ <!--
131
+ Good results will show most (>90%) individual timing calls take less than
93
132
one microsecond. Average per loop overhead will be even lower, below 100
94
133
nanoseconds. This example from an Intel i7-860 system using a TSC clock
95
134
source shows excellent performance:
135
+ -->
136
+ 好的结果将显示大多数(>90%)单个时间调用花费不到一微妙。平均每循环开销将更低,
137
+ 低于100纳秒。这个示例来自一个Intel i7-860系统,使用TSC时钟资源,显示性能优良:
96
138
97
139
<screen>
98
140
Testing timing overhead for 3 seconds.
@@ -108,21 +150,33 @@ Histogram of timing durations:
108
150
</para>
109
151
110
152
<para>
153
+ <!--
111
154
Note that different units are used for the per loop time than the
112
155
histogram. The loop can have resolution within a few nanoseconds (nsec),
113
156
while the individual timing calls can only resolve down to one microsecond
114
157
(usec).
158
+ -->
159
+ 请注意,每循环时间和直方图使用的时间单位不同。当单个时间调用只能降低到一微妙(usec)解决时,
160
+ 该循环可以在几纳秒内解决(nsec)。
115
161
</para>
116
162
117
163
</refsect2>
118
164
<refsect2>
165
+ <!--
119
166
<title>Measuring executor timing overhead</title>
167
+ -->
168
+ <title>测量执行者时间开销</title>
120
169
121
170
<para>
171
+ <!--
122
172
When the query executor is running a statement using
123
173
<command>EXPLAIN ANALYZE</command>, individual operations are timed as well
124
174
as showing a summary. The overhead of your system can be checked by
125
175
counting rows with the <application>psql</application> program:
176
+ -->
177
+ 当查询执行者使用<command>EXPLAIN ANALYZE</command>运行一个语句时,
178
+ 单个操作的时间也可以显示一个总结。你的系统开销可以通过<application>psql</application>
179
+ 程序计数行来检查:
126
180
127
181
<screen>
128
182
CREATE TABLE t AS SELECT * FROM generate_series(1,100000);
@@ -133,24 +187,38 @@ EXPLAIN ANALYZE SELECT COUNT(*) FROM t;
133
187
</para>
134
188
135
189
<para>
190
+ <!--
136
191
The i7-860 system measured runs the count query in 9.8 ms while
137
192
the <command>EXPLAIN ANALYZE</command> version takes 16.6 ms, each
138
193
processing just over 100,000 rows. That 6.8 ms difference means the timing
139
194
overhead per row is 68 ns, about twice what pg_test_timing estimated it
140
195
would be. Even that relatively small amount of overhead is making the fully
141
196
timed count statement take almost 70% longer. On more substantial queries,
142
197
the timing overhead would be less problematic.
198
+ -->
199
+ i7-860系统测量运行计数查询使用了9.8 ms,而<command>EXPLAIN ANALYZE</command>
200
+ 版本使用了16.6 ms,每个处理超出100,000行。6.8 ms的差异意味着时间开销每行是68 ns,
201
+ 大约是pg_test_timing预估的两倍。即使是相对少量的开销,也使得完整时间计数语句多花费了近70%。
202
+ 在更大量的查询上,时间开销将会有更少的问题。
143
203
</para>
144
204
145
205
</refsect2>
146
206
147
207
<refsect2>
208
+ <!--
148
209
<title>Changing time sources</title>
210
+ -->
211
+ <title>改变时间来源</title>
149
212
<para>
213
+ <!--
150
214
On some newer Linux systems, it's possible to change the clock source used
151
215
to collect timing data at any time. A second example shows the slowdown
152
216
possible from switching to the slower acpi_pm time source, on the same
153
217
system used for the fast results above:
218
+ -->
219
+ 在一些较新的Linux系统上,随时修改用于统计时间数据的时钟来源是可能的。
220
+ 第二个例子显示了通过切换到较缓慢acpi_pm时间来源变缓的可能,
221
+ 在同一个系统上用于上面快速的结果:
154
222
155
223
<screen>
156
224
# cat /sys/devices/system/clocksource/clocksource0/available_clocksource
@@ -169,18 +237,27 @@ Histogram of timing durations:
169
237
</para>
170
238
171
239
<para>
240
+ <!--
172
241
In this configuration, the sample <command>EXPLAIN ANALYZE</command> above
173
242
takes 115.9 ms. That's 1061 nsec of timing overhead, again a small multiple
174
243
of what's measured directly by this utility. That much timing overhead
175
244
means the actual query itself is only taking a tiny fraction of the
176
245
accounted for time, most of it is being consumed in overhead instead. In
177
246
this configuration, any <command>EXPLAIN ANALYZE</command> totals involving
178
247
many timed operations would be inflated significantly by timing overhead.
248
+ -->
249
+ 在这个配置中,上面的<command>EXPLAIN ANALYZE</command>示例花费了115.9 ms。
250
+ 1061纳秒的时间开销,再次是这个工具直接测量的几倍。
251
+ 那么多时间开销意味着实际查询本身只花费了其中的一小部分,大多数被消耗掉了。
252
+ 在这个配置中,任何<command>EXPLAIN ANALYZE</command>总计都包括许多时间开销显著膨胀的操作。
179
253
</para>
180
254
181
255
<para>
256
+ <!--
182
257
FreeBSD also allows changing the time source on the fly, and it logs
183
- information about the timer selected during boot:
258
+ information about the timer selected during boot:
259
+ -->
260
+ FreeBSD也允许在运行中修改时间来源,并且它记录在启动时选择的计时器:
184
261
185
262
<screen>
186
263
# dmesg | grep "Timecounter"
@@ -194,12 +271,18 @@ kern.timecounter.hardware: ACPI-fast -> TSC
194
271
</para>
195
272
196
273
<para>
274
+ <!--
197
275
Other systems may only allow setting the time source on boot. On older
198
276
Linux systems the "clock" kernel setting is the only way to make this sort
199
277
of change. And even on some more recent ones, the only option you'll see
200
278
for a clock source is "jiffies". Jiffies are the older Linux software clock
201
279
implementation, which can have good resolution when it's backed by fast
202
- enough timing hardware, as in this example:
280
+ enough timing hardware, as in this example:
281
+ -->
282
+ 其他系统可能只允许在启动时设置时间来源。在老一些的Linux系统上,
283
+ "clock"内核设置是修改时间来源的唯一方式。即使是在一些最近的系统上,
284
+ 你看到的时钟来源的唯一选项是"jiffies"。Jiffies是老一些的Linux软件时钟实现,
285
+ 当它依靠在足够快的时间硬件上时,可以有很好的解决,如下面的例子:
203
286
204
287
<screen>
205
288
$ cat /sys/devices/system/clocksource/clocksource0/available_clocksource
@@ -223,9 +306,13 @@ Histogram of timing durations:
223
306
</refsect2>
224
307
225
308
<refsect2>
309
+ <!--
226
310
<title>Clock hardware and timing accuracy</title>
311
+ -->
312
+ <title>时钟硬件和时间精度</title>
227
313
228
314
<para>
315
+ <!--
229
316
Collecting accurate timing information is normally done on computers using
230
317
hardware clocks with various levels of accuracy. With some hardware the
231
318
operating systems can pass the system clock time almost directly to
@@ -234,18 +321,31 @@ Histogram of timing durations:
234
321
either case, operating system kernels provide a clock source that hides
235
322
these details. But the accuracy of that clock source and how quickly it can
236
323
return results varies based on the underlying hardware.
324
+ -->
325
+ 收集准确的时间信息通常是在计算机上使用硬件时钟和各种级别的精度来完成的。
326
+ 在一些硬件上,操作系统可以传递系统时钟时间直接到程序。
327
+ 系统时钟也可以来自一个芯片,简单的提供时间中断,周期性的在一些已知的时间间隔运转。
328
+ 在这两种情况下,操作系统内核提供一个时钟资源,隐藏了这些细节。
329
+ 但是时钟资源的精度和它可以多快的返回结果基于底层硬件的不同。
237
330
</para>
238
331
239
332
<para>
333
+ <!--
240
334
Inaccurate time keeping can result in system instability. Test any change
241
335
to the clock source very carefully. Operating system defaults are sometimes
242
336
made to favor reliability over best accuracy. And if you are using a virtual
243
337
machine, look into the recommended time sources compatible with it. Virtual
244
338
hardware faces additional difficulties when emulating timers, and there are
245
339
often per operating system settings suggested by vendors.
340
+ -->
341
+ 不准确的时间会导致系统不稳定。要小心的测试任何时钟源的改变。
342
+ 操作系统默认是有时在支持最好的精度的情况下提供最高的可靠性。如果你正在使用一个虚拟机,
343
+ 看看推荐的时间资源兼容。虚拟硬件在计算时间时面临更多的困难,
344
+ 通常有供应商建议的每操作系统设置。
246
345
</para>
247
346
248
347
<para>
348
+ <!--
249
349
The Time Stamp Counter (TSC) clock source is the most accurate one available
250
350
on current generation CPUs. It's the preferred way to track the system time
251
351
when it's supported by the operating system and the TSC clock is
@@ -257,49 +357,80 @@ Histogram of timing durations:
257
357
backwards, a problem this program checks for. And even the newest systems
258
358
can fail to provide accurate TSC timing with very aggressive power saving
259
359
configurations.
360
+ -->
361
+ 时间戳计数器(TSC)时钟资源是在当前一代CPU上可用的最精确的一个。
362
+ 当操作系统支持它并且TSC时钟可靠时,这是追踪系统时间的首选方式。
363
+ 有几种方式,TSC未能提供准确的时间源,使得它不可靠。
364
+ 较老的系统可能有一个基于CPU温度变化的TSC时钟,使其无法计时。
365
+ 在一些较老的多核CPU上尝试使用TSC会给出与多核不一致的报告时间。
366
+ 这会导致时间回退,一个这个程序检查的问题。甚至最新的系统在非常节能的配置下,
367
+ 也未能提供准确的TSC时间。
260
368
</para>
261
369
262
370
<para>
371
+ <!--
263
372
Newer operating systems may check for the known TSC problems and switch to a
264
373
slower, more stable clock source when they are seen. If your system
265
374
supports TSC time but doesn't default to that, it may be disabled for a good
266
375
reason. And some operating systems may not detect all the possible problems
267
376
correctly, or will allow using TSC even in situations where it's known to be
268
377
inaccurate.
378
+ -->
379
+ 较新的操作系统会检查已知的TSC问题,并在观察到问题时切换到一个较缓慢、更稳定的时钟源。
380
+ 如果你的系统支持TSC时间,但是缺省不是它,它可能是因为一个好的原因而禁用了。
381
+ 一些操作系统可能不能正确的检测所有可能的问题,或者在已知不准确的情况下允许使用TSC。
269
382
</para>
270
383
271
384
<para>
385
+ <!--
272
386
The High Precision Event Timer (HPET) is the preferred timer on systems
273
387
where it's available and TSC is not accurate. The timer chip itself is
274
388
programmable to allow up to 100 nanosecond resolution, but you may not see
275
389
that much accuracy in your system clock.
390
+ -->
391
+ 高精度事件定时器(HPET)在可用并且TSC不准确的系统上是首选的定时器。
392
+ 定时器芯片本身是可编程的,允许高达100纳秒的精度,但是你可能在你的系统时钟上没有看到有多精确。
276
393
</para>
277
394
278
395
<para>
396
+ <!--
279
397
Advanced Configuration and Power Interface (ACPI) provides a Power
280
398
Management (PM) Timer, which Linux refers to as the acpi_pm. The clock
281
399
derived from acpi_pm will at best provide 300 nanosecond resolution.
400
+ -->
401
+ 高级配置和电源接口(ACPI)提供了一个电源管理(PM)定时器,Linux称其为acpi_pm。
402
+ 该时钟来源于acpi_pm,最高提供300纳秒的精度。
282
403
</para>
283
404
284
405
<para>
406
+ <!--
285
407
Timers used on older PC hardware include the 8254 Programmable Interval
286
408
Timer (PIT), the real-time clock (RTC), the Advanced Programmable Interrupt
287
409
Controller (APIC) timer, and the Cyclone timer. These timers aim for
288
410
millisecond resolution.
411
+ -->
412
+ 较老PC硬件上使用的定时器包括8254可编程间隔计时器(PIT)、实时时钟(RTC)、
413
+ 高级可编程中断控制器(APIC)定时器和Cyclone定时器。这些定时器是毫秒精度的。
289
414
</para>
290
415
</refsect2>
291
416
</refsect1>
292
417
293
418
<refsect1>
419
+ <!--
294
420
<title>Author</title>
421
+ -->
422
+ <title>作者</title>
295
423
296
424
<para>
297
425
Ants Aasma <email>ants.aasma@eesti.ee</email>
298
426
</para>
299
427
</refsect1>
300
428
301
429
<refsect1>
430
+ <!--
302
431
<title>See Also</title>
432
+ -->
433
+ <title>又见</title>
303
434
304
435
<simplelist type="inline">
305
436
<member><xref linkend="sql-explain"></member>
0 commit comments