Skip to content

Instantly share code, notes, and snippets.

@Hyunho
Last active Aug 29, 2015
Embed
What would you like to do?
print TPS and number of tuples for transactions

transaction 기록 출력 문서

실행방법

아래의 명령어를 실행하도록 합니다.

% ./print_dbtps

출력결과 형식

아래와 같은 형식으로 출력되며 ~/mmdb/trace/디렉토리에 DB_TPS.(date).csv 이름으로 저장됩니다.

(date, select_tps, update_tps, insert_tps, delete_tps, num_PRIVATE_TBL, num_PUBLIC_TBL)

출력결과 예시

% tail ~/mmdb/trace/DB_TPS.2015-03-19.cvs
2015-03-19 14:14:01, 2, 0, 0, 0, 23646121, 25546128
2015-03-19 14:14:02, 2, 0, 0, 0, 23646121, 25546128
2015-03-19 14:14:03, 2, 0, 0, 0, 23646121, 25546128
2015-03-19 14:22:44, 1, 0, 0, 0, 23646121, 25546128
2015-03-19 14:22:45, 2, 0, 0, 0, 23646121, 25546128

#!/bin/sh
while true
do
python print_tps.py -c 1 >> ~/mmdb/trace/DB_TPS.`date +"%Y-%m-%d"`.csv
sleep 5
done
#!/usr/bin/python
import commands, sys
import datetime, time
import re
from optparse import OptionParser
def grep(pettern, output):
matched_lines = list()
for line in output.split('\n'):
if re.search(pettern, line) :
matched_lines.append(line)
return matched_lines
def sum_up_tps(matched_lines):
sum_of_tps = 0
for line in matched_lines:
tps = int(line.split()[0])
sum_of_tps = sum_of_tps + tps
return sum_of_tps
def print_transaction_infos(interval, repeated_times = None):
# print "(date, select_tps, update_tps, insert_tps, delete_tps, num_PRIVATE_TBL, num_PUBLIC_TBL)"
while True:
status, output = commands.getstatusoutput('mdb_client -s "show transactions"')
#print output
matched_lines = grep("SELECT", output)
select_tps = sum_up_tps(matched_lines)
matched_lines = grep("UPDATE", output)
update_tps = sum_up_tps(matched_lines)
matched_lines = grep("INSERT", output)
insert_tps = sum_up_tps(matched_lines)
matched_lines = grep("DELETE", output)
delete_tps = sum_up_tps(matched_lines)
status, output = commands.getstatusoutput(
""" mdb_client -b - -t " " -s "select NUMTUPLES from __tables__ where TABLE_NAME = 'PRIVATE_TBL'" | tail -n 1""")
num_private_tbl = int(output)
status, output = commands.getstatusoutput(
""" mdb_client -b - -t " " -s "select NUMTUPLES from __tables__ where TABLE_NAME = 'PUBLIC_TBL'" | tail -n 1""")
num_public_tbl = int(output)
print ("%s, %d, %d, %d, %d, %d, %d" % (
str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")), select_tps, update_tps, insert_tps, delete_tps,
num_private_tbl, num_public_tbl))
if type(repeated_times) == int:
repeated_times = repeated_times - 1;
if repeated_times <= 0 :
return 0
time.sleep(interval)
def dummy_transactions():
status, output = commands.getstatusoutput('mdb_client -s "create table dummy (a int);"')
status, output = commands.getstatusoutput('mdb_client -s "insert into dummy values (1)"')
status, output = commands.getstatusoutput('mdb_client -s "select a from dummy"')
status, output = commands.getstatusoutput('mdb_client -s "update dummy set a=2 where a=1"')
status, output = commands.getstatusoutput('mdb_client -s "update dummy set a=2"')
status, output = commands.getstatusoutput('mdb_client -s "delete from dummy"')
status, output = commands.getstatusoutput('mdb_client -s "drop table dummy;"')
if __name__=="__main__":
usage = "usage: %prog interval(s)"
parser = OptionParser(usage=usage)
parser.add_option("-t", "--test",
action="store_true", dest="test", default=False,
help="clear provious transactions and burst dummy trasactions first to test.")
parser.add_option("-c", "--count",
type="int", dest="count", default=None,
help="show a transaction n times.")
parser.add_option("-i", "--interval",
type="int", dest="interval", default=5)
(options, args) = parser.parse_args()
if options.test == True:
print "Clear provious transactions and burst dummy trasactions first to test. "
print
status, output = commands.getstatusoutput('mdb_client -s "show transactions"')
for i in range(10):
dummy_transactions()
interval = options.interval
count = options.count
print_transaction_infos(interval, count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment