#!/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. C语言带参宏定义和函数的区别

    带参数的宏和函数很相似,但有本质上的区别:宏展开仅仅是字符串的替换,不会对表达式进行计算:宏在编译之前就被处理掉了,它没有机会参与编译,也不会占用内存.而函数是一段可以重复使用的代码,会被编译,会给它 ...

  2. java泛型笔记一

    名词:泛型类 泛型方法 原始类型 子类型 版本 参数化类型 通配符类型 超类通配 子类通配 全通配 定义变量 创建对象 检查模板 类型实参 类型形参 补充 替代语法特征:尖括号括起来的类型参数表 // ...

  3. E - Round Numbers

    #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> ...

  4. Java EE学习笔记(三)

    Spring AOP 1.Spring AOP简介 1).AOP的全称是Aspect-Oriented Programming,即面向切面编程(也称面向方面编程).它是面向对象编程(OOP)的一种补充 ...

  5. JAVA常用知识总结(十二)——数据库(二)

    MySQL主从热备份工作原理 简单的说:就是主服务器上执行过的sql语句会保存在binLog里面,别的从服务器把他同步过来,然后重复执行一遍,那么它们就能一直同步啦. 整体上来说,复制有3个步骤: 作 ...

  6. python flask学习(2)

    本文主要整理下几个Flask扩展: 0.Flask-Bootstrap:集成Twitter开发的一个开源框架Bootstrap.1.Flask-Script:为Flask程序添加一个命令行解析器2.F ...

  7. nodejs 快要变成爬虫界的王者

    nodejs 快要变成爬虫界的王者 爬虫这东西是很多数据采集必须要的东西. 但是现在随着网页不断发展,已经出现了出单纯的网页,到 ajax 网页, 再到 spa , 再到 websocket 应用,一 ...

  8. Kettle Rest大文件上传(RestUploadFile.ktr) Rest文件下载(FileDownload.ktr)

    1. Rest大文件上传(RestUploadFile.ktr) 需求描述 上传文件大于10M小于500M 上传文件进行分片(5M一片要比1M分片整体时间快) 先使用java类进行功能模拟在迁移Ktr ...

  9. python第一模块数据类型

    一·进制之间的转换 十进制转换为二进制:逆序取余法. 二进制转换为十进制:如1101  1*2^0 + 0*2^1 + 1*2^2 +1 十六进制转换为二进制:231     0010  0011   ...

  10. NSTimer 实现时钟回调方法

    在开发过程中,发现时钟调用的地方比较多.所以对时钟进行了一个简单的统一封装.具体代码如下: 1.时钟回调函数的声明: #pragma mark 时钟回调处理 //时钟回调 +(NSTimer*) ls ...