Loadrunner中多线程与多进程的区别

上一篇 / 下一篇  2011-12-14 14:51:46 / 个人分类:LoadRunner

51Testing软件测试网[ W$N:a&e Kz5S

用户可以在Controller的run-time setting中选择Vuser的运行方式:多进程/多线程。

|mZ})^,i#I0

X8vI#pV&B(Gdv#G0多进程和多线程方式的区别是:51Testing软件测试网]:b5@_7f!@u

51Testing软件测试网7e_U"m9LO

Controller将使用驱动程序mdrv运行Vuser。如果按进程方式运行每个Vuser,则对于每个Vuser实例,都将启动一个mdrv进程。多个mdrv进程会占用大量内存及其他系统资源,这就限制了可以在任一负载生成器上运行的Vuser的数量。如果选择按线程方式运行,在默认情况下,Controller为每50个Vuser仅启动一个mdrv.exe进程,而每个Vuser都按线程运行,这些线程Vuser将共享父进程的内存段。这就节省了大量内存控件,从而可以在一个负载生成器上运行更多的Vuser。

d&o8@$mN0

um(kB,T0但是任何选择都是有两面性的。选择线程方式运行Vuser会带来一些安全问题。因为线程的资源是从进程资源中分配出来的,因此同一个进程中的多个线程会有共享的内存空间,这样可能会引起多个线程的同步问题,调度不好,就会出问题,不如A线程要用的资源就必须等待B线程释放,而B也在等待其他资源释放才能继续。这就会出现这样的问题:同一个测试场景,用线程并发就会超时失败或报错,而用进程并发就没错。

|3ZW(h O0

P E9GKRn!x0一个组里10个用户和10个组每个组一个用户有什么区别?51Testing软件测试网C2t d,qi+A
  我们先看一下LR的官方帮助:
8ZQD Z Fs0 51Testing软件测试网-Tv-kh;B#y N g
Multithreading51Testing软件测试网5AI"P\"^(Hr A
Vusers support multithread environments. The primary advantage of a multithread environment is the ability to run more Vusers per load generator. Only threadsafe protocols should be run as threads. (not applicable to Mercury Business Availability Center)51Testing软件测试网 N2j-zp3B
Note: The following protocols are not threadsafe: Sybase-Ctlib, Sybase-Dblib, Informix, Tuxedo, and PeopleSoft-Tuxedo.
W2Nb-wwx#C0o      To enable multithreading, click Run Vuser as a thread.51Testing软件测试网"{7jWp4X
o      To disable multithreading and run each Vuser as a separate process, click Run Vuser as a process.51Testing软件测试网qPQ\.})r
The Controller and Tuning Console use a driver program (such as mdrv.exe or r3vuser.exe) to run your Vusers. If you run each Vuser as a process, then the same driver program is launched (and loaded) into the memory again and again for every instance of the Vuser. Loading the same driver program into memory uses up large amounts of RAM (random access memory) and other system resources. This limits the numbers of Vusers that can be run on any load generator.51Testing软件测试网 H*K*Y0p h
Alternatively, if you run each Vuser as a thread, the Controller or Tuning Console launches only one instance of the driver program (such as mdrv.exe), for every 50 Vusers (by default). This driver process/program launches several Vusers, each Vuser running as a thread. These threaded Vusers share segments of the memory of the parent driver process. This eliminates the need for multiple re-loading of the driver program/process saves much memory space, thereby enabling more Vusers to be run on a single load generator.51Testing软件测试网o!YU'X&L5S
 
V\{!H G0 51Testing软件测试网 T\3~0p0f:RgtB
  从上面的描述可以看到,
x/Mv7C`E3q1z9i0  如果是线程安全的协议,在一个组(进程)里并发多个vusers,可以不用开那么进程。这可以减少系统的开销。
4h3\6z%UtG0t+^%G0  如果不是线程安全的协议,我们需要开多个进程来处理Vusers。这样势必增加系统的开销。51Testing软件测试网%R2`glB?$E)pWw
  其实对现在的硬件来说,基本上客户端成为瓶颈的机会不是很大。(除非这公司太穷了)51Testing软件测试网(u%T5y[DQ*MDf
 
rNmb0|k0  这里我做了个实验,画了一张表,来形象的说明一下组/vusers/线程/进程的关系。51Testing软件测试网|:hcb;_r L0@h
注:这里,我假定的是10vsuers:
51Testing软件测试网nHUj Y

%Z _.[}6p0G8[0

s8t4Q T!T3X0

;A:gA/]@O9zj0   我这里脚本都是一样的。51Testing软件测试网zmi0KeU+W ^:g
  大家如果自己做实验,内存可能会不一样。51Testing软件测试网9u0Gkq4@O4X
  在表里,我们可以很清楚的看到,进程多的时候,占用内存肯定是多的。51Testing软件测试网"r%TD-V3F%PV
  如果在同一组里开多个线程,占用内存就少得多。51Testing软件测试网aL E w!HRrU
  我们还要注意一个细节就是在用线程来运行vusers的时候,每个进程中会多出几个线程来。51Testing软件测试网t7A4m#W;k6q.yY
  这多出来的很个进程在做什么,我没有查它的API,我想可能是维护进程之间的运行。51Testing软件测试网]O+Y+ia5~
 51Testing软件测试网"D#ML"Nl c p`
  很显然的,还有个问题,就是哪个
压力更大。51Testing软件测试网9D+TP \"S3N.S2dH:R0@
  这个问题也有些人在问,我想这个应该是很明显的吧。51Testing软件测试网 Vj H(Qt#`~ q
  其实对
服务器来说,只要是10个用户都在正常工作,而速度不会受到本地硬件的影响。
)\|kfLp:P:e0  对服务器的压力是一样的。
JF5I8o#AJ,m3Het$sD0  这么来思考:51Testing软件测试网$J,ph+I/D
  假设来说。
E{4] `/Z3do%^ f0  我们是从客户端来发
数据的,10个用户,如果一秒钟发20个数据包。51Testing软件测试网0~/X:yd]2c4ohD'{
  那对服务器来说,收到的数据包都是一样多的。所以压力也会是一样的。
i4hF6hJ7e0  那会不会存在在同一个进程里开10个线程速度更慢呢。
^so-_6@4MV2X0  这个,我以为不会的。51Testing软件测试网k`.v \7u!U1T7t
 51Testing软件测试网 CIY'o1R8W
  所以我认为压力是一样的。
51Testing软件测试网,r#rM;BY~_


TAG:

 

评分:0

我来说两句

Open Toolbar