#!/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. 关于js对象参数的讨论 用街道类比

    var obj = { p: 1 }; function f(o) { o.p = 2; } f(obj); obj.p 上面代码中,传入函数f的是参数对象obj的地址.因此,在函数内部修改obj的属 ...

  2. android studio ffmpeg简单使用 (cmake)

    编译ffmpeg android studio 新建项目,勾选上 将编译好的libffmpeg.so库扔到src/main/jniLibs/armeabi下(主要这里我只编译了arm的ffmpeg的库 ...

  3. 213. 打家劫舍 II

    你是一个专业的小偷,计划偷窃沿街的房屋,每间房内都藏有一定的现金.这个地方所有的房屋都围成一圈,这意味着第一个房屋和最后一个房屋是紧挨着的.同时,相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在 ...

  4. 浅谈H5技术

    1.什么是H5:HTML5将成为HTML.XHTML以及HTML  DOM的新标准.目前仍处于完善之中.然而,大部分现代浏览器已经具备了某些HTML5支持. 2.背景:HTML5 是 W3C 与 WH ...

  5. HDU 1233(最小生成树)

    HDU 1233(最小生成树 模板) #include <iostream> #include <algorithm> #include <cstdio> usin ...

  6. JAVA设计模式之观察者模式 - Observer

    有趣的事情发生时,可千万别错过了!有一个模式可以帮你的对象知悉现况,不会错过该对象感兴趣的事.对象甚至在运行时可决定是否要继续被通知.有了观察者,你将会消息灵通. 介绍 观察者模式的定义: 在对象之间 ...

  7. 【extjs6学习笔记】0.2 准备:类库结构

  8. MySQL分表操作的例子

    USE project;DROP PROCEDURE IF EXISTS project.delete_test_user;delimiter $$CREATE PROCEDURE project.d ...

  9. JAVA的程序基本结构和数据类型

    //源程序 Hello.java public class Hello { static String str ="Hello World"; public static void ...

  10. Windows64+Python27下配置matplotlib

    注:转载请注明原作者并附上原文链接! 网上看了很多方法,均遇到这样或者那样的问题导致安装失败,最后自己摸索一条方法,最终安装成功了. 1,首先安装numpy,这个可以选择install安装包,很简单, ...