#!/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. 买票案例 1.synchronize关键字 2.lock锁

  2. nginx 一些配置

    worker_processes 4; #工作进程数 events { #epoll是多路复用IO(I/O Multiplexing)中的一种方式, #仅用于linux2.6以上内核,可以大大提高ng ...

  3. SpringBoot | 集成Java Mail

    Spring Boot 对Java mail 集成提供了自动配置的支持,只需要配置依赖以及在application.properties 里配置邮件信息即可. 添加依赖: <dependency ...

  4. python多线程的实现

    入门案例 import threading,time ''' #线程的创建有两种方式,.直接调用,.继承 ''' # def run(n): # print('test',n) # #.直接调用 # ...

  5. Codeforces Round #396 (Div. 2) C

    Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz ...

  6. FTP任务(重点看断点续传)

    一.FTP任务目录: 1. 多用户同时登陆:     socketserver 2. 用户登陆,加密认证: md5加密 3. 上传/下载文件,保证文件一致性:md5摘要 4. 传输过程中现实进度条 5 ...

  7. how browser supports https

    1. pre-installed certificate authorities 2. ssl/tls encription ssl/tls handshake flow: 1. exchange d ...

  8. POJ 1830 开关问题 高斯消元,自由变量个数

    http://poj.org/problem?id=1830 如果开关s1操作一次,则会有s1(记住自己也会变).和s1连接的开关都会做一次操作. 那么设矩阵a[i][j]表示按下了开关j,开关i会被 ...

  9. 获取文件的MD5码(C#)

    using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace Test ...

  10. 3、从尾到头打印链表------------>剑指offer系列

    题目 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList. 分析 要了解链表的数据结构: val属性存储当前的值,next属性存储下一个节点的引用. 要遍历链表就是不断找到当前节点的nex ...