zoukankan      html  css  js  c++  java
  • 统计每个用户的qps每秒

    import time
    import MySQLdb
    begin_dic = {}
    end_dic = {}
    last_dic = {}
    sql = """select user,sum(total),now() from user_summary_by_statement_type where user not in ('root') group by user"""
    conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='123456',port=int(3306),db='sys')
    cur=conn.cursor(MySQLdb.cursors.DictCursor)
    cur.execute(sql)
    result = cur.fetchall()
    print result 
    for rel in result:
        begin_dic.update({rel['user']:rel['sum(total)']})
    
    time.sleep(2)
    
    cur.execute(sql)
    result = cur.fetchall()
    for rel in result:
        end_dic.update({rel['user']:rel['sum(total)']})
    
    
    for i in begin_dic:
        if i in end_dic:
            val = round((end_dic[i] - begin_dic[i])/2,2)
            last_dic.update({i:val})
    cur.close()
    conn.close()
    
    
    for k,v in last_dic.items():
        print k,v 
    
    ({'sum(total)': Decimal('320498'), 'now()': datetime.datetime(2018, 1, 4, 16, 10, 45), 'user': 'user_bizbops'}, {'sum(total)': Decimal('753790'), 'now()': datetime.datetime(2018, 1, 4, 16, 10, 45), 'user': 'user_comment'}, {'sum(total)': Decimal('56'), 'now()': datetime.datetime(2018, 1, 4, 16, 10, 45), 'user': 'user_contract'}, {'sum(total)': Decimal('4331102025'), 'now()': datetime.datetime(2018, 1, 4, 16, 10, 45), 'user': 'user_wdpaiduivo'})
    user_bizbops 0.0
    user_wdpaiduivo 72.5
    user_comment 0.0
    user_contract 0.0
  • 相关阅读:
    python 的时间复杂度
    python之进制转换
    进程、线程、协程
    [GO]gtk的windows环境搭建
    [GO]并的爬取捧腹的段子
    [GO]并发的网络爬虫
    [GO]百度贴吧的爬虫
    [operator]jenkins+gitlab/Webhook自动构建发布
    [GO]并发实现聊天室服务器
    [GO]文件的收发服务器
  • 原文地址:https://www.cnblogs.com/mao3714/p/8193938.html
Copyright © 2011-2022 走看看