edit-icon download-icon

How to check node performance?

Last Updated: Jan 12, 2018

Background

A cluster instance of ApsaraDB for Redis has multiple nodes. To use the service, you need to view the memory and number of keys of each subnode. Currently, Alibaba Cloud provides the iinfo command used to view the performance of a node. In the future, you will be able to view the node data on the console.

  1. iinfo db_idx [section]

db_idx indicates the number of nodes, whose range is [0, nodecount). You can obtain nodecount by using the info command. section is set in the same way as the Redis’ standard optional parameters for the info command.

Procedure

  1. Download the Python client.

    1. wget "https://pypi.python.org/packages/68/44/5efe9e98ad83ef5b742ce62a15bea609ed5a0d1caf35b79257ddb324031a/redis-2.10.5.tar.gz#md5=3b26c2b9703b4b56b30a1ad508e31083"
  2. Decompress and install the Python client.

    1. tar -xvf redis-2.10.5.tar.gz
    2. cd redis-2.10.5
    3. sudo python setup.py install
  3. Run the following scan script:

    1. import sys
    2. import redis
    3. from redis._compat import nativestr
    4. def parse_info(response):
    5. "Parse the result of Redis's INFO command into a Python dict"
    6. info = {}
    7. response = nativestr(response)
    8. def get_value(value):
    9. if ',' not in value or '=' not in value:
    10. try:
    11. if '.' in value:
    12. return float(value)
    13. else:
    14. return int(value)
    15. except ValueError:
    16. return value
    17. else:
    18. sub_dict = {}
    19. for item in value.split(','):
    20. k, v = item.rsplit('=', 1)
    21. sub_dict[k] = get_value(v)
    22. return sub_dict
    23. for line in response.splitlines():
    24. if line and not line.startswith('#'):
    25. if line.find(':') != -1:
    26. key, value = line.split(':', 1)
    27. info[key] = get_value(value)
    28. else:
    29. # if the line isn't splittable, append it to the "__raw__" key
    30. info.setdefault('__raw__', []).append(line)
    31. return info
    32. if __name__ == '__main__':
    33. if len(sys.argv) != 4:
    34. print 'Usage: python ', sys.argv[0], ' host port password '
    35. exit(1)
    36. db_host = sys.argv[1]
    37. db_port = sys.argv[2]
    38. db_password = sys.argv[3]
    39. r = redis.StrictRedis(host=db_host, port=int(db_port), password=db_password)
    40. nodecount = r.info()['nodecount']
    41. for node in range(0, nodecount):
    42. info = r.execute_command("iinfo", str(node))
    43. info_res = parse_info(info)
    44. print "============ node ", str(node), " ================"
    45. print 'used_memory_human:', info_res['used_memory_human']
    46. print r.execute_command("iinfo", str(node), "keyspace")
    47. info_res = r.info()
    48. print "============ total ================"
    49. print 'used_memory_human:', info_res['used_memory_human']
    50. print r.info('keyspace')

    Run the python check_sharding_db host port password command. The command output is as follows:

    1. ============ node 0 ================
    2. used_memory_human: 37.56M
    3. # Keyspace
    4. db0:keys=9887,expires=0,avg_ttl=0
    5. ============ node 1 ================
    6. used_memory_human: 37.58M
    7. # Keyspace
    8. db0:keys=9835,expires=0,avg_ttl=0
    9. db1:keys=1,expires=0,avg_ttl=0
    10. ============ node 2 ================
    11. used_memory_human: 41.24M
    12. # Keyspace
    13. db0:keys=9956,expires=0,avg_ttl=0
    14. db1:keys=1,expires=0,avg_ttl=0
    15. ============ node 3 ================
    16. used_memory_human: 37.58M
    17. # Keyspace
    18. db0:keys=9863,expires=0,avg_ttl=0
    19. ============ node 4 ================
    20. used_memory_human: 37.61M
    21. # Keyspace
    22. db0:keys=10045,expires=0,avg_ttl=0
    23. ============ node 5 ================
    24. used_memory_human: 37.58M
    25. # Keyspace
    26. db0:keys=10038,expires=0,avg_ttl=0
    27. ============ node 6 ================
    28. used_memory_human: 37.58M
    29. # Keyspace
    30. db0:keys=10055,expires=0,avg_ttl=0
    31. ============ node 7 ================
    32. used_memory_human: 37.57M
    33. # Keyspace
    34. db0:keys=9969,expires=0,avg_ttl=0
    35. ============ total ================
    36. used_memory_human: 304.31M
    37. {'db1': {'keys': 2, 'expires': 0, 'avg_ttl': 0}, 'db0': {'keys': 79648, 'expires': 0, 'avg_ttl': 0}}
Thank you! We've received your feedback.