长连接和短连接性能测试结果差异11页精选文档Word格式文档下载.docx
《长连接和短连接性能测试结果差异11页精选文档Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《长连接和短连接性能测试结果差异11页精选文档Word格式文档下载.docx(11页珍藏版)》请在冰点文库上搜索。
何谓长连接:
就是一次操作完后不断开连接,连接在一段时间保持着,则是多用于操作频繁情况,每个TCP连接都需要三步握手这需要时间如果每个操作都是先连接再操作的话那么处理速度会降低很多所以每个操作完后都不断开下次处理时直接发送数据包就可以了,不用重新建立TCP新连接。
。
2.
在性能测试过程中,需要注意业务需求,应该是用长连接还是短连接?
之间的性能差异大概是多少?
如果有差异是消耗在哪里?
2.1测试场景简介:
下面以测试XXXX性能测试结果为例,做个简单的对比.由于XXXX后端协议用的是TCP/IP协议,后端AGENT发送很多带不同参数类型到MONITOR。
现要测试一个MONITOR处理极限是多少?
理想状态希望一个monitor最高能支持1W条AGENTE的信息,并且这个1W条信息时希望只建立一个SOCKET连接里面发送的事务数。
2.2测试环境描述:
机器名
CPU
内存
OS
应用软件
说明
10.20.136.19
(DB)
8
16G
Linux
tomcat
10.20.136.23(APP)
10.20.136.73
8G
windows
loadrunner
2.2测试脚本简述:
在LR中开发JAVA脚本,直接发送字符串并成功接受返回的字符串。
2.4测试结果对比:
并发线程
连接类型
TPS
响应时间
20
长连接
6766
0.015S
APP:
780%
DB:
23%
36%
DB:
85%
短连接
7292
0.011S
740%
14%
57%
83%
2.5测试结果分析:
线程并发数一样,但是长连接的TPS低于短连接的TPS,相差大概在6%左右,长连接的应用服务器的APP的资源利用稍微大点,但是短连接的内存消耗明显比长连接的高,高出了大概58%左右。
之所以消耗怎么高是因为,短连接不停的忙着建立连接,不停的建立握手,这样频繁的操作,造成内存资源上的很大消耗。
3.总结
虽然短连接的测试结果TPS以及相应时间是好于长连接的测试结果,但是不符合线上环境。
最重要的一点是,测试人员,做测试脚本以及设计测试场景的时候,一定谨记不要把测试数据发送到服务器端,压力上去后,就不去分析了写的测试脚本以及测试场景是否是满足线上需要的,这样得出的测试结果会给开发人员造成一定的误解。
测试的场景单一,没有去分析线程并发在不同的情况下的,性能结果差异是多少,如果谁有兴趣可以在分不同的线程并发,多尝试几次,看看性能数据的差异是多少?
4.测试代码附上,
4.1长连接代码:
/*
*LoadRunnerJavascript.(Build:
3020)
*
*ScriptDescription:
*
*/
importlrapi.lr;
importjava.io.DataInputStream;
importjava.io.DataOutputStream;
importjava.io.IOException;
importjava.Socket;
publicclassActions
{
Socketsocket=null;
DataOutputStreamout;
DataInputStreamin;
publicintinit()throwsThrowable{
socket=newSocket("
10.20.136.23"
13888);
out=newDataOutputStream(socket.getOutputStream());
in=newDataInputStream(socket.getInputStream());
sendConnect(out,"
10.16.200.119"
"
performance_test"
);
Stringtext=readMessage(in);
System.out.println(text);
return0;
}//endofinit
publicintaction()throwsThrowable{
send_memory(out);
send_jvm(out);
send_gc(out);
send_threading(out);
}//endofaction
publicintend()throwsThrowable{
if(socket!
=null){
socket.close();
}
}//endofend
publicStringreadMessage(DataInputStreamin)throwsIOException{
shorttype=in.readShort();
if(type!
=1){
thrownewIOException("
notsupporttype"
+type);
intlength=in.readInt();
byte[]bytes=newbyte[length];
in.readFully(bytes);
returnnewString(bytes,"
UTF-8"
}
publicvoidsendConnect(DataOutputStreamout,Stringip,Stringhostname)throwsIOException{
Stringmessage="
[{/"
T/"
:
/"
Connect/"
/"
S/"
1},{/"
MAC_ADDR/"
[/"
00-26-c6-8f-d8-2c/"
00-50-56-c0-00-08/"
],/"
IP/"
"
+ip
+"
192.168.64.1/"
VERSON/"
2.5/"
SERVICE_TAG/"
wenshao-pc-service-tag/"
HOST_NAME/"
+hostname+"
CLIENT_SESSION/"
[]}]"
;
sendMessage(out,message);
publicvoidsend_memory(DataOutputStreamout)throwsException{
longdate=System.currentTimeMillis();
MonitorItemData/"
39},{/"
D/"
{/"
UsedPhysicalMemorySize/"
1908174848,/"
MemoryNonHeapCommitted/"
41943040,/"
MemoryHeapCommitted/"
122224640,/"
MemoryHeapUsed/"
101766328,/"
TotalPhysicalMemorySize/"
2036363264,/"
UsedSwapSpaceSize/"
2582024192,/"
TotalSwapSpaceSize/"
4072726528,/"
MemoryNonHeapUsed/"
41367072},/"
APP_NUM/"
demo/"
INST_NUM/"
null},/"
TS/"
+date+"
MID/"
548691}]"
publicvoidsend_jvm(DataOutputStreamout)throwsException{
42},{/"
AvailableProcessors/"
2,/"
JavaHome/"
C:
//ProgramFiles//Java//jdk1.6.0_19//jre/"
JavaVersion/"
1.6.0_19/"
PID/"
3112/"
OSVersion/"
6.1/"
UnloadedClassCount/"
0,/"
TotalCompilationTime/"
6089,/"
OSName/"
Windows7/"
JavaSpecificationVersion/"
1.6/"
Arch/"
amd64/"
LoadedClassCount/"
5006,/"
JVM/"
JavaHotSpot(TM)64-BitServerVM(16.2-b04,mixedmode)/"
StartTime/"
1288273090499,/"
InputArguments/"
-agentlib:
jdwp=transport=dt_socket,suspend=y,address=localhost:
55785/n-Dcatalina.base=D:
//java//workspace-dragoon-25//.metadata//.plugins//org.eclipse.wst.server.core//tmp0/n-Dcatalina.home=D:
//java//apache-tomcat-6.0.26/n-Dwtp.deploy=D:
//java//workspace-dragoon-25//.metadata//.plugins//org.eclipse.wst.server.core//tmp0//wtpwebapps/n-Djava.endorsed.dirs=D:
//java//apache-tomcat-6.0.26//endorsed/n-Dfile.encoding=UTF-8/"
TotalLoadedClassCount/"
JavaLibraryPath/"
//ProgramFiles//Java//jdk1.6.0_19//bin;
.;
//Windows//Sun//Java//bin;
//Windows//system32;
//Windows;
//ProgramFiles//Java//jdk1.6.0_19//jre//bin;
//product//11.1.0//client_1;
//Windows//System32//Wbem;
//Windows//System32//WindowsPowerShell//v1.0//;
//ProgramFiles(x86)//TortoiseSVN//bin;
D:
//java//apache-maven-2.2.1//bin;
//ProgramFiles(x86)//Subversion//bin;
//ProgramFiles(x86)//SSHCommunicationsSecurity//SSHSecureShell;
//Python25;
//java//diffutils-2.8.7-1-bin//bin/"
},/"
554891}]"
publicvoidsend_gc(DataOutputStreamout)throwsException{
41},{/"
YoungGCCollectionTime/"
107,/"
FullGCCollectionTime/"
141,/"
FullGCCollectionCount/"
11,/"
PermGenUsed/"
39267864,/"
SurvivorSpaceUsed/"
7201980,/"
EdenSpaceUsed/"
85454816,/"
YoungGCCollectionCount/"
10,/"
OldGenUsed/"
11791088},/"
552091}]"
publicvoidsend_threading(DataOutputStreamout)throwsException{
43},{/"
RunnableThreadCount/"
15,/"
ProcessCpuTimeRate/"
0.901,/"
NewThreadCount/"
TotalStartedThreadCount/"
49,/"
BlockedThreadCount/"
DeadLockedThreadCount/"
FullGCCollectionTimeRate/"
DaemonThreadCount/"
17,/"
WaitingThreadCount/"
TeminatedThreadCount/"
ThreadCount/"
48,/"
TimedWaitingThreadCount/"
25},/"
550191}]"
privatevoidsendMessage(DataOutputStreamout,Stringtext)throwsIOException{
byte[]bytes=text.getBytes("
out.writeShort
(1);
out.writeInt(bytes.length);
out.write(bytes);
4.2短连接代码
return0;
test_connect();
publicvoidtest_connect()throwsException{
//10.249.168.152:
18001
try{
socket=newSocket("
DataOutputStreamout=newDataOutputStream(socket.getOutputStream());
DataInputStreamin=newDataInputStream(socket.getInputStream());
sendConnect(out,"
Stringtext=readMessage(in);
System.out.println(text);
}finally{
if(socket!
socket.close();
shorttype=in.readShort();
if(type!
thrownewIOException("
intlength=in.readInt();
byte[]bytes=newbyte[length];
in.readFully(bytes);
returnnewString(bytes,"
wenshao-pc-s