import string
import argparse
import random
import threading
import time
from contextlib import contextmanager
import pymysql
DB_NAME='test_insert_data_db'
TABLE_NAME='test_insert_data_table'
CREATE_TABLE_STATEMENT="""create table {0} (id int(10) AUTO_INCREMENT,
name varchar(255),
datetime double,
PRIMARY KEY(id))""".format(TABLE_NAME)
def _argparse():
parse=argparse.ArgumentParser(description='benchmark tool for mysql database')
parse.add_argument('--host',action='store',dest='host',required=True,help='connect to host')
parse.add_argument('--user',action='store',dest='user',required=True,help='user for login')
parse.add_argument('--password',action='store',dest='password',required=True,help='password to use when connecting to server')
parse.add_argument("--port",action='store',dest='port',default=3306,type=int,help='port number to use for connection or 3306')
parse.add_argument('--thread_size',action='store',dest='thread_size',default=5,type=int,help='how much connection for database')
parse.add_argument('--row_size',action='store',dest='row_size',default=5000,type=int,help='how much rows')
parse.add_argument('-v','--version',action='version',version='%(prog)s 0.1')
return parse.parse_args()
@contextmanager
def get_conn(**kwargs):
conn=pymysql.connect(**kwargs)
try:
yield conn
finally:
conn.close()
def create_db_and_table(conn):
with conn as cur:
for sql in ['drop database if exists {0}'.format(DB_NAME),
'create database {0}'.format(DB_NAME),
'use {0}'.format(DB_NAME),
CREATE_TABLE_STATEMENT]:
print(sql)
cur.execute(sql)
def random_string(length=10):
s=string.ascii_letters+string.digits
return "".join(random.sample(s,length))
def add_row(cursor):
SQL_FORMAT="INSERT INTO {0} (name,datetime) values ('{1}','{2}')"
sql=SQL_FORMAT.format(TABLE_NAME,random_string(),time.time())
cursor.execute(sql)
def insert_data(conn_args,row_size):
with get_conn(**conn_args) as conn:
with conn as c:
c.execute('use {0}'.format(DB_NAME))
with conn as c:
for i in range(row_size):
add_row(c)
conn.commit()
def main():
parse=_argparse()
conn_args=dict(host=parse.host,user=parse.user,password=parse.password,port=parse.port)
with get_conn(**conn_args) as conn:
create_db_and_table(conn)
thread=[]
for i in range(parse.thread_size):
t=threading.Thread(target=insert_data,args=(conn_args,parse.row_size))
thread.append(t)
t.start()
for t in thread:
t.join()
if __name__ == '__main__':
main()
相关推荐
unity 腾讯地图sdk移动和缩放代码
unity 腾讯地图sdk 实现移动端 缩放 和 移动
MySQL 如何快速插入大量测试数据
我们要确保生成的测试数据要有足够的随机性,测试结果才会更准确,如果某个字段的测试数据都是一样的,索引的效率会大大折扣,测试结果往往与真实数据的执行结果大相径庭我们可以使用 MySQL 的自定义函数来实现随机值的生成,下面罗列出几种常见的字段的函数定义。
linux应用程序段错误调试
一、堆、栈 在分析段错误之前,先了解一下什么是堆?什么是栈? 堆:一般由开发者分配释放,如果没有释放,程序结束时,在有的OS中可能会被自动释放,分配方式类似于链表。堆的操作方式为,队列优先,先进先出的原则。 栈:由操作系统自动分配,存放函数的参数值,局部变量。栈的操作方式为,先进后出的原则。 堆栈中定义了一些操作。 两个最重要的是PUSH和POP。 PUSH:操作在堆栈的顶部加入一个元素...
MySQL实现字段自动填充功能
MySQL实现字段自动填充功能
Optisystem软件与Matlab软件的联合数据读取
目录 Matlab软件程序编写 Optisystem软件的连接与设置 数据读取结果 Matlab软件程序编写 利用Matlab软件按照下图编写程序,保存为getdata.m文件。 OutputPort1 =InputPort1; fileID=fopen('OSAdata.txt','wt'); fprintf(fileID,'%f\n',OutputPort1.Sampled.Signal); fclose(fileID); Optisystem软件的连接与设置 (以基于线性插值法
Linux驱动学习--HCI框架及源码分析
目录 一、引言 二、HCI框架 三、pcm_read简要分析 一、引言 最近一直在分析蓝牙驱动,发现在底层驱动与上层协议栈间还有一层HCI,主机控制层,两者之间通过HCI协议通讯 而Linux也将HCI协议抽象层了一个框架。 为上层提供一个统一的接口,让上层协议不依赖于具体硬件的实现。HCI在硬件中的固件与HCI在主机端的驱动通信方式有多种,比如像 UART、USB和PC Card等等。hci_core.c相当于一个框架,用于把各种具体通信方式绞合起来,并提供一些公共函数的实现。 今天就来简单的分析一下 二
mysql---为测试数据库填充大量数据
一、创建一个数据库bigdata 二、创建表 CREATE TABLE `single_table` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(50) DEFAULT NULL, `post` TEXT, PRIMARY KEY (`id`) ) ENGINE=MYISAM DEFAULT CHARSET=utf8;
AI大模型探索之路-认知篇1-全景透视:揭秘AIGC技术的进化之路
随着人工智能技术的突飞猛进,内容创作方式的发生了革命性的转变;从早期专业人员主导的内容生产,到现如今生成式人工智(AIGC)能创作时代;本篇文章主要讲解AIGC技术的演变历程。
【MySQL】MySQL批量插入测试数据的几种方式
在开发过程中我们不管是用来测试性能还是在生产环境中页面展示好看一点, 又或者学习验证某一知识点经常需要一些测试数据, 这个时候如果手敲的话, 十行二十行还好, 多了就很死亡了, 接下来介绍两种常用的MySQL测试数据批量生成方式存储方式+函数Navicat的数据生成。
【图论】系列(七)图论的中心性度量方法及重要性评价指标
图论中的中心性度量方法是用来衡量图中各个节点(或顶点)相对重要性的指标。
planning模块(6)-参考线的平滑(二次规划)
上一篇已经介绍了采样点生成锚点数据的过程,并且将所有采样点生成的锚点数据设置到了平滑器中.接下来继续介绍使用二次规划平滑参考线的算法过程.从锚点数据中提取坐标存入raw_point2d,提取横向边界存入anchorpoints_lateralbound,将起点和终点的横向边界设置为0,防止车在起点和终点位置偏离车道中心线.
mysql数据库如何实现自动空值自动填充
在mysql中,假设我们由这样一个需求,现在搞到了一批数据,需要对这些数据进行预处理,其中一项就是数据中有一部分空值,现在我们要根据含有空值的这一列进行自动向前填充,用前面一行的值填充当前行,如果前面一行的值也是空值,那么再往前推,直到找到一行的值不是空值,就用它填充这些空值。-- 如果当前行的 convertible_rate 不为 NULL,则更新 prev_rate。-- 如果当前行的 convertible_rate 为 NULL,则用前一行的值替换。-- 如果遍历完数据,退出循环。
WIFI和BT测试(射频工程师)
买不了吃亏买不了上当,我卖的是技能,你收获的是经验。
MySQL随机数据生成器:测试数据库的利器
MySQL随机数据生成器:测试数据库的利器 在我们的日常开发和测试中,往往需要为MySQL数据库填充大量的测试数据以模拟真实环境。这是一项繁琐且重复性高的工作,而Percona Lab开源的mysql_random_data_load项目正为此问题提供了解决方案。 项目介绍 mysql_random_data_load是一个智能的数据生成工具,能够根据指定表结构自动生成对应的随机数据。这个项目处于...
Camera2Demo
在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作
jdk-8u144-linux-x64.tar.gz.
该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包
python3 mysql 封装多表_Python3 & 实现向Mysql表中插入10w条不同测试数据
场景:做性能测试,向Mysql数据库,student表中插入10w条测试数据,每条数据不重复。解决方案:这里采用Python自动生成SQL,再执行已生成好的SQL往Mysql数据库插入数据。使用语言:python 3.8准备SQL 语句,需每条 id 不重复 ,创建student表create table student(s_no int primary key auto_increment,s_...
WINCC7.3破解文件
WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!
mysql利用存储过程造随机数据
mysql –建表 create table dxp_qgm_test_three( id bigint(20) PRIMARY KEY, dom_datatime VARCHAR(255), dom_id bigint(20), dom_string varchar(255)); –创建存储过程 SELECT CONCAT( ‘2018-11-’ , LPAD(FLOOR(1 + RAND() * 30), 2, 0),-- 01-30 ’ ', LPAD(FLOOR(RAND() * 24), 2, 0
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
用MySQL快速验证你的应用创意原型
作为一个经常需要验证产品想法的开发者,我发现数据模型的设计往往是最耗时的环节之一。最近发现了一个特别高效的方法,几分钟就能搞定原本需要半天的工作量。特别是数据库设计,既要考虑表结构,又要写各种SQL语句,等这些都弄完,验证想法的热情可能都消磨殆尽了。如果能快速生成一个可用的数据库原型,就能立即开始核心功能的开发。不需要配置本地环境,打开网页就能直接使用,生成的原型可以一键部署测试,省去了很多繁琐的步骤。从想法到可运行的原型,可能只需要喝杯咖啡的时间。- 自动生成了用户表、帖子表、评论表等。
mysql数据库批量插入测试数据
1.首先需要一个基础表。(并加入10条数据) CREATE TABLE sample( id INT(11) NOT NULL AUTO_INCREMENT, value INT(5) NOT NULL DEFAULT 0, PRIMARY KEY (id) ); INSERT INTO sample(value) VALUES (1), (2), (3), (4), (5),...
测试数据 生成的研究
文章目录1.使用java代码生成千万数据的例子2.使用mysql生成千万数据的例子,源自韩顺平mysql教程 1.使用java代码生成千万数据的例子 使用java 生成测试数据 表结构 drop database if exists datatest; create database datatest; use datatest; CREATE TABLE datamillion ( sname...
python-mysql-为数据库生成测试数据
测试表 create table single_table ( id int not null auto_increment, key1 varchar(100), key2 int, key3 varchar(100), key_part1 varchar(100), key_part2 varchar(100), key_part3 va...
mysql利用存储过程批量插入数据
近期须要測试一下mysql单表数据达到1000W条以上时增删改查的性能。因为没有现成的数据,因此自己构造。本文仅仅是实例。以及简单的介绍。 首先当然是建表: CREATE TABLE `fortest` ( `ID` INT(30) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `IP` VARCHAR(32) NOT NULL...
Starship 安装完全指南:4 步搞定跨 Shell 终端提示符
Starship 是一款极简、极速、可无限定制的跨 Shell 终端提示符。跟着本文 4 步完成 Starship 安装,你就能让提示符自动显示 Git 分支、语言运行时版本、电池电量等上下文信息,同时保持提示符简洁。全程命令都能直接复制执行。 [将导致服务器将几个额外字段写入日志Log_s...
使用Sysbench进行MySQL数据库性能测试
使用Sysbench进行MySQL数据库性能测试
1283



被折叠的 条评论
为什么被折叠?



