51Testing软件测试论坛

标题: 虚拟500个用户同时对数据库进行插入操作,每个用户循环插入30条数据。该怎么设计呢 [打印本页]

作者: bustersword    时间: 2011-5-1 16:31
标题: 虚拟500个用户同时对数据库进行插入操作,每个用户循环插入30条数据。该怎么设计呢
本帖最后由 bustersword 于 2011-5-5 09:47 编辑

我的脚本是单用户登陆系统并插入2张图片,然后注销,
然后我迭代插入的action15次。什么参数化,关联,搞好后,我就放到controller中了,虚拟500个用户,直接运行- -
然后结果就是数据库了只进入了1000多条数据,理论上应该有15000条数据的.......我感觉是时间太紧凑了,用户之间的操作,来不及响应?
我也设置thinktime的,难道没用么?
大大们给点帮助,谢谢了,第一次用loadrunner测试系统.....实在没办法老大突然叫测性能,我了个去,叫我一个开发的做测试,还好以前摸过loadrunner,不过也只是鸡毛蒜皮,实在没办法,求助大大们,帮帮忙

以上的 丢失 ,我通过改写脚本,不会出现这么大量的丢失了,是我脚本每写好的原因,现在的问题是我下面遇到的。。。请大家看接下去回答的部分,需要翻页,真不好意思 19楼往下
作者: zhongmiao88    时间: 2011-5-2 08:06
脚本在那台负载机上可以成功运行
作者: andyfly_001    时间: 2011-5-2 11:26
看楼主的情况要么是连接超时,要么是写操作有错误,看日志就明了。
作者: bustersword    时间: 2011-5-2 15:46
我想问,怎样的脚本在control中运行,才能合理,测出系统的性能
作者: bustersword    时间: 2011-5-2 15:48
我的脚本是没问题的,少量用户执行,也行,就是500用户- -......
作者: herryshell    时间: 2011-5-2 17:08
看你的描述,我决得你现在是单用户执行了15次同样的操作
而不是每个用户执行一次操作后注销.
作者: msnshow    时间: 2011-5-2 17:33
这个得一步步的来查原因,可能原因太多
作者: bustersword    时间: 2011-5-2 17:45
明天去公司,把脚本给给位看看,还有什么执行结果,再研究研究
作者: bustersword    时间: 2011-5-3 13:41
我又来了,今天我用50个用户跑了一遍,成功 导入1500条数据
Maximum Running Vusers:50
Total Throughput (bytes):[/url]633,007,167
Average Throughput (bytes/second):[/url]831,810
Total Hits:[/url]19,750
Average Hits per Second:[/url]25.953  View HTTP Responses Summary[/url]


Transaction Summary

Transactions:[/url]Total Passed: 3,950Total Failed: 0Total Stopped: 0         Average Response Time[/url]

Transaction NameMinimumAverageMaximumStd. Deviation90 PercentPassFailStop
Action_Transaction5.43413.57322.1492.39716.44175000
inputend0.1061.8095.2021.3483.62275000
inputselect1.4454.4397.5421.1545.69275000
login2.5312.7323.1240.1562.9865000
loginout0.0010.0721.9710.2950.0265000
save10.1652.1815.5911.316475000
save20.1851.685.8050.9452.91475000
vuser_end_Transaction0.0010.0721.9710.2950.0265000
vuser_init_Transaction4.2124.6425.1990.2494.9235000

HTTP Responses Summary

HTTP ResponsesTotalPer second
HTTP_20018,95024.901
HTTP_3028001.051








save1与save2 就是保存数据的transaction


然后 我用100个用户跑的时候,又出问题了,只插入了2731条数据,其实应该插入3000条,又丢失了.....




作者: bustersword    时间: 2011-5-3 13:43
cenario Name:Scenario1
Results in Session:d:\100users\res\res.lrr
Duration:15 minutes and 43 seconds.

Statistics Summary

Maximum Running Vusers:100
Total Throughput (bytes):1,266,942,752
Average Throughput (bytes/second):1,342,100
Total Hits:39,500
Average Hits per Second:41.843  View HTTP Responses Summary

Transaction Summary

Transactions:Total Passed: 7,900Total Failed: 0Total Stopped: 0         Average Response Time

Transaction NameMinimumAverageMaximumStd. Deviation90 PercentPassFailStop
Action_Transaction7.85625.77747.0447.19735.1071,50000
inputend0.0044.0248.9742.166.7581,50000
inputselect2.6868.80514.4182.10411.0921,50000
login0.0731.7513.0940.6362.48210000
loginout0.0010.6572.2660.7852.05310000
save10.1763.25210.3042.286.4871,50000
save20.1312.9318.1422.2585.3991,50000
vuser_end_Transaction0.0020.6572.2660.7852.05310000
vuser_init_Transaction0.3161.9643.4090.6792.69110000

HTTP Responses Summary

HTTP ResponsesTotalPer second
HTTP_20037,90040.148
HTTP_3021,6001.695

Filters: (do not Include Think Time)










下面是个别Vuser的log,这两个用户有处理同一张图片,但是数据库里只记录了test71的数据




Start auto log messages stack.
vuser_init.c(53): Registering web_url("WebResource.axd") was successful  
vuser_init.c(61): Registering web_url("logo_cn.png") was successful  
vuser_init.c(69): web_concurrent_end was successful, 130304 body bytes, 800 header bytes  
vuser_init.c(71): Notify: Transaction "login" started.
vuser_init.c(73): lr_think_time: 3.00 seconds.
vuser_init.c(75): Redirecting "http://192.169.10.12/impweb/index.aspx" (redirection depth=0)  
vuser_init.c(75): To location "http://192.169.10.12/impweb/Main/Main.aspx"  
vuser_init.c(75): web_submit_data("index.aspx") was successful, 1182 body bytes, 478 header bytes  
vuser_init.c(92): Error: 登录用户名---> test1
End auto log messages stack.


Start auto log messages stack - Iteration 1.
Action.c(198): Registering web_reg_save_param was successful  
Action.c(203): Registering web_reg_save_param was successful  
Action.c(209): Registering web_reg_save_param was successful  
Action.c(215): Registering web_reg_save_param was successful  
Action.c(223): Redirecting "http://192.169.10.12/impweb/DataInput/DataIInputSelect.aspx" (redirection depth=0)  
Action.c(223): To location "http://192.169.10.12/impweb/DataInput/DataInput_Model_1_Horizontal.aspx"  
Action.c(223): web_submit_data("DataIInputSelect.aspx_5") was successful, 76050 body bytes, 509 header bytes  
Action.c(244): Error: 组别---> 001
Action.c(245): Error: 第一张图片名 : 1001_a_001_001.jpg
Action.c(246): Error: 用户名: test1
Action.c(247): Error: 第一次录入剩余图片数  : 1045
End auto log messages stack.


Start auto log messages stack - Iteration 1.
Action.c(315): web_convert_param was successful  
Action.c(321): Resource "http://192.169.10.12/impweb/BusinessCardPicture/test0414/test0414/test0429/1001_a_001_001.jpg" is in the cache already and will not be downloaded again  
Action.c(335): Registering web_reg_save_param was successful  
Action.c(341): Registering web_reg_save_param was successful  
Action.c(348): Registering web_reg_save_param was successful  
Action.c(354): web_submit_data("DataInput_Model_1_Horizontal.aspx_2") was successful, 12792 body bytes, 223 header bytes  
Action.c(383): Error: 第二张图片名 : 1356_b_001_001.jpg
Action.c(385): Error: 第二次录入图片剩余数  : 1041
End auto log messages stack.


-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------












作者: bustersword    时间: 2011-5-3 13:43
Start auto log messages stack.
vuser_init.c(53): Registering web_url("WebResource.axd") was successful  
vuser_init.c(61): Registering web_url("logo_cn.png") was successful  
vuser_init.c(69): web_concurrent_end was successful, 130304 body bytes, 800 header bytes  
vuser_init.c(71): Notify: Transaction "login" started.
vuser_init.c(73): lr_think_time: 3.00 seconds.
vuser_init.c(75): Redirecting "http://192.169.10.12/impweb/index.aspx" (redirection depth=0)  
vuser_init.c(75): To location "http://192.169.10.12/impweb/Main/Main.aspx"  
vuser_init.c(75): web_submit_data("index.aspx") was successful, 1182 body bytes, 478 header bytes  
vuser_init.c(92): Error: 登录用户名---> test71
End auto log messages stack.


Start auto log messages stack - Iteration 1.
Action.c(198): Registering web_reg_save_param was successful  
Action.c(203): Registering web_reg_save_param was successful  
Action.c(209): Registering web_reg_save_param was successful  
Action.c(215): Registering web_reg_save_param was successful  
Action.c(223): Redirecting "http://192.169.10.12/impweb/DataInput/DataIInputSelect.aspx" (redirection depth=0)  
Action.c(223): To location "http://192.169.10.12/impweb/DataInput/DataInput_Model_1_Horizontal.aspx"  
Action.c(223): web_submit_data("DataIInputSelect.aspx_5") was successful, 76055 body bytes, 509 header bytes  
Action.c(244): Error: 组别---> 001
Action.c(245): Error: 第一张图片名 : 1001_a_001_001.jpg
Action.c(246): Error: 用户名: test71
Action.c(247): Error: 第一次录入剩余图片数  : 1046
End auto log messages stack.


Start auto log messages stack - Iteration 1.
Action.c(315): web_convert_param was successful  
Action.c(321): Resource "http://192.169.10.12/impweb/BusinessCardPicture/test0414/test0414/test0429/1001_a_001_001.jpg" is in the cache already and will not be downloaded again  
Action.c(335): Registering web_reg_save_param was successful  
Action.c(341): Registering web_reg_save_param was successful  
Action.c(348): Registering web_reg_save_param was successful  
Action.c(354): web_submit_data("DataInput_Model_1_Horizontal.aspx_2") was successful, 12792 body bytes, 223 header bytes  
Action.c(383): Error: 第二张图片名 : 1002_b_001_001.jpg
Action.c(385): Error: 第二次录入图片剩余数  : 1043
End auto log messages stack.




作者: 阿星爱美酒    时间: 2011-5-3 14:56
强悍。。。学习中!
作者: bustersword    时间: 2011-5-3 15:33
求助.......................
为什么用户一多,就丢失数据了............

作者: jsqyue    时间: 2011-5-3 16:29
看看中间件的配置,另外,loadrunner上没有报错吗?
你把测试场景重新设置一下看看,比如1s登陆2个vuser
我估计时中间件压力太大了,vuser少的时候还可以登陆,多的时候就shut down了,另外,把插入图片的脚本前设置下思考时间
作者: hongliangqing    时间: 2011-5-3 16:47
明白了吗?帽子
作者: soarsky629    时间: 2011-5-3 17:32
我觉得thinktime是一种可能,还有可能是不是迭代次数太多了……??
作者: dionysus    时间: 2011-5-3 23:23
监控下应用服务器和数据库吧
作者: jj_ljw    时间: 2011-5-4 09:11
如果500人全部执行成功,可能是你数据库接收速度跟不上吧
作者: bustersword    时间: 2011-5-4 14:58
我今天又重新写了下脚本下面是执行的结果

50Vuser *15条数据
一次性加载50VUuser

Analysis SummaryPeriod: 04-05-2011 11:59:14 - 04-05-2011 12:01:54

Scenario Name:Scenario1
Results in Session:d:\res\res\res.lrr
Duration:2 minutes and 40 seconds.

Statistics Summary

Maximum Running Vusers:50
Total Throughput (bytes):86,699,121
Average Throughput (bytes/second):538,504
Total Hits:5,750
Average Hits per Second:35.714  View HTTP Responses Summary

Transaction Summary

Transactions:Total Passed: 1,800Total Failed: 0Total Stopped: 0         Average Response Time

Transaction NameMinimumAverageMaximumStd. Deviation90 PercentPassFailStop
Action_Transaction3.7898.6813.4992.33411.4865000
login0.1131.3412.1310.6482.0625000
loginout0.0020.0030.0380.0050.0025000
outInput0.1080.1870.2570.0350.2375000
save10.1672.4816.211.4064.1685000
save20.1540.5524.9650.4320.95370000
SavePicSingle_Transaction0.1540.5534.9660.4320.95370000
startInput0.9025.1236.3991.0926.2655000
vuser_end_Transaction0.110.190.2620.0360.245000
vuser_init_Transaction0.1281.3672.2020.6512.0995000
file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/15%E4%B9%9850%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/15%E4%B9%9850%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/dot_trans.gif

HTTP Responses Summary

HTTP ResponsesTotalPer second
HTTP_2005,65035.093
HTTP_3021000.621
file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/15%E4%B9%9850%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/15%E4%B9%9850%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/dot_trans.gif

file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/15%E4%B9%9850%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/15%E4%B9%9850%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/dot_trans.gif
Filters: (do not Include Think Time)


作者: bustersword    时间: 2011-5-4 15:00
80Vuser*15条数据一次性加载80Vuser

Analysis SummaryPeriod: 04-05-2011 13:14:16 - 04-05-2011 13:18:32

Scenario Name:Scenario1
Results in Session:d:\res\res\res.lrr
Duration:4 minutes and 16 seconds.

Statistics Summary

Maximum Running Vusers:80
Total Throughput (bytes):138,615,393
Average Throughput (bytes/second):539,360
Total Hits:9,198
Average Hits per Second:35.79  View HTTP Responses Summary

Transaction Summary

Transactions:Total Passed: 2,876Total Failed: 4Total Stopped: 0         Average Response Time

Transaction NameMinimumAverageMaximumStd. Deviation90 PercentPassFailStop
Action_Transaction7.77116.74436.3745.22722.5398000
login0.0691.1882.5390.6552.078000
loginout0.0010.0020.0060.0010.0028000
outInput0.0040.2130.8460.0890.2678000
save11.7324.73421.7453.1416.6228000
save20.151.78425.1362.323.1281,11820
SavePicSingle_Transaction0.151.78425.1362.323.1281,11820
startInput0.7968.56411.7962.48110.2538000
vuser_end_Transaction0.0060.2150.8480.0890.278000
vuser_init_Transaction0.2851.3682.5650.5732.1118000
file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/15%E4%B9%9880%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/15%E4%B9%9880%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/dot_trans.gif

HTTP Responses Summary

HTTP ResponsesTotalPer second
HTTP_2009,03835.167
HTTP_3021600.623
file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/15%E4%B9%9880%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/15%E4%B9%9880%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/dot_trans.gif

file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/15%E4%B9%9880%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/15%E4%B9%9880%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/dot_trans.gif
Filters: (do not Include Think Time)


作者: bustersword    时间: 2011-5-4 15:04
本帖最后由 bustersword 于 2011-5-4 15:05 编辑

100Vuser*15条数据一次性加载100VUser

顺带说下,这三次测试,我都在登录完后设置了集合点


Analysis SummaryPeriod: 04-05-2011 12:49:28 - 04-05-2011 12:54:32

Scenario Name:Scenario1
Results in Session:d:\res\res\res.lrr
Duration:5 minutes and 4 seconds.

Statistics Summary

Maximum Running Vusers:100
Total Throughput (bytes):173,669,703
Average Throughput (bytes/second):569,409
Total Hits:11,493
Average Hits per Second:37.682  View HTTP Responses Summary

Transaction Summary

Transactions:Total Passed: 3,586Total Failed: 14Total Stopped: 0         Average Response Time

Transaction NameMinimumAverageMaximumStd. Deviation90 PercentPassFailStop
Action_Transaction10.38620.05138.0515.527.60110000
login0.1851.1732.4060.5881.98210000
loginout0.0010.0040.0410.0060.01310000
outInput0.0050.3424.5640.6260.34110000
save12.1285.89120.4492.959.43110000
save20.1547.22937.6653.2868.6271,39370
SavePicSingle_Transaction0.1547.22937.6653.2868.6271,39370
startInput0.89210.31416.3473.45512.63610000
vuser_end_Transaction0.0060.3464.5660.6250.34310000
vuser_init_Transaction0.3441.3512.4350.5552.01210000
file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/15%E4%B9%98100%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/15%E4%B9%98100%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/dot_trans.gif

HTTP Responses Summary

HTTP ResponsesTotalPer second
HTTP_20011,29337.026
HTTP_3022000.656
file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/15%E4%B9%98100%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/15%E4%B9%98100%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/dot_trans.gif

file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/15%E4%B9%98100%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/15%E4%B9%98100%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/dot_trans.gif
Filters: (do not Include Think Time)

file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/15%E4%B9%98100%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/15%E4%B9%98100%E7%94%A8%E6%88%B7-%E7%BB%93%E6%9E%9C%E5%88%86%E6%9E%90-2011-5-4/dot_trans.gif



作者: bustersword    时间: 2011-5-4 15:10
三次的TPS是
11.18

11.191

11.757

现在我不会出现大量丢失数据的情况,但是少量的fail,算不算测试中的正常情况呢?
再者,我现在系统的TPS是不是也到瓶颈了?

我又测试了缓慢加载用户的场景,TPS都差不多,200用户每10S增加5Vuser的场景,fail的次数就多点40左右,TPS  11.497 ,最大 运行用户120
实际中,200用户同时去处理,会怎么样呢?
作者: giftoflife    时间: 2011-5-4 15:35
场景运行过程中有错误么?是哪些呢?
作者: bustersword    时间: 2011-5-4 15:54
运行中的错误都是关联没有找到匹配的错误 ,我想应该是页面来不及响应,所有也就来不及匹配了...
作者: giftoflife    时间: 2011-5-4 16:05
数据库和服务器的性能检测呢?
作者: bustersword    时间: 2011-5-4 16:15
数据库没检测.....服务器是IIS的,运行的时候cpu使用率蛮高的。。。。。具体数据没保留................
作者: bustersword    时间: 2011-5-4 16:39
三次的TPS是
11.18

11.191

11.757

现在我不会出现大量丢失数据的情况,但是少量的fail,算不算测 ...
bustersword 发表于 2011-5-4 15:10


这些问题,根据现有数据,或者你的经验,谁来回答下....3Q
作者: qingyi0711    时间: 2011-5-4 22:13
时间是否设置的够呢??500个并发,每个并发迭代15次,每次迭代的时间算好后,再计算500并发的时间,估计得跑一段时间吧.......
作者: sherryshi    时间: 2011-5-5 10:48
借楼主热帖问下,什么情况下设置思考时间,什么情况下不设置思考时间?另外这个思考时间指的是什么呢?
作者: sherryshi    时间: 2011-5-5 10:50
再问个问题,如何排除应用服务器和程序,只对数据进行压力测试。这样的测试如何进行呢。我现在在做一个系统的压力测试,不知道怎么分析到底是程序问题,中间件问题,还是数据库问题?
作者: bustersword    时间: 2011-5-5 17:29
我今天又测试了100用户*100数据,也就是一共插入10000条数据,丢失4条数据,但是保存数据的响应时间竟然达到了10S左右,我了个去......50用户插入750条数据,倒是3S内,现在至于要根据这些结果,让我去改程序,或者服务器,数据库,我还真是有点迷茫了..........天啊!
怎么搞负载均衡,什么分布式缓存,神马神马啊!
疯了
作者: sherryshi    时间: 2011-5-5 17:47
我今天又测试了100用户*100数据,也就是一共插入10000条数据,丢失4条数据,但是保存数据的响应时间竟然达到 ...
bustersword 发表于 2011-5-5 17:29



    你已经很厉害了,呵呵

我更加迷茫,现在有一个功能点在多并发的情况下速度很慢,让我分析原因,是程序还是服务器还是数据库。姐姐我不知道怎么弄啊,分析不来呀,压力做了又做????
作者: bustersword    时间: 2011-5-5 18:06
我真的很不厉害............是菜鸟,我现在是完全找不到东南西北
作者: bustersword    时间: 2011-5-5 18:11
Action()
{
int rc;  
int db_connection; // 数据库连接
int query_result; // 查询结果集 MYSQL_RES
char** result_row; // 查询的数据衕
  
char *server = "localhost";
char *user = "root";
char *password = "123456";
char *database = "test";
int port = 3306;
int unix_socket = NULL;  
int flags = 0;  
  
// 找到libmysql.dll的所在位置.
rc = lr_load_dll("C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\libmysql.dll");
if (rc != 0) {
    lr_error_message("Could not load libmysql.dll");
    lr_abort();
}
  
// 创建MySQL对象
db_connection = mysql_init(NULL);
if (db_connection == NULL) {
    lr_error_message("Insufficient memory");
    lr_abort();
}
  
// 连接到MySQL数据库
rc = mysql_real_connect(db_connection, server, user, password, database, port, unix_socket, flags);
if (rc == NULL) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
  
// 向数据库插入数据
// 此处的 {ORDER_ID} 是一个参数,简单测试时可以用一个常数代替
lr_save_string (lr_eval_string("INSERT INTO test_data (order_id) VALUES ({ORDER_ID})"),"paramInsertQuery");  
rc = mysql_query(db_connection, lr_eval_string("{paramInsertQuery}"));
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
  
// 从数据库读取一个数据并显示
rc = mysql_query(db_connection, "SELECT order_id FROM test_data WHERE status IS FALSE LIMIT 1");
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
query_result = mysql_use_result(db_connection);
if (query_result == NULL) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}
// 如果结果集包含多行数据,需要多次调用 mysql_fetch_row 直到返回NULL
result_row = (char **)mysql_fetch_row(query_result);  
if (result_row == NULL) {
    lr_error_message("Did not expect the result set to be empty");
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}
// 保存参数,用于删除这行数据
lr_save_string(result_row[0], "paramOrderID");
lr_output_message("Order ID is: %s", lr_eval_string("{paramOrderID}"));
mysql_free_result(query_result);
  
// 在事务里更新一行数据,需要用InnoDB引擎
rc = mysql_query(db_connection, "BEGIN"); //启动事务
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
// 使用 "FOR UPDATE" 锁住要更新的数据行
rc = mysql_query(db_connection, "SELECT order_id FROM test_data WHERE status IS FALSE LIMIT 1 FOR UPDATE");  
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
query_result = mysql_use_result(db_connection);
if (query_result == NULL) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}
result_row = (char **)mysql_fetch_row(query_result);  
if (result_row == NULL) {
    lr_error_message("没有查询到结果");
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}
lr_save_string(result_row[0], "paramOrderID");
lr_output_message("Order ID is: %s", lr_eval_string("{paramOrderID}"));
mysql_free_result(query_result);
lr_save_string(lr_eval_string("UPDATE test_data SET status=TRUE, date_used=NOW() WHERE order_id='{paramOrderID}'"),"paramUpdateQuery");
rc = mysql_query(db_connection, lr_eval_string("{paramUpdateQuery}"));
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
rc = mysql_query(db_connection, "COMMIT"); // 提交事务
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
  
// 再次查找数据,应该为空了,因为前面的事务更新了标志
rc = mysql_query(db_connection, "SELECT order_id FROM test_data WHERE status IS FALSE LIMIT 1");
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
query_result = mysql_use_result(db_connection);
if (query_result == NULL) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}
result_row = (char **)mysql_fetch_row(query_result);
if (result_row == NULL) {
    lr_output_message("Result set is empty as expected");
    mysql_free_result(query_result);
} else {
    lr_error_message("Did not expect the result set to contain any rows");
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}
  
// 删除数据
lr_save_string(lr_eval_string("DELETE FROM test_data WHERE order_id = '{paramOrderID}'"),"paramDeleteQuery");
rc = mysql_query(db_connection, lr_eval_string("{paramDeleteQuery}"));
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
  
// 释放MySQL资源
mysql_close(db_connection);
    return 0;
}
/*需要的表结构如下
CREATE TABLE `test_data` (
`order_id` BIGINT UNSIGNED NOT NULL COMMENT 'Order numbers. Must be unique.',
`status` BOOL NOT NULL DEFAULT '0' COMMENT 'Whether data has been used or not. A value of 0 means FALSE.',
`date_used` DATETIME NULL COMMENT 'Date/time that the data was used.',
UNIQUE (
    `order_id`
)
) ENGINE = innodb COMMENT = 'LoadRunner test data';
*/
Action()
{
int rc;
int db_connection; // 数据库连接
int query_result; // 查询结果集 MYSQL_RES
char** result_row; // 查询的数据衕

char *server = "localhost";
char *user = "root";
char *password = "123456";
char *database = "test";
int port = 3306;
int unix_socket = NULL;
int flags = 0;
作者: bustersword    时间: 2011-5-5 18:11
// 找到libmysql.dll的所在位置.
rc = lr_load_dll("C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\libmysql.dll");
if (rc != 0) {
    lr_error_message("Could not load libmysql.dll");
    lr_abort();
}

// 创建MySQL对象
db_connection = mysql_init(NULL);
if (db_connection == NULL) {
    lr_error_message("Insufficient memory");
    lr_abort();
}

// 连接到MySQL数据库
rc = mysql_real_connect(db_connection, server, user, password, database, port, unix_socket, flags);
if (rc == NULL) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}

// 向数据库插入数据
// 此处的 {ORDER_ID} 是一个参数,简单测试时可以用一个常数代替
lr_save_string (lr_eval_string("INSERT INTO test_data (order_id) VALUES ({ORDER_ID})"),"paramInsertQuery");
rc = mysql_query(db_connection, lr_eval_string("{paramInsertQuery}"));
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}

// 从数据库读取一个数据并显示
rc = mysql_query(db_connection, "SELECT order_id FROM test_data WHERE status IS FALSE LIMIT 1");
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
query_result = mysql_use_result(db_connection);
if (query_result == NULL) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}
// 如果结果集包含多行数据,需要多次调用 mysql_fetch_row 直到返回NULL
result_row = (char **)mysql_fetch_row(query_result);
if (result_row == NULL) {
    lr_error_message("Did not expect the result set to be empty");
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}
// 保存参数,用于删除这行数据
lr_save_string(result_row[0], "paramOrderID");
lr_output_message("Order ID is: %s", lr_eval_string("{paramOrderID}"));
mysql_free_result(query_result);

// 在事务里更新一行数据,需要用InnoDB引擎
rc = mysql_query(db_connection, "BEGIN"); //启动事务
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
// 使用 "FOR UPDATE" 锁住要更新的数据行
rc = mysql_query(db_connection, "SELECT order_id FROM test_data WHERE status IS FALSE LIMIT 1 FOR UPDATE");
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
query_result = mysql_use_result(db_connection);
if (query_result == NULL) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}
result_row = (char **)mysql_fetch_row(query_result);
if (result_row == NULL) {
    lr_error_message("没有查询到结果");
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}
lr_save_string(result_row[0], "paramOrderID");
lr_output_message("Order ID is: %s", lr_eval_string("{paramOrderID}"));
mysql_free_result(query_result);
lr_save_string(lr_eval_string("UPDATE test_data SET status=TRUE, date_used=NOW() WHERE order_id='{paramOrderID}'"),"paramUpdateQuery");
rc = mysql_query(db_connection, lr_eval_string("{paramUpdateQuery}"));
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
rc = mysql_query(db_connection, "COMMIT"); // 提交事务
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}

// 再次查找数据,应该为空了,因为前面的事务更新了标志
rc = mysql_query(db_connection, "SELECT order_id FROM test_data WHERE status IS FALSE LIMIT 1");
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}
query_result = mysql_use_result(db_connection);
if (query_result == NULL) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}
result_row = (char **)mysql_fetch_row(query_result);
if (result_row == NULL) {
    lr_output_message("Result set is empty as expected");
    mysql_free_result(query_result);
} else {
    lr_error_message("Did not expect the result set to contain any rows");
    mysql_free_result(query_result);
    mysql_close(db_connection);
    lr_abort();
}

// 删除数据
lr_save_string(lr_eval_string("DELETE FROM test_data WHERE order_id = '{paramOrderID}'"),"paramDeleteQuery");
rc = mysql_query(db_connection, lr_eval_string("{paramDeleteQuery}"));
if (rc != 0) {
    lr_error_message("%s", mysql_error(db_connection));
    mysql_close(db_connection);
    lr_abort();
}

// 释放MySQL资源
mysql_close(db_connection);
return 0;
}


我想知道上面这段连接mysql测试的前提环境配置----------------------------------求解
作者: bustersword    时间: 2011-5-6 13:46
顶下,等待高手
作者: sherryshi    时间: 2011-5-6 15:45
恩,也顶一记,等待高人
作者: wuwoyiran    时间: 2011-5-6 17:16
学习了
作者: bustersword    时间: 2011-5-9 10:24
.....我想知道怎么解决服务器响应慢的问题。优化SQL语句,优化页面,and???????
作者: sherryshi    时间: 2011-5-9 13:23
.....我想知道怎么解决服务器响应慢的问题。优化SQL语句,优化页面,and???????
bustersword 发表于 2011-5-9 10:24



    应该找出原因吧,我现在就急于求教如何分析是哪部分原因造成的
作者: sherryshi    时间: 2011-5-9 13:54
性能自动化的朋友请加群:146971792
zouhui1003it 发表于 2011-5-8 18:43



    群怎么加不了呢
作者: lmzkuaipao    时间: 2011-5-9 15:13
回复 29# sherryshi


    思考时间,打个比方,你登陆QQ时,需要输入用户名密码,这个输入时间就是thinktime。如果要测试登陆的响应时间,应该在点确认登陆前加transaction,登陆完毕后结束transaction。录制完毕后,把脚本里,transaction里面自动录制出来的thinktime删掉,手动在transaction之前加thinktime。什么时候设什么时候不设thinktime,要看你具体的测试要求了
作者: wyh1987com    时间: 2011-5-9 17:22
回复 40# bustersword


    你用了什么监控数据库啊?
作者: sherryshi    时间: 2011-5-10 11:02
回复  sherryshi


    思考时间,打个比方,你登陆QQ时,需要输入用户名密码,这个输入时间就是thinkt ...
lmzkuaipao 发表于 2011-5-9 15:13



    谢谢详细解答
作者: sherryshi    时间: 2011-5-10 11:09
本帖最后由 sherryshi 于 2011-5-10 11:15 编辑

如果我要测的是查询,插入,提交这样的业务类型,设置思考时间好呢,还是不设置好呢?
作者: sherryshi    时间: 2011-5-10 11:10
另外勾选专家模式和不勾选,有什么区别呢。我测出来的结果是不同的
作者: bustersword    时间: 2011-5-11 11:31
回复  bustersword


    你用了什么监控数据库啊?
wyh1987com 发表于 2011-5-9 17:22



    其实,我没用什么监测数据库,只是看了下数据库日志而已。。。。目前困扰在怎样提升性能




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2