天天看點

LoadRunner驅動MySQL性能測試

  而lr本身推薦的是使用提供的dll庫或者自行編寫dll庫進行測試。

  隻要能在網上找到支援自編寫dll庫的license即可

  本文方法參考的主要是bish.co.uk論壇,有mysql,php和loadrunner闆塊,

  使用它們編寫的mysql連結庫

  ---–待測試庫環境準備--------

  grant all privileges on *.* to'root'@'windowsip'

  identified by'root'withgrantoption;

  -----–loadrunner運作庫準備-------

  a.解壓mysql loadrunner libraries.zip版本1 版本2 中的檔案至lr安裝目錄

  b.在lr的vuser腳本的init中加入執行個體資訊

#include "ptt_mysql.h"

#define mysqlserver "192.168.2.5"

#define mysqlusername "root"

#define mysqlpassword "root"

#define mysqldb "tpch_1"

#define mysqlport "5029"

  lr_load_dll("libmysql.dll");

  -------–vu腳本編寫方法,c語言--------–

//action中加入

char chquery[128];

mysql *mconn;

//将sql語句儲存在 char中

lr_load_dll("libmysql.dll");

//每個sql前加入讀取dll庫

mconn = lr_mysql_connect(mysqlserver, mysqlusername,

mysqlpassword, mysqldb,

atoi(mysqlport));

//從init的define中讀取連接配接參數

sprintf(chquery, "select n_nationkey,n_name,n_regionkey from

nation limit 3;");

lr_mysql_query(mconn, chquery);

//在輸出中列印語句,調用dll中的lr_mysql_query方法執行語句

lr_save_string(row[0][0].cell, "sn_nationkey");

lr_save_string(row[1][0].cell, "sn_name");

lr_save_string(row[2][0].cell, "sn_regionkey");

//結果集要儲存到多元數組中也可以直接忽略輸出

lr_output_message(lr_eval_string("n_nationkey: {sn_nationkey};

n_name: {sn_name}; n_regionkey description:{sn_regionkey}"));

lr_save_string(row[0][1].cell, "sn_nationkey");

lr_save_string(row[1][1].cell, "sn_name");

lr_save_string(row[2][1].cell, "sjobdesc");

n_name: {sn_name}; n_regionkey description:{

//vu_end中加入

lr_mysql_disconnect(mconn);

//斷開連接配接

自己錄制腳本例子

#define mysqlserver "192.168.20.67"

#define mysqlpassword "111111"

#define mysqldb    "mysql"

#define mysqlport "3306"

vuser_init(){

lr_load_dll("libmysql.dll");

mconn=lr_mysql_connect(mysqlserver,mysqlusername,mysqlpassword,mysqldb,atoi(mysqlport));

return 0;

}

action()

{

//sprintf(chquery,"select `host`, `user`, `password` from user1;");

lr_mysql_query(mconn,chquery);

lr_save_string(row[0][0].cell,"host");

lr_save_string(row[1][0].cell,"user");

lr_save_string(row[2][0].cell,"password");

lr_output_message(lr_eval_string("host: {host}; user: {user};password:{password}"));

vuser_end()

lr_mysql_disconnect(mconn);

原創作品,轉載時請務必以超連結形式标明本文原始出處、作者資訊和本聲明,否則将追究法律責任。

最新内容請見作者的github頁:http://qaseven.github.io/