python 多线程 压测 mysql
#!/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的更多相关文章
- sysbench 环境安装,压测mysql
源码路径:https://github.com/akopytov/sysbench 版本linux 6.8sysbench 0.5mysql 5.6.29 1.安装pip略 2.pip 安装bzr p ...
- jmeter压测mysql数据库
jmeter连接并压测mysql数据库,之前一直想用jmeter一下测试mysql数据库的性能,今天偶然看到一篇博客,于是乎开始自己动手实践. 一.准备工作 1.安装好mysql数据库,可以安装在本地 ...
- 【Jmeter】压测mysql数据库中间件mycat
背景 因为博主所负责测试的项目需要数据库有较大的吞吐量,在最近进行了升级,更新了一个数据库中间件 - - mycat.查询了一些资料,了解到这是阿里的一个开源项目,基于mysql,是针对磁盘的读与写, ...
- 用sysbench压测MySQL,通过orzdba监控MySQL
1.1 安装sysbench wget https://codeload.github.com/akopytov/sysbench/zip/0.5 unzip 0.5 cd sysbench-0.5/ ...
- 【Jmeter 压测MySql连接问题】
JDBC Request :Cannot load JDBC driver class 'com.mysql.jdbc.Driver'解决办法 在Jmeter中run JDBC Request时, ...
- 用mysqlslap压测mysql
参考文献:http://my.oschina.net/costaxu/blog/108568 上面网友详细的列举了用mysqlslap对mysql的压力测试结果,我也照葫芦画瓢试了一次,结果如下: 以 ...
- sysbench压测mysql
MySQL数据库测试 select 1.先创建数据库test,再准备数据 time /usr/local/sysbench/bin/sysbench --test=oltp --num-threa ...
- jmeter压测mysql报can not be represented as java.sql.Timestame错误解决方法
JDBC Request 测试mysql时报以下问题? jmeter报错信息: 解决方法: 在数据库url后拼接上字符串?characterEncoding=utf8&zeroDateTim ...
- sysbench压测mysql基本步骤
MySQL数据库测试 select 1.先创建数据库test,再准备数据 time /usr/local/sysbench/bin/sysbench --test=oltp --num-threa ...
随机推荐
- mybatis二级缓存
二级缓存区域是根据mapper的namespace划分的,相同namespace的mapper查询数据放在同一个区域,如果使用mapper代理方法每个mapper的namespace都不同,此时可以理 ...
- Linux 软连接和硬连接(转)
1.Linux链接概念Linux链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link).默认情况下,ln命令产生硬链接. [硬连接]硬连接指通过索引节点 ...
- hard(2018.10.18)
题意:给你一棵\(n\)个节点的树,\(q\)个询问,每次询问读入\(u,v,k,op\),需要满足树上有\(k\)对点的简单路径交都等于\(u,v\)之间的简单路径,\(op=1\)表示\(k\)对 ...
- Python开发 第02课 Python 数据类型
1.Python 变量类型 变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间.基于变量的数据类型,解释器会分配指定内存,并决定什么数据可以被存储在内存中.因此,变量可以指定不同的数据 ...
- HackerRank Super Six Substrings dp
https://www.hackerrank.com/contests/hourrank-18/challenges/super-six-substrings 能被6整除的数有一个特点,就是能同时被3 ...
- game 竞赛图 缩环
[问题背景] zhx 和他的妹子(们)做游戏. [问题描述] 考虑 N 个人玩一个游戏, 任意两个人之间进行一场游戏 (共 N*(N-)/ 场) , 且每场一定能分出胜负. 现在,你需要在其中找到三个 ...
- Redis的下载安装
Redis官网只提供了Linux版,MicroSoft自己搞了个Windows版,可在GitHub下载: https://github.com/microsoftarchive/redis/relea ...
- 【Linux】Tmux分屏
1.Tmux Arch维基: https://wiki.archlinux.org/index.php/Tmux_(简体中文) 官方WIKI: https://github.com/tmux/tmux ...
- 【转】HashMap,ArrayMap,SparseArray源码分析及性能对比
HashMap,ArrayMap,SparseArray源码分析及性能对比 jjlanbupt 关注 2016.06.03 20:19* 字数 2165 阅读 7967评论 13喜欢 43 Array ...
- 【js】数组去重时间复杂度为n的方法
# 时间复杂度O(n^2) function fn(arr) { return arr.filter((item, index, arr) => arr.indexOf(item) === in ...