#!/usr/bin/env python
# encoding: utf-8 #@author: 东哥加油
#@file: sthread.py
#@time: 2018/9/17 17:07 import threading
import time
import pymysql exitFlag = 0 def get_conn48():
conn = None
try:
conn = pymysql.connect(
host="192.168.1.3",
port=3308,
user="root",
passwd="mysqlpass",
charset="utf8",
)
except Exception as err:
print(err)
return conn def get_data48(sql):
conn = get_conn48()
cur = conn.cursor()
cur.execute(sql)
data = cur.fetchall()
return data class myThread (threading.Thread):
def __init__(self, threadID, counter,member_id):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = "Thread-"+str(threadID)
self.counter = counter
self.member_id = member_id
def run(self):
print ("开始线程:" + self.name)
print_time(self.name, self.counter,self.member_id)
print ("退出线程:" + self.name) def print_time(threadName, counter,member_id):
while counter:
if exitFlag:
threadName.exit() print ("%s: %s" % (threadName, time.ctime(time.time())))
conn = get_conn48()
cursor = conn.cursor() try:
# 执行sql语句
sql = ''' update goeses.tb_member_balance set modify_time = modify_time + 1 where member_id=%s '''%(member_id)
print(sql)
cursor.execute(sql)
conn.commit()
except:
# 如果发生错误则回滚
conn.rollback()
# 关闭数据库连接
conn.close()
counter -= 1 # 创建新线程
thread1 = myThread(1, 500000,1000000001)
thread2 = myThread(2, 500000,1000000002)
thread3 = myThread(3, 500000,1000000003)
thread4 = myThread(4, 500000,1000000004)
thread5 = myThread(5, 500000,1000000005)
thread6 = myThread(6, 500000,1000000006)
thread7 = myThread(7, 500000,1000000007)
thread8 = myThread(8, 500000,1000000008)
thread9 = myThread(9, 500000,1000000009)
thread10 = myThread(10, 500000,1000000010)
thread11 = myThread(11, 500000,1000000011)
thread12 = myThread(12, 500000,1000000012)
thread13 = myThread(13, 500000,1000000013)
thread14 = myThread(14, 500000,1000000014)
thread15 = myThread(15, 500000,1000000015)
thread16 = myThread(16, 500000,1000000016)
thread17 = myThread(17, 500000,1000000017)
thread18 = myThread(18, 500000,1000000018)
thread19 = myThread(19, 500000,1000000019)
thread20 = myThread(20, 500000,1000000020)
thread21 = myThread(21, 500000,1000000021)
thread22 = myThread(22, 500000,1000000022)
thread23 = myThread(23, 500000,1000000023)
thread24 = myThread(24, 500000,1000000024)
thread25 = myThread(25, 500000,1000000025)
thread26 = myThread(26, 500000,1000000026)
thread27 = myThread(27, 500000,1000000027)
thread28 = myThread(28, 500000,1000000028)
thread29 = myThread(29, 500000,1000000029)
thread30 = myThread(30, 500000,1000000030)
thread31 = myThread(31, 500000,1000000031)
thread32 = myThread(32, 500000,1000000032)
thread33 = myThread(33, 500000,1000000033)
thread34 = myThread(34, 500000,1000000034)
thread35 = myThread(35, 500000,1000000035)
thread36 = myThread(36, 500000,1000000036)
thread37 = myThread(37, 500000,1000000037)
thread38 = myThread(38, 500000,1000000038)
thread39 = myThread(39, 500000,1000000039)
thread40 = myThread(40, 500000,1000000040)
thread41 = myThread(41, 500000,1000000041)
thread42 = myThread(42, 500000,1000000042)
thread43 = myThread(43, 500000,1000000043)
thread44 = myThread(44, 500000,1000000044)
thread45 = myThread(45, 500000,1000000045)
thread46 = myThread(46, 500000,1000000046)
thread47 = myThread(47, 500000,1000000047)
thread48 = myThread(48, 500000,1000000048)
thread49 = myThread(49, 500000,1000000049)
thread50 = myThread(50, 500000,1000000050) # 开启新线程
thread1.start()
thread2.start()
thread3.start()
thread4.start()
thread5.start()
thread6.start()
thread7.start()
thread8.start()
thread9.start()
thread10.start()
thread11.start()
thread12.start()
thread13.start()
thread14.start()
thread15.start()
thread16.start()
thread17.start()
thread18.start()
thread19.start()
thread20.start()
thread21.start()
thread22.start()
thread23.start()
thread24.start()
thread25.start()
thread26.start()
thread27.start()
thread28.start()
thread29.start()
thread30.start()
thread31.start()
thread32.start()
thread33.start()
thread34.start()
thread35.start()
thread36.start()
thread37.start()
thread38.start()
thread39.start()
thread40.start()
thread41.start()
thread42.start()
thread43.start()
thread44.start()
thread45.start()
thread46.start()
thread47.start()
thread48.start()
thread49.start()
thread50.start()
thread1.join()
thread2.join()
thread3.join()
thread4.join()
thread5.join()
thread6.join()
thread7.join()
thread8.join()
thread9.join()
thread10.join()
thread11.join()
thread12.join()
thread13.join()
thread14.join()
thread15.join()
thread16.join()
thread17.join()
thread18.join()
thread19.join()
thread20.join()
thread21.join()
thread22.join()
thread23.join()
thread24.join()
thread25.join()
thread26.join()
thread27.join()
thread28.join()
thread29.join()
thread30.join()
thread31.join()
thread32.join()
thread33.join()
thread34.join()
thread35.join()
thread36.join()
thread37.join()
thread38.join()
thread39.join()
thread40.join()
thread41.join()
thread42.join()
thread43.join()
thread44.join()
thread45.join()
thread46.join()
thread47.join()
thread48.join()
thread49.join()
thread50.join() print ("退出主线程")

  

python 多线程 压测 mysql的更多相关文章

  1. sysbench 环境安装,压测mysql

    源码路径:https://github.com/akopytov/sysbench 版本linux 6.8sysbench 0.5mysql 5.6.29 1.安装pip略 2.pip 安装bzr p ...

  2. jmeter压测mysql数据库

    jmeter连接并压测mysql数据库,之前一直想用jmeter一下测试mysql数据库的性能,今天偶然看到一篇博客,于是乎开始自己动手实践. 一.准备工作 1.安装好mysql数据库,可以安装在本地 ...

  3. 【Jmeter】压测mysql数据库中间件mycat

    背景 因为博主所负责测试的项目需要数据库有较大的吞吐量,在最近进行了升级,更新了一个数据库中间件 - - mycat.查询了一些资料,了解到这是阿里的一个开源项目,基于mysql,是针对磁盘的读与写, ...

  4. 用sysbench压测MySQL,通过orzdba监控MySQL

    1.1 安装sysbench wget https://codeload.github.com/akopytov/sysbench/zip/0.5 unzip 0.5 cd sysbench-0.5/ ...

  5. 【Jmeter 压测MySql连接问题】

    JDBC Request :Cannot load JDBC driver class 'com.mysql.jdbc.Driver'解决办法   在Jmeter中run JDBC Request时, ...

  6. 用mysqlslap压测mysql

    参考文献:http://my.oschina.net/costaxu/blog/108568 上面网友详细的列举了用mysqlslap对mysql的压力测试结果,我也照葫芦画瓢试了一次,结果如下: 以 ...

  7. sysbench压测mysql

    MySQL数据库测试 select   1.先创建数据库test,再准备数据 time /usr/local/sysbench/bin/sysbench --test=oltp --num-threa ...

  8. jmeter压测mysql报can not be represented as java.sql.Timestame错误解决方法

    JDBC Request  测试mysql时报以下问题? jmeter报错信息: 解决方法: 在数据库url后拼接上字符串?characterEncoding=utf8&zeroDateTim ...

  9. sysbench压测mysql基本步骤

    MySQL数据库测试 select   1.先创建数据库test,再准备数据 time /usr/local/sysbench/bin/sysbench --test=oltp --num-threa ...

随机推荐

  1. 利用多项式实现图像几何校正(Matlab实现)

    1.原理简述:     根据两幅图像中的一些已知对应点(控制点对),建立函数关系式,通过坐标变换,实现失真图像的几何校正. 设两幅图像坐标系统之间畸变关系能用解析式来描述: 根据上述的函数关系,可以依 ...

  2. 网络编程WebSocket 和socket、HTTP的区别和联系

    一.WebSocket 是什么? WebSocket是HTML5规范提出的一种协议:目前除了完犊子的IE浏览器,其他浏览器都基本支持.他是一种协议,万变不离其宗,也是基于TCP协议的:和HTTP协议是 ...

  3. git上如何删除已有项目

    删除fork别人的项目 由于最近想删除fork别人项目,步骤如下. 点击进入需要删除fork的项目 进入Settings选项 找到delete this repository按钮 确认是否要删除,Pl ...

  4. iOS 7:漫谈#define 宏定义

           #define宏定义在C系开发中可以说占有举足轻重的作用.底层框架自不必说,为了编译优化和方便,以及跨平台能力,宏被大量使用,可以说底层开发离开define将寸步难行.而在更高层级进行开 ...

  5. JavaScript 中的面向对象编程

    使用JSON 来定义一个对象: <script type="text/javascript">var xiaoming = { name : 'xiaoming', a ...

  6. socket模拟服务器,客户端下载东西(ftp)

    服务端(ftp_server.py) import hashlib,socket,os server = socket.socket() server.bind(("localhost&qu ...

  7. 牛客寒假6-A.出题

    链接:https://ac.nowcoder.com/acm/contest/332/A 题意: 小B准备出模拟赛. 她把题目按难度分为四等,分值分别为6,7,8,9. 已知小B共出了m道题,共n分. ...

  8. Ubuntu-apt安装Jenkins

    系统环境: Ubuntu 16.0.4 2CPU,8G 1.默认Ubuntu软件包里没有Jenkins 2.系统里添加存储密钥 wget -q -O - https://pkg.jenkins.io/ ...

  9. libev 使用

    观察器 IO ev_io_init (ev_io *, callback, int fd, int events) ev_io_set (ev_io *, int fd, int events) I/ ...

  10. Sql Server 排序规则字符集的冲突问题

    可通过如下sql 进行修改: 如果整个DB都不一致: Alter database Expense_Portal collate Chinese_PRC_CI_AS 某张Table的栏位不一致: ) ...