Created
October 19, 2012 00:56
-
-
Save rpherrera/3915655 to your computer and use it in GitHub Desktop.
Inserts a record every second, so we could see if the MySQL internal engine could deal smootly with that when transition occours
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import MySQLdb as mdb | |
import sys | |
from time import sleep | |
class TimedInsert: | |
def __init__(self, connection): | |
self.connection = connection | |
def insert_entries(self, time=0): | |
cursor = connection.cursor() | |
print "Inserting entries about %d seconds: " % time | |
for i in range(int(time)): | |
cursor.execute('INSERT INTO `timezone_transition`.`current_time_entry` (`id` ,`current_time`) VALUES (NULL , CURRENT_TIMESTAMP)') | |
connection.commit() | |
sys.stdout.write('.') | |
sys.stdout.flush() | |
sleep(1) | |
cursor.close() | |
connection.close() | |
print ' OK' | |
def get_user_input(): | |
return raw_input('Host: '), raw_input('User: '), raw_input('Password: '), raw_input('Database: '), raw_input('Seconds: ') | |
if __name__ == '__main__': | |
host, user, password, database, seconds = get_user_input() | |
try: | |
connection = mdb.connect(host, user, password, database) | |
timed_insert = TimedInsert(connection) | |
timed_insert.insert_entries(seconds) | |
except mdb.Error, e: | |
print "Error %d: %s" % (e.args[0], e.args[1]) | |
sys.exit (1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment