我想测量PostgreSQL进程的IOPS,我不认为我做得对。
代码:
def Postgres_Process_IO(self, pid_str):
io_dict = {}
total_io_bytes = 0
for x in range(2):
for io in self.wmi.query(
"SELECT IOReadBytesPerSec, IOWriteBytesPerSec, Timestamp_Sys100NS FROM Win32_PerfRawData_PerfProc_Process WHERE IDProcess = {}".format(
pid_str)):
io_read_bytes_1, io_write_bytes_1, time_1 = int(io['IOReadBytesPerSec']), int(io['IOWriteBytesPerSec']), long(io['Timestamp_Sys100NS'])
io_read_bytes_0, io_write_bytes_0, time_0 = io_dict.get(io, (0, 0, 0))
io_read_bytes = io_read_bytes_1 - io_read_bytes_0
io_write_bytes = io_write_bytes_1 - io_write_bytes_0
time_stamp = float((time_1 - time_0)) / 10000000
io_dict[io] = (io_read_bytes_1, io_write_bytes_1, time_1)
if x > 0:
total_io_bytes += ((io_read_bytes / time_stamp) + (io_write_bytes / time_stamp))
return total_io_bytes / 1024
与此同时,我用这个命令强调PostgreSQL服务器: " pgbench -h / tmp -i -s 60"
我的代码输出: 353626.09#KB
这似乎高达一秒钟,我做错了什么?