Created
April 13, 2015 16:07
-
-
Save stickystyle/8cebde204781b7d27c90 to your computer and use it in GitHub Desktop.
Simple script to monitor the network latencey between app servers and DB servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
import timeit | |
loops = 1000 | |
setup = """ | |
import MySQLdb | |
db = MySQLdb.connect(host="remotedb.example.com", | |
read_default_file="/root/.my.cnf", | |
charset = "utf8", use_unicode = True) | |
c = db.cursor() | |
""" | |
stmt = 'c.execute("SELECT 1")' | |
t = timeit.Timer(stmt, setup) | |
total_time = t.timeit(number=loops) | |
print "Total loops: {}".format(loops) | |
print "Total time: {}".format(total_time) | |
print "Avg time per loop: {}".format(total_time / loops) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We use SELECT 1; as the test query as we only want to check for latency between the host and the mysql engine, we are not testing the database schema performance here.