零基础性能测试实战直播班招生中,多种优惠进行中,优惠无套路,开课你决定       |       python自动化测试班-轻课模式,随到随学

咨询QQ:2083503238、1684129674、480934277(请勿重复咨询) 咨询微信:qiangfans

性能测试培训总结-loadrunner测试mysql

2018-02-09 15:32:00
大管家
原创 1291 投稿得红包

前言

网上很多文章都是基于windows的,或者是odbc链接的,如果当作练习可以,但实际测试的时候我们往往遇到的不是上述的情况,那么如何对mysql进行性能测试呢?


本文将已测试某条sql语句为例进行讲解,ok,下面正式开始。


Lr的mysqllib库


介绍


As most performance testers know passing data between multiple vUsers in scripts can be difficult, there may be occasions where you want to use a common set of data for multiple scripts or use data created by one script as input data for a subsequent script. Mercury developed Virtual Table Server (VTS) as a solution to this problem. Unfortunately, VTS has a number of major limitations, for example it is easy to close it down without saving data, it can't run as a service and it does not allow you to write SQL queries; instead you must use the functions provided, like lrvtc_retrieve_row() and lrvtc_query_row().


捏着鼻子读读上面的e文吧,虽然我也很方案,呵呵,还是比较简单的,大家看看把。


下载


可以到如下网址下载:


http://down.51cto.com/data/403722


安装


So easy,解压到你的loadrunner安装目录即可,是把解压后的include和bin目录放到loadrunner的安装目录哦!!!有不少童鞋可耻的直接把解压的loadrunner mysqllibs目录放到下面了,汗啊。


使用


不废话,直接上代码


Vuser_init


#define MYSQLSERVER "XXX.XXX.XXX.XXX" # mysqlip


#define MYSQLUSERNAME "XXX"# 用户名


#define MYSQLPASSWORD "XXX"# 密码


#define MYSQLDB"XXX"# 数据库


#define MYSQLPORT "XXX"# 端口



#include "Ptt_Mysql.h"引入mysql libh文件



vuser_init()


{


return 0;


}


看看,简单吧,哈哈,接着往下走


Action()


{


char chQuery[128];


MYSQL *Mconn;


lr_load_dll("libmysql.dll"); 引入libmysqldll



Mconn = lr_mysql_connect(MYSQLSERVER, MYSQLUSERNAME, MYSQLPASSWORD, MYSQLDB, atoi(MYSQLPORT));# connection mysql



sprintf(chQuery, "update 表名 set a=a+1 where id=123;"


);



lr_mysql_query(Mconn, chQuery);执行sql


lr_mysql_disconnect(Mconn);# close connection



return 0;


}



spacer.gif怎么样?还是很简单吧,就是定义点变量,然后在引入个dll,剩余的就是大家熟悉的sql了,这个是已update为例子的,select和insert大致一样,只需稍作修改即可,这里就不举例了。



至于vuser_end木有任何修改!


监控msyql


当然既然有测试,必然有监控,至于如何监控,我的blog里有不少方法,可以到http://xqtesting.blog.51cto查找。


这里我在多介绍几个命令:


l Show innodb status;


l Show processlist;


l Show open tables from db_name;


具体代表什么大家自己百度一下吧,很简单


小结


1、这个东西比较好用,非常赞一个,可以链接本地的或者远程的都ok


2、记得user要有一定权限哦


3、有时候会提示内存冲突,大家最好关闭其他软件,比如像QQ管家、foxmail等,小弟用的时候发现和这两个冲突

参考资料

http://www.bish.co.uk/forum/index.php?topic=50.0

技术交流QQ群 229390571 测试帮日记接口测试群

电影下载QQ群 533341883 XQ电影下载圈