Python obtains the system iops sample code and pythoniops sample code.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.