good luck for opensource! by: cpp.la 磁盘IO:因为IOPS原因,SSD和HDD、包括RAID卡,ZFS等阵列技术。IO对性能的影响还需要结合自身服务器情况来判断。 比如我这里是机械硬盘,大量做随机小文件读写,那么很低的读写也就能造成硬盘长时间的等待。 如果这里做连续性IO,那么普通机械硬盘写入到100Mb/s,那么也能造成硬盘长时间的等待。 磁盘读写有误差:4k,8k ,https://stackoverflow.com/questions/34413926/psutil-vs-dd-monitoring-disk
()
| 265 | time.sleep(INTERVAL) |
| 266 | |
| 267 | def _disk_io(): |
| 268 | ''' |
| 269 | good luck for opensource! by: cpp.la |
| 270 | 磁盘IO:因为IOPS原因,SSD和HDD、包括RAID卡,ZFS等阵列技术。IO对性能的影响还需要结合自身服务器情况来判断。 |
| 271 | 比如我这里是机械硬盘,大量做随机小文件读写,那么很低的读写也就能造成硬盘长时间的等待。 |
| 272 | 如果这里做连续性IO,那么普通机械硬盘写入到100Mb/s,那么也能造成硬盘长时间的等待。 |
| 273 | 磁盘读写有误差:4k,8k ,https://stackoverflow.com/questions/34413926/psutil-vs-dd-monitoring-disk-i-o |
| 274 | :return: |
| 275 | ''' |
| 276 | while True: |
| 277 | # pre pid snapshot |
| 278 | snapshot_first = {} |
| 279 | # next pid snapshot |
| 280 | snapshot_second = {} |
| 281 | # read count snapshot |
| 282 | snapshot_read = 0 |
| 283 | # write count snapshot |
| 284 | snapshot_write = 0 |
| 285 | # process snapshot |
| 286 | pid_snapshot = [str(i) for i in os.listdir("/proc") if i.isdigit() is True] |
| 287 | for pid in pid_snapshot: |
| 288 | try: |
| 289 | with open("/proc/{}/io".format(pid)) as f: |
| 290 | pid_io = {} |
| 291 | for line in f.readlines(): |
| 292 | if "read_bytes" in line: |
| 293 | pid_io["read"] = int(line.split("read_bytes:")[-1].strip()) |
| 294 | elif "write_bytes" in line and "cancelled_write_bytes" not in line: |
| 295 | pid_io["write"] = int(line.split("write_bytes:")[-1].strip()) |
| 296 | pid_io["name"] = open("/proc/{}/comm".format(pid), "r").read().strip() |
| 297 | snapshot_first[pid] = pid_io |
| 298 | except: |
| 299 | if pid in snapshot_first: |
| 300 | snapshot_first.pop(pid) |
| 301 | |
| 302 | time.sleep(INTERVAL) |
| 303 | |
| 304 | for pid in pid_snapshot: |
| 305 | try: |
| 306 | with open("/proc/{}/io".format(pid)) as f: |
| 307 | pid_io = {} |
| 308 | for line in f.readlines(): |
| 309 | if "read_bytes" in line: |
| 310 | pid_io["read"] = int(line.split("read_bytes:")[-1].strip()) |
| 311 | elif "write_bytes" in line and "cancelled_write_bytes" not in line: |
| 312 | pid_io["write"] = int(line.split("write_bytes:")[-1].strip()) |
| 313 | pid_io["name"] = open("/proc/{}/comm".format(pid), "r").read().strip() |
| 314 | snapshot_second[pid] = pid_io |
| 315 | except: |
| 316 | if pid in snapshot_first: |
| 317 | snapshot_first.pop(pid) |
| 318 | if pid in snapshot_second: |
| 319 | snapshot_second.pop(pid) |
| 320 | |
| 321 | for k, v in snapshot_first.items(): |
| 322 | if snapshot_first[k]["name"] == snapshot_second[k]["name"] and snapshot_first[k]["name"] != "bash": |
| 323 | snapshot_read += (snapshot_second[k]["read"] - snapshot_first[k]["read"]) |
| 324 | snapshot_write += (snapshot_second[k]["write"] - snapshot_first[k]["write"]) |
nothing calls this directly
no outgoing calls
no test coverage detected