Python obtains the system iops sample code and pythoniops sample code.
Iops Overview
Iops is mainly used for data. This indicator is an important reference for database performance evaluation. iops refers to the number of read/write (I/O) operations per second, mainly depending on the random access performance, generally, disk arrays are used to increase iops. The actual online databases are basically configured with raid 10. In actual production environments, raid5 cannot withstand pressure, of course, you also need to set specific business pressure. If you are using a physical machine, you need to check how much iops can actually run. Now the cloud is also common. If you are using an RDS cloud database, this iops can be selected based on the business situation. It is basically a parameter and can be modified as needed. Of course, the higher the value, the higher the cost.
Python obtains the system iops Code as follows:
#!/usr/bin/pythonimport os, time, mathrun_tests = 3devices = os.listdir('/sys/block/')check_devices = []reads = {}writes = {}for dev in devices: if dev.startswith('md') or dev.startswith('sd') or dev.startswith('hd'): check_devices.append(dev) reads[dev] = [] writes[dev] = []check_devices = sorted(check_devices)for t in range(run_tests + 1): for dev in check_devices: file_data = open('/sys/block/%s/stat' % dev).readline().strip().split(' ') clean = [] for num in file_data: if num != '': clean.append(int(num)) reads[dev].append(clean[0]) writes[dev].append(clean[4]) print reads[dev] print writes[dev] time.sleep(1)print "Device Read Write"print "--------------------------------------"for dev in check_devices: clean_reads = [] reads[dev].reverse() for test, result in enumerate(reads[dev]): if test > 0: clean_reads.append(float(reads[dev][test - 1] - result)) rops = int(math.ceil(sum(clean_reads) / len(clean_reads))) clean_writes = [] writes[dev].reverse() for test, result in enumerate(writes[dev]): if test > 0: clean_writes.append(float(writes[dev][test - 1] - result)) wops = int(math.ceil(sum(clean_writes) / len(clean_writes))) print "%s %s %s" % (dev.ljust(13), repr(rops).ljust(11), repr(wops))
Summary
The above is all about Python's iops. I hope this article will help you learn and use python. If you have any questions, please leave a message.