原因:
网上给出的可能的原因大致有两个:
1. 压力负载机器的资源不足(CPU,内存)
2. 分配内存和释放内存的语句不匹配。
并给出了一些解决方案,最开始我以为是加了IP地址的原因,不断尝试增加IP,减少IP, 还是没有解决。又尝试添加工作机为load generator (压力负载机是通过VPN连接的),发现连接不上,只好放弃。 怀疑是开发人员做了代码改动,但是把服务端日志取下来看,日志和之前能正常运行场景时产生的日志并无二致。 于是又尝试修改vuser的运行方式,在进程和线程间切换。问题依旧存在。只能说前次正常运行场景纯属巧合了。
后来仔细查看代码,发现socket的分配内存和释放内存的语句须要匹配使用。
原来的代码:
#include "lrs.h"
Action()
{
char *Data=(char*) malloc(512,sizeof(char));
int Size=0;
int rc=0;
int receive_code;
memset(Data,0,strlen(Data));
rc=lrs_create_socket("socket0","TCP","RemoteHost=10.100.200.100:22108",LrsLastArg);
if (0==rc) {
lr_output_message("Socket was successfully created ");
}
else
{
lr_output_message("An error occurred while creating the socket, Error Code: %d",rc);
}
lr_start_transaction("POS_80_trans");
lrs_send("socket0","buf0",LrsLastArg); //Íù"socket0"·¢ËÍ"buf0"ÖеÄÊý¾Ý
lrs_disable_socket("socket0", DISABLE_SEND);
receive_code=lrs_receive("socket0","buf1",LrsLastArg);
lrs_get_last_received_buffer("socket0",&Data,&Size);
lrs_free_buffer(Data);
lr_end_transaction("POS_80_trans",LR_AUTO);
lrs_close_socket("socket0");
return 0;
}
修改后的代码(修改后的代码用红色字体表示):
#include "lrs.h"
Action()
{
//char *Data=(char*) malloc(512,sizeof(char));
char *Data;
int NumberofBytes=512;
int Size=0;
int rc=0;
int receive_code;
//memset(Data,0,strlen(Data));
lrs_get_buffer_by_name("buf1",&Data,&NumberofBytes);
rc=lrs_create_socket("socket0","TCP","RemoteHost=10.100.200.100:22108",LrsLastArg);
if (0==rc) {
lr_output_message("Socket was successfully created ");
}
else
{
lr_output_message("An error occurred while creating the socket, Error Code: %d",rc);
}
lr_start_transaction("POS_80_trans");
lrs_send("socket0","buf0",LrsLastArg); //Íù"socket0"·¢ËÍ"buf0"ÖеÄÊý¾Ý
lrs_disable_socket("socket0", DISABLE_SEND);
receive_code=lrs_receive("socket0","buf1",LrsLastArg);
lrs_get_last_received_buffer("socket0",&Data,&Size);
lrs_free_buffer(Data);
lr_end_transaction("POS_80_trans",LR_AUTO);
lrs_close_socket("socket0");
return 0;
}